Skip to content

Commit

Permalink
feat(config): Set current context
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 25, 2023
1 parent 82bb489 commit ad780eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type KubeClient struct {
ClientSet kubernetes.Interface
ClientConfig *rest.Config
Discovery *discovery.DiscoveryClient
Context string
Namespace string
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/util/cmd_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit ad780eb

Please sign in to comment.