From 264ad3271ed01697c359bdfd1506c8cacf35721c Mon Sep 17 00:00:00 2001 From: Adam Reese <adam@reese.io> Date: Tue, 11 Apr 2017 15:30:24 -0700 Subject: [PATCH] fix(init): use ImagePullPolicy Always for canary installs fixes: #2155 --- cmd/helm/installer/install.go | 4 ++-- cmd/helm/installer/install_test.go | 19 ++++++++++++------- cmd/helm/installer/options.go | 9 +++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/helm/installer/install.go b/cmd/helm/installer/install.go index 338e31eca..b159ec660 100644 --- a/cmd/helm/installer/install.go +++ b/cmd/helm/installer/install.go @@ -20,7 +20,6 @@ import ( "io/ioutil" "github.com/ghodss/yaml" - "k8s.io/kubernetes/pkg/api" kerrors "k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/apis/extensions" @@ -57,6 +56,7 @@ func Upgrade(client internalclientset.Interface, opts *Options) error { return err } obj.Spec.Template.Spec.Containers[0].Image = opts.selectImage() + obj.Spec.Template.Spec.Containers[0].ImagePullPolicy = opts.pullPolicy() if _, err := client.Extensions().Deployments(opts.Namespace).Update(obj); err != nil { return err } @@ -138,7 +138,7 @@ func generateDeployment(opts *Options) *extensions.Deployment { { Name: "tiller", Image: opts.selectImage(), - ImagePullPolicy: "IfNotPresent", + ImagePullPolicy: opts.pullPolicy(), Ports: []api.ContainerPort{ {ContainerPort: 44134, Name: "tiller"}, }, diff --git a/cmd/helm/installer/install_test.go b/cmd/helm/installer/install_test.go index 4d9a2cbca..7da65b42b 100644 --- a/cmd/helm/installer/install_test.go +++ b/cmd/helm/installer/install_test.go @@ -34,14 +34,15 @@ import ( func TestDeploymentManifest(t *testing.T) { tests := []struct { - name string - image string - canary bool - expect string + name string + image string + canary bool + expect string + imagePullPolicy api.PullPolicy }{ - {"default", "", false, "gcr.io/kubernetes-helm/tiller:" + version.Version}, - {"canary", "example.com/tiller", true, "gcr.io/kubernetes-helm/tiller:canary"}, - {"custom", "example.com/tiller:latest", false, "example.com/tiller:latest"}, + {"default", "", false, "gcr.io/kubernetes-helm/tiller:" + version.Version, "IfNotPresent"}, + {"canary", "example.com/tiller", true, "gcr.io/kubernetes-helm/tiller:canary", "Always"}, + {"custom", "example.com/tiller:latest", false, "example.com/tiller:latest", "IfNotPresent"}, } for _, tt := range tests { @@ -58,6 +59,10 @@ func TestDeploymentManifest(t *testing.T) { t.Errorf("%s: expected image %q, got %q", tt.name, tt.expect, got) } + if got := dep.Spec.Template.Spec.Containers[0].ImagePullPolicy; got != tt.imagePullPolicy { + t.Errorf("%s: expected imagePullPolicy %q, got %q", tt.name, tt.imagePullPolicy, got) + } + if got := dep.Spec.Template.Spec.Containers[0].Env[0].Value; got != api.NamespaceDefault { t.Errorf("%s: expected namespace %q, got %q", tt.name, api.NamespaceDefault, got) } diff --git a/cmd/helm/installer/options.go b/cmd/helm/installer/options.go index 41f8aaf2a..003bb1d70 100644 --- a/cmd/helm/installer/options.go +++ b/cmd/helm/installer/options.go @@ -18,7 +18,9 @@ package installer // import "k8s.io/helm/cmd/helm/installer" import ( "fmt" + "k8s.io/helm/pkg/version" + "k8s.io/kubernetes/pkg/api" ) const defaultImage = "gcr.io/kubernetes-helm/tiller" @@ -76,4 +78,11 @@ func (opts *Options) selectImage() string { } } +func (opts *Options) pullPolicy() api.PullPolicy { + if opts.UseCanary { + return api.PullAlways + } + return api.PullIfNotPresent +} + func (opts *Options) tls() bool { return opts.EnableTLS || opts.VerifyTLS } -- GitLab