From ad780eb3444c5d626734ce7608f961f9574b4b57 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 25 Oct 2023 11:59:09 -0500 Subject: [PATCH] feat(config): Set current context --- internal/kubernetes/client.go | 5 +++++ internal/util/cmd_setup.go | 1 + 2 files changed, 6 insertions(+) diff --git a/internal/kubernetes/client.go b/internal/kubernetes/client.go index 7595c8e8..00b0a560 100644 --- a/internal/kubernetes/client.go +++ b/internal/kubernetes/client.go @@ -18,6 +18,7 @@ type KubeClient struct { ClientSet kubernetes.Interface ClientConfig *rest.Config Discovery *discovery.DiscoveryClient + Context string Namespace string } @@ -56,6 +57,10 @@ func NewConfigLoader(kubeconfig, context string) clientcmd.ClientConfig { func NewClient(kubeconfig, context, namespace string) (config KubeClient, err error) { configLoader := NewConfigLoader(kubeconfig, context) + if rawConfig, err := configLoader.RawConfig(); err == nil { + config.Context = rawConfig.CurrentContext + } + config.ClientConfig, err = configLoader.ClientConfig() if err != nil { return config, err diff --git a/internal/util/cmd_setup.go b/internal/util/cmd_setup.go index 8ad59976..35e1b07a 100644 --- a/internal/util/cmd_setup.go +++ b/internal/util/cmd_setup.go @@ -46,6 +46,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e return err } log.WithField("namespace", conf.Client.Namespace).Debug("created kube client") + conf.Context = conf.Client.Context conf.Namespace = conf.Client.Namespace access := config.NewNamespaceRegexp(cmd.Annotations["access"])