Skip to content

Commit

Permalink
Merge pull request #10 from deiga/patch-1
Browse files Browse the repository at this point in the history
Allows passing thorough --context from kubectl command
  • Loading branch information
emirozer authored Feb 3, 2020
2 parents bf1c7f7 + 21b8c22 commit 8f5e83a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func InitClient() *kubernetes.Clientset {
// determine which kubeconfig to use
var kubeconfig *string
var kubeconfigbase string
var kubecontext *string

kubeconfigFromEnv, err := tryGetKubeConfigFromEnvVar()
if err != nil {
Expand All @@ -47,13 +48,20 @@ func InitClient() *kubernetes.Clientset {
kubeconfigbase,
"(optional) absolute path to the kubeconfig file",
)
kubecontext = flag.String(
"context",
"",
"(optional) name of kube context",
)

flag.Parse()

// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
config = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: *kubeconfig},
&clientcmd.ConfigOverrides{
CurrentContext: *context,
}).ClientConfig()

csBackup, err := getClientSetFromConfig(config)
if err != nil {
panic(err.Error())
Expand Down

0 comments on commit 8f5e83a

Please sign in to comment.