Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Allow istio to be updated based on version releases (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob0h authored Nov 26, 2018
1 parent 21fa63f commit 176f1ab
Show file tree
Hide file tree
Showing 75 changed files with 1,539 additions and 3,462 deletions.
31 changes: 12 additions & 19 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ ignored = [
[[override]]
name = "github.com/russross/blackfriday"
version = "1.5.1"

[[constraint]]
branch = "master"
name = "github.com/hashicorp/go-version"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ _mockgen:
github.com/replicatedhq/ship/pkg/util \
AssetUploader & \
mockgen \
-destination pkg/test-mocks/githubclient/release_note_fetcher.go \
-destination pkg/test-mocks/githubclient/github_fetcher.go \
-package githubclient \
github.com/replicatedhq/ship/pkg/specs/githubclient \
GitHubReleaseNotesFetcher & \
GitHubFetcher & \
wait


Expand Down
2 changes: 1 addition & 1 deletion integration/init/istio-1.0.3/expected/.ship/state.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions integration/update/version/expected/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"v1": {
"config": {},
"helmValues": "replicaCount: 1\nimage:\n repository: nginx\n tag: stable\n pullPolicy: Always\nservice:\n type: ClusterIP\n port: 82\ningress:\n enabled: false\n annotations: {}\n path: /\n hosts:\n - chart-example.local\n tls: []\nresources: {}\nnodeSelector: {}\ntolerations: []\naffinity: {}\n",
"releaseName": "version",
"helmValuesDefaults": "# Default values for basic.\n# This is a YAML-formatted file.\n# Declare variables to be passed into your templates.\n\nreplicaCount: 1\n\nimage:\n repository: nginx\n tag: stable\n pullPolicy: Always\n\nservice:\n type: ClusterIP\n port: 82\n\ningress:\n enabled: false\n annotations: {}\n # kubernetes.io/ingress.class: nginx\n # kubernetes.io/tls-acme: \"true\"\n path: /\n hosts:\n - chart-example.local\n tls: []\n # - secretName: chart-example-tls\n # hosts:\n # - chart-example.local\n\nresources: {}\n # We usually recommend not to specify default resources and to leave this as a conscious\n # choice for the user. This also increases chances charts run on environments with little\n # resources, such as Minikube. If you do want to specify resources, uncomment the following\n # lines, adjust them as necessary, and remove the curly braces after 'resources:'.\n # limits:\n # cpu: 100m\n # memory: 128Mi\n # requests:\n # cpu: 100m\n # memory: 128Mi\n\nnodeSelector: {}\n\ntolerations: []\n\naffinity: {}\n",
"upstream": "https://github.com/replicatedhq/test-charts/tree/_latest_/version",
"metadata": {
"applicationType": "helm",
"name": "version",
"releaseNotes": "Bump versions chart to 0.0.2 (#12)",
"version": "0.0.2"
},
"contentSHA": "fae33489bcdae655ee68c369d392e7182281e21688f6c448ea376be009279c48"
}
}
42 changes: 42 additions & 0 deletions integration/update/version/expected/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# Source: version/templates/deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: version
labels:
app: version
chart: version-0.0.2
release: version
heritage: Tiller
spec:
replicas: 1
selector:
matchLabels:
app: version
release: version
template:
metadata:
labels:
app: version
release: version
spec:
containers:
- name: version
image: "nginx:stable"
imagePullPolicy: Always
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{}

5 changes: 5 additions & 0 deletions integration/update/version/expected/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: ""
apiversion: ""
resources:
- deployment.yaml
- service.yaml
21 changes: 21 additions & 0 deletions integration/update/version/expected/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# Source: version/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: version
labels:
app: version
chart: version-0.0.2
release: version
heritage: Tiller
spec:
type: ClusterIP
ports:
- port: 82
targetPort: http
protocol: TCP
name: http
selector:
app: version
release: version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: ""
apiversion: ""
bases:
- ../../base
58 changes: 58 additions & 0 deletions integration/update/version/expected/rendered.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: version
chart: version-0.0.2
heritage: Tiller
release: version
name: version
spec:
ports:
- name: http
port: 82
protocol: TCP
targetPort: http
selector:
app: version
release: version
type: ClusterIP
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
app: version
chart: version-0.0.2
heritage: Tiller
release: version
name: version
spec:
replicas: 1
selector:
matchLabels:
app: version
release: version
template:
metadata:
labels:
app: version
release: version
spec:
containers:
- image: nginx:stable
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /
port: http
name: version
ports:
- containerPort: 80
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /
port: http
resources: {}
16 changes: 16 additions & 0 deletions integration/update/version/input/.ship/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"v1": {
"config": null,
"helmValues": "replicaCount: 1\nimage:\n repository: nginx\n tag: stable\n pullPolicy: IfNotPresent\nservice:\n type: ClusterIP\n port: 80\ningress:\n enabled: false\n annotations: {}\n path: /\n hosts:\n - chart-example.local\n tls: []\nresources: {}\nnodeSelector: {}\ntolerations: []\naffinity: {}\n",
"releaseName": "version",
"helmValuesDefaults": "# Default values for basic.\n# This is a YAML-formatted file.\n# Declare variables to be passed into your templates.\n\nreplicaCount: 1\n\nimage:\n repository: nginx\n tag: stable\n pullPolicy: IfNotPresent\n\nservice:\n type: ClusterIP\n port: 80\n\ningress:\n enabled: false\n annotations: {}\n # kubernetes.io/ingress.class: nginx\n # kubernetes.io/tls-acme: \"true\"\n path: /\n hosts:\n - chart-example.local\n tls: []\n # - secretName: chart-example-tls\n # hosts:\n # - chart-example.local\n\nresources: {}\n # We usually recommend not to specify default resources and to leave this as a conscious\n # choice for the user. This also increases chances charts run on environments with little\n # resources, such as Minikube. If you do want to specify resources, uncomment the following\n # lines, adjust them as necessary, and remove the curly braces after 'resources:'.\n # limits:\n # cpu: 100m\n # memory: 128Mi\n # requests:\n # cpu: 100m\n # memory: 128Mi\n\nnodeSelector: {}\n\ntolerations: []\n\naffinity: {}\n",
"upstream": "https://github.com/replicatedhq/test-charts/tree/_latest_/version",
"metadata": {
"applicationType": "helm",
"name": "version",
"releaseNotes": "Add a new version chart for versioned updates (#11)",
"version": "0.0.1"
},
"contentSHA": "4adecfde17359b4fb196e700785a36aefa4a337b64b96f2defdc7e6f55ea24d2"
}
}
1 change: 1 addition & 0 deletions integration/update/version/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
args: ["--prefer-git"]
7 changes: 6 additions & 1 deletion pkg/ship/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ func (s *Ship) Init(ctx context.Context) error {
return errors.New("No upstream provided")
}

release, err := s.Resolver.ResolveRelease(ctx, target)
maybeVersionedUpstream, err := s.Resolver.MaybeResolveVersionedUpstream(ctx, target, existingState)
if err != nil {
return errors.Wrap(err, "create versioned release")
}

release, err := s.Resolver.ResolveRelease(ctx, maybeVersionedUpstream)
if err != nil {
return errors.Wrap(err, "resolve release")
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/ship/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ func (s *Ship) Update(ctx context.Context) error {
return errors.New(fmt.Sprintf(`No upstream URL found at %s, please run "ship init"`, s.Viper.GetString("state-file")))
}

maybeVersionedUpstream, err := s.Resolver.MaybeResolveVersionedUpstream(ctx, upstreamURL, existingState)
if err != nil {
return errors.New(`Unable to resolve versioned upstream ` + upstreamURL)
}

debug.Log("event", "fetch latest chart")
s.Daemon.SetProgress(daemontypes.StringProgress("kustomize", `Downloading latest from upstream `+upstreamURL))
s.Daemon.SetProgress(daemontypes.StringProgress("kustomize", `Downloading latest from upstream `+maybeVersionedUpstream))

debug.Log("event", "reset steps completed")
if err := s.StateManager.ResetLifecycle(); err != nil {
return errors.Wrap(err, "reset state.json completed lifecycle")
}

release, err := s.Resolver.ResolveRelease(ctx, upstreamURL)
release, err := s.Resolver.ResolveRelease(ctx, maybeVersionedUpstream)
if err != nil {
return errors.Wrapf(err, "resolve helm chart metadata for %s", upstreamURL)
return errors.Wrapf(err, "resolve helm chart metadata for %s", maybeVersionedUpstream)
}

release.Spec.Lifecycle = s.IDPatcher.EnsureAllStepsHaveUniqueIDs(release.Spec.Lifecycle)
Expand Down
9 changes: 7 additions & 2 deletions pkg/ship/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ func (s *Ship) Watch(ctx context.Context) error {
return errors.New(`No current chart url found at ` + s.Viper.GetString("state-file") + `, please run "ship init"`)
}

maybeVersionedUpstream, err := s.Resolver.MaybeResolveVersionedUpstream(ctx, upstream, existingState)
if err != nil {
return errors.New(`Unable to resolve versioned upstream ` + upstream)
}

debug.Log("event", "read.lastSHA")
lastSHA := existingState.Versioned().V1.ContentSHA
if lastSHA == "" {
return errors.New(`No current SHA found at ` + s.Viper.GetString("state-file") + `, please run "ship init"`)
}

contentSHA, err := s.Resolver.ReadContentSHAForWatch(ctx, upstream)
contentSHA, err := s.Resolver.ReadContentSHAForWatch(ctx, maybeVersionedUpstream)
if err != nil {
return errors.Wrap(err, "read content SHA")
}
Expand All @@ -59,7 +64,7 @@ func (s *Ship) Watch(ctx context.Context) error {
"previous", existingState.Versioned().V1.ContentSHA,
"new", contentSHA,
)
s.UI.Info(fmt.Sprintf("%s has an update available", upstream))
s.UI.Info(fmt.Sprintf("%s has an update available", maybeVersionedUpstream))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/specs/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (r *Resolver) resolveMetadata(ctx context.Context, upstream, localPath stri
}

if util.IsGithubURL(upstream) {
releaseNotes, err := r.GitHubReleaseNotesFetcher.ResolveReleaseNotes(ctx, upstream)
releaseNotes, err := r.GitHubFetcher.ResolveReleaseNotes(ctx, upstream)
if err != nil {
debug.Log("event", "releaseNotes.resolve.fail", "upstream", upstream, "err", err)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/specs/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (

// A Resolver resolves specs
type Resolver struct {
Logger log.Logger
Client *replicatedapp.GraphQLClient
StateManager state.Manager
FS afero.Afero
AppResolver replicatedapp.Resolver
GitHubReleaseNotesFetcher githubclient.GitHubReleaseNotesFetcher
Logger log.Logger
Client *replicatedapp.GraphQLClient
StateManager state.Manager
FS afero.Afero
AppResolver replicatedapp.Resolver
GitHubFetcher githubclient.GitHubFetcher

ui cli.Ui
appTypeInspector apptype.Inspector
Expand Down Expand Up @@ -52,8 +52,8 @@ func NewResolver(
shaSummer: func(resolver *Resolver, s string) (string, error) {
return resolver.calculateContentSHA(s)
},
AppResolver: appresolver,
GitHubReleaseNotesFetcher: github,
NoOutro: v.GetBool("no-outro"),
AppResolver: appresolver,
GitHubFetcher: github,
NoOutro: v.GetBool("no-outro"),
}
}
Loading

0 comments on commit 176f1ab

Please sign in to comment.