From 33cc6062dd7fb2ab73f5627c1583bfb6ec07d8df Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Thu, 3 Jun 2021 14:00:01 +0200 Subject: [PATCH] split kubeconfig --- pkg/kubeutil/kubeutil.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/kubeutil/kubeutil.go b/pkg/kubeutil/kubeutil.go index d64ab96..35d0d7e 100644 --- a/pkg/kubeutil/kubeutil.go +++ b/pkg/kubeutil/kubeutil.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -27,7 +28,7 @@ func (p *Params) Bind(cmd *cobra.Command) error { return nil } -func (p *Params) Client() (kubernetes.Interface, error) { +func (p *Params) Config() (*rest.Config, error) { if p.kubeconfig == "" { p.kubeconfig = os.Getenv(EnvKubeconfig) } @@ -37,6 +38,15 @@ func (p *Params) Client() (kubernetes.Interface, error) { return nil, errors.Wrap(err, "failed to load kubernetes config") } + return config, nil +} + +func (p *Params) Client() (kubernetes.Interface, error) { + config, err := p.Config() + if err != nil { + return nil, errors.WithStack(err) + } + client, err := kubernetes.NewForConfig(config) if err != nil { return nil, errors.Wrap(err, "failed to initialize kubernetes client")