From 4f43007908105bc2529bc5230bff8913231f9ac2 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 13 Oct 2016 16:04:31 -0700 Subject: [PATCH] feat(helm): add canary option to init command To install the tiller canary `helm init --canary` --- cmd/helm/init.go | 6 ++++-- cmd/helm/installer/install.go | 7 +++++-- cmd/helm/installer/install_test.go | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/helm/init.go b/cmd/helm/init.go index 3a7354cb8..b39bb0f50 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -46,6 +46,7 @@ const ( type initCmd struct { image string clientOnly bool + canary bool out io.Writer home helmpath.Home kubeClient unversioned.DeploymentsNamespacer @@ -68,7 +69,8 @@ func newInitCmd(out io.Writer) *cobra.Command { }, } cmd.Flags().StringVarP(&i.image, "tiller-image", "i", "", "override tiller image") - cmd.Flags().BoolVarP(&i.clientOnly, "client-only", "c", false, "If set does not install tiller") + cmd.Flags().BoolVar(&i.canary, "canary-image", false, "use the canary tiller image") + cmd.Flags().BoolVarP(&i.clientOnly, "client-only", "c", false, "if set does not install tiller") return cmd } @@ -86,7 +88,7 @@ func (i *initCmd) run() error { } i.kubeClient = c } - if err := installer.Install(i.kubeClient, tillerNamespace, i.image, flagDebug); err != nil { + if err := installer.Install(i.kubeClient, tillerNamespace, i.image, i.canary, flagDebug); err != nil { if !kerrors.IsAlreadyExists(err) { return fmt.Errorf("error installing: %s", err) } diff --git a/cmd/helm/installer/install.go b/cmd/helm/installer/install.go index 2fa600d10..c8dffdb75 100644 --- a/cmd/helm/installer/install.go +++ b/cmd/helm/installer/install.go @@ -35,8 +35,11 @@ const defaultImage = "gcr.io/kubernetes-helm/tiller" // command failed. // // If verbose is true, this will print the manifest to stdout. -func Install(client unversioned.DeploymentsNamespacer, namespace, image string, verbose bool) error { - if image == "" { +func Install(client unversioned.DeploymentsNamespacer, namespace, image string, canary, verbose bool) error { + switch { + case canary: + image = defaultImage + ":canary" + case image == "": image = fmt.Sprintf("%s:%s", defaultImage, version.Version) } obj := generateDeployment(image) diff --git a/cmd/helm/installer/install_test.go b/cmd/helm/installer/install_test.go index 3bb320806..64bd9a784 100644 --- a/cmd/helm/installer/install_test.go +++ b/cmd/helm/installer/install_test.go @@ -42,7 +42,24 @@ func TestInstall(t *testing.T) { return true, obj, nil }) - err := Install(fake.Extensions(), "default", image, false) + err := Install(fake.Extensions(), "default", image, false, false) + if err != nil { + t.Errorf("unexpected error: %#+v", err) + } +} + +func TestInstall_canary(t *testing.T) { + fake := testclient.Fake{} + fake.AddReactor("create", "deployments", func(action testclient.Action) (bool, runtime.Object, error) { + obj := action.(testclient.CreateAction).GetObject().(*extensions.Deployment) + i := obj.Spec.Template.Spec.Containers[0].Image + if i != "gcr.io/kubernetes-helm/tiller:canary" { + t.Errorf("expected canary image, got '%s'", i) + } + return true, obj, nil + }) + + err := Install(fake.Extensions(), "default", "", true, false) if err != nil { t.Errorf("unexpected error: %#+v", err) }