diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 926e5e6d8..ce3385cb3 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -22,8 +22,6 @@ import ( "strings" "github.com/spf13/cobra" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" // Import to initialize client auth plugins. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -136,28 +134,6 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error { return nil } -// configForContext creates a Kubernetes REST client configuration for a given kubeconfig context. -func configForContext(context string) (*rest.Config, error) { - config, err := kube.GetConfig(context).ClientConfig() - if err != nil { - return nil, fmt.Errorf("could not get Kubernetes config for context %q: %s", context, err) - } - return config, nil -} - -// getKubeClient creates a Kubernetes config and client for a given kubeconfig context. -func getKubeClient(context string) (*rest.Config, kubernetes.Interface, error) { - config, err := configForContext(context) - if err != nil { - return nil, nil, err - } - client, err := kubernetes.NewForConfig(config) - if err != nil { - return nil, nil, fmt.Errorf("could not get Kubernetes client: %s", err) - } - return config, client, nil -} - // ensureHelmClient returns a new helm client impl. if h is not nil. func ensureHelmClient(h helm.Interface) helm.Interface { if h != nil { @@ -167,15 +143,18 @@ func ensureHelmClient(h helm.Interface) helm.Interface { } func newClient() helm.Interface { - _, clientset, err := getKubeClient(settings.KubeContext) + cfg := kube.GetConfig(settings.KubeContext) + kc := kube.New(cfg) + clientset, err := kc.KubernetesClientSet() if err != nil { // TODO return error panic(err) } // TODO add other backends - cfgmaps := driver.NewConfigMaps(clientset.Core().ConfigMaps(settings.TillerNamespace)) + cfgmaps := driver.NewConfigMaps(clientset.CoreV1().ConfigMaps(settings.TillerNamespace)) return helm.NewClient( + helm.KubeClient(kc), helm.Driver(cfgmaps), helm.Discovery(clientset.Discovery()), ) diff --git a/pkg/helm/client.go b/pkg/helm/client.go index 2f6247600..fc8b40cd7 100644 --- a/pkg/helm/client.go +++ b/pkg/helm/client.go @@ -18,7 +18,6 @@ package helm // import "k8s.io/helm/pkg/helm" import ( "k8s.io/helm/pkg/chartutil" - "k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/release" rls "k8s.io/helm/pkg/proto/hapi/services" @@ -42,9 +41,7 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() *Client { env := environment.New() env.Releases = storage.Init(c.opts.driver) - - // TODO - env.KubeClient = kube.New(nil) + env.KubeClient = c.opts.kubeClient c.tiller = tiller.NewReleaseServer(env, c.opts.discovery) return c diff --git a/pkg/helm/option.go b/pkg/helm/option.go index cad158058..375cb719d 100644 --- a/pkg/helm/option.go +++ b/pkg/helm/option.go @@ -24,6 +24,7 @@ import ( "k8s.io/helm/pkg/proto/hapi/release" rls "k8s.io/helm/pkg/proto/hapi/services" "k8s.io/helm/pkg/storage/driver" + "k8s.io/helm/pkg/tiller/environment" ) // Option allows specifying various settings configurable by @@ -68,8 +69,9 @@ type options struct { // release test options are applied directly to the test release history request testReq rls.TestReleaseRequest - driver driver.Driver - discovery discovery.DiscoveryInterface + driver driver.Driver + kubeClient environment.KubeClient + discovery discovery.DiscoveryInterface } func (opts *options) runBefore(msg proto.Message) error { @@ -378,6 +380,12 @@ func Driver(d driver.Driver) Option { } } +func KubeClient(kc environment.KubeClient) Option { + return func(opts *options) { + opts.kubeClient = kc + } +} + func Discovery(dc discovery.DiscoveryInterface) Option { return func(opts *options) { opts.discovery = dc