Merge pull request #2132 from fibonacci1729/ref/installer

ref/installer: pass arguments in options struct to installer apis
pull/2137/head
Brian 8 years ago committed by GitHub
commit a21f010c6d

@ -143,12 +143,13 @@ func (i *initCmd) run() error {
} }
i.kubeClient = c i.kubeClient = c
} }
if err := installer.Install(i.kubeClient, i.namespace, i.image, i.canary, flagDebug); err != nil { opts := &installer.Options{Namespace: i.namespace, ImageSpec: i.image, UseCanary: i.canary}
if err := installer.Install(i.kubeClient, opts); err != nil {
if !kerrors.IsAlreadyExists(err) { if !kerrors.IsAlreadyExists(err) {
return fmt.Errorf("error installing: %s", err) return fmt.Errorf("error installing: %s", err)
} }
if i.upgrade { if i.upgrade {
if err := installer.Upgrade(i.kubeClient, i.namespace, i.image, i.canary); err != nil { if err := installer.Upgrade(i.kubeClient, opts); err != nil {
return fmt.Errorf("error when upgrading: %s", err) return fmt.Errorf("error when upgrading: %s", err)
} }
fmt.Fprintln(i.out, "\nTiller (the helm server side component) has been upgraded to the current version.") fmt.Fprintln(i.out, "\nTiller (the helm server side component) has been upgraded to the current version.")

@ -34,42 +34,38 @@ import (
const defaultImage = "gcr.io/kubernetes-helm/tiller" const defaultImage = "gcr.io/kubernetes-helm/tiller"
// Install uses kubernetes client to install tiller // Install uses kubernetes client to install tiller.
// //
// Returns the string output received from the operation, and an error if the // Returns an error if the command failed.
// command failed. func Install(client internalclientset.Interface, opts *Options) error {
// if err := createDeployment(client.Extensions(), opts.Namespace, opts.ImageSpec, opts.UseCanary); err != nil {
// If verbose is true, this will print the manifest to stdout.
func Install(client internalclientset.Interface, namespace, image string, canary, verbose bool) error {
if err := createDeployment(client.Extensions(), namespace, image, canary); err != nil {
return err return err
} }
if err := createService(client.Core(), namespace); err != nil { if err := createService(client.Core(), opts.Namespace); err != nil {
return err return err
} }
return nil return nil
} }
// // Upgrade uses kubernetes client to upgrade tiller to current version.
// Upgrade uses kubernetes client to upgrade tiller to current version
// //
// Returns an error if the command failed. // Returns an error if the command failed.
func Upgrade(client internalclientset.Interface, namespace, image string, canary bool) error { func Upgrade(client internalclientset.Interface, opts *Options) error {
obj, err := client.Extensions().Deployments(namespace).Get("tiller-deploy") obj, err := client.Extensions().Deployments(opts.Namespace).Get("tiller-deploy")
if err != nil { if err != nil {
return err return err
} }
obj.Spec.Template.Spec.Containers[0].Image = selectImage(image, canary) obj.Spec.Template.Spec.Containers[0].Image = selectImage(opts.ImageSpec, opts.UseCanary)
if _, err := client.Extensions().Deployments(namespace).Update(obj); err != nil { if _, err := client.Extensions().Deployments(opts.Namespace).Update(obj); err != nil {
return err return err
} }
// If the service does not exists that would mean we are upgrading from a tiller version // If the service does not exists that would mean we are upgrading from a tiller version
// that didn't deploy the service, so install it. // that didn't deploy the service, so install it.
if _, err := client.Core().Services(namespace).Get("tiller-deploy"); err != nil { if _, err := client.Core().Services(opts.Namespace).Get("tiller-deploy"); err != nil {
if !kerrors.IsNotFound(err) { if !kerrors.IsNotFound(err) {
return err return err
} }
if err := createService(client.Core(), namespace); err != nil { if err := createService(client.Core(), opts.Namespace); err != nil {
return err return err
} }
} }

@ -45,7 +45,6 @@ func TestDeploymentManifest(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
o, err := DeploymentManifest(api.NamespaceDefault, tt.image, tt.canary) o, err := DeploymentManifest(api.NamespaceDefault, tt.image, tt.canary)
if err != nil { if err != nil {
t.Fatalf("%s: error %q", tt.name, err) t.Fatalf("%s: error %q", tt.name, err)
@ -109,7 +108,8 @@ func TestInstall(t *testing.T) {
return true, obj, nil return true, obj, nil
}) })
if err := Install(fc, api.NamespaceDefault, image, false, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault, ImageSpec: image}
if err := Install(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }
@ -133,7 +133,8 @@ func TestInstall_canary(t *testing.T) {
return true, obj, nil return true, obj, nil
}) })
if err := Install(fc, api.NamespaceDefault, "", true, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault, UseCanary: true}
if err := Install(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }
@ -164,7 +165,8 @@ func TestUpgrade(t *testing.T) {
return true, existingService, nil return true, existingService, nil
}) })
if err := Upgrade(fc, api.NamespaceDefault, image, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault, ImageSpec: image}
if err := Upgrade(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }
@ -202,7 +204,8 @@ func TestUpgrade_serviceNotFound(t *testing.T) {
return true, obj, nil return true, obj, nil
}) })
if err := Upgrade(fc, api.NamespaceDefault, image, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault, ImageSpec: image}
if err := Upgrade(fc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }

@ -0,0 +1,59 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package installer // import "k8s.io/helm/cmd/helm/installer"
// Options control how to install tiller into a cluster, upgrade, and uninstall tiller from a cluster.
type Options struct {
// EnableTLS instructs tiller to serve with TLS enabled.
//
// Implied by VerifyTLS. If set the TLSKey and TLSCert are required.
EnableTLS bool
// VerifyTLS instructs tiller to serve with TLS enabled verify remote certificates.
//
// If set TLSKey, TLSCert, TLSCaCert are required.
VerifyTLS bool
// UseCanary indicates that tiller should deploy using the latest tiller image.
UseCanary bool
// Namespace is the kubernetes namespace to use to deploy tiller.
Namespace string
// ImageSpec indentifies the image tiller will use when deployed.
//
// Valid if and only if UseCanary is false.
ImageSpec string
// TLSKeyFile identifies the file containing the pem encoded TLS private
// key tiller should use.
//
// Required and valid if and only if EnableTLS or VerifyTLS is set.
TLSKey string
// TLSCertFile identifies the file containing the pem encoded TLS
// certificate tiller should use.
//
// Required and valid if and only if EnableTLS or VerifyTLS is set.
TLSCertFile string
// TLSCaCertFile identifies the file containing the pem encoded TLS CA
// certificate tiller should use to verify remotes certificates.
//
// Required and valid if and only if VerifyTLS is set.
TLSCaCertFile string
}

@ -31,19 +31,19 @@ import (
) )
// Uninstall uses kubernetes client to uninstall tiller // Uninstall uses kubernetes client to uninstall tiller
func Uninstall(kubeClient internalclientset.Interface, kubeCmd *kube.Client, namespace string, verbose bool) error { func Uninstall(kubeClient internalclientset.Interface, kubeCmd *kube.Client, opts *Options) error {
if _, err := kubeClient.Core().Services(namespace).Get("tiller-deploy"); err != nil { if _, err := kubeClient.Core().Services(opts.Namespace).Get("tiller-deploy"); err != nil {
if !kerrors.IsNotFound(err) { if !kerrors.IsNotFound(err) {
return err return err
} }
} else if err := deleteService(kubeClient.Core(), namespace); err != nil { } else if err := deleteService(kubeClient.Core(), opts.Namespace); err != nil {
return err return err
} }
if obj, err := kubeClient.Extensions().Deployments(namespace).Get("tiller-deploy"); err != nil { if obj, err := kubeClient.Extensions().Deployments(opts.Namespace).Get("tiller-deploy"); err != nil {
if !kerrors.IsNotFound(err) { if !kerrors.IsNotFound(err) {
return err return err
} }
} else if err := deleteDeployment(kubeCmd, namespace, obj); err != nil { } else if err := deleteDeployment(kubeCmd, opts.Namespace, obj); err != nil {
return err return err
} }
return nil return nil

@ -73,7 +73,8 @@ func TestUninstall(t *testing.T) {
rf := &fakeReaperFactory{Factory: f, reaper: r} rf := &fakeReaperFactory{Factory: f, reaper: r}
kc := &kube.Client{Factory: rf} kc := &kube.Client{Factory: rf}
if err := Uninstall(fc, kc, api.NamespaceDefault, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault}
if err := Uninstall(fc, kc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }
@ -106,7 +107,8 @@ func TestUninstall_serviceNotFound(t *testing.T) {
rf := &fakeReaperFactory{Factory: f, reaper: r} rf := &fakeReaperFactory{Factory: f, reaper: r}
kc := &kube.Client{Factory: rf} kc := &kube.Client{Factory: rf}
if err := Uninstall(fc, kc, api.NamespaceDefault, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault}
if err := Uninstall(fc, kc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }
@ -142,7 +144,8 @@ func TestUninstall_deploymentNotFound(t *testing.T) {
rf := &fakeReaperFactory{Factory: f, reaper: r} rf := &fakeReaperFactory{Factory: f, reaper: r}
kc := &kube.Client{Factory: rf} kc := &kube.Client{Factory: rf}
if err := Uninstall(fc, kc, api.NamespaceDefault, false); err != nil { opts := &Options{Namespace: api.NamespaceDefault}
if err := Uninstall(fc, kc, opts); err != nil {
t.Errorf("unexpected error: %#+v", err) t.Errorf("unexpected error: %#+v", err)
} }

@ -104,7 +104,7 @@ func (d *resetCmd) run() error {
return fmt.Errorf("There are still %d deployed releases (Tip: use --force).", len(res.Releases)) return fmt.Errorf("There are still %d deployed releases (Tip: use --force).", len(res.Releases))
} }
if err := installer.Uninstall(d.kubeClient, d.kubeCmd, d.namespace, flagDebug); err != nil { if err := installer.Uninstall(d.kubeClient, d.kubeCmd, &installer.Options{Namespace: d.namespace}); err != nil {
return fmt.Errorf("error unstalling Tiller: %s", err) return fmt.Errorf("error unstalling Tiller: %s", err)
} }

Loading…
Cancel
Save