1
0
mirror of synced 2026-02-06 10:55:56 +00:00

Add a --context option

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
This commit is contained in:
Sylvain Rabot
2020-11-02 20:50:14 +01:00
parent 9da7ded976
commit 78d7dca985
126 changed files with 136 additions and 54 deletions

View File

@@ -124,11 +124,19 @@ func ExecTemplate(obj interface{}, tmpl, filename string) error {
return file.Sync()
}
func KubeClient(kubeConfigPath string) (client.Client, error) {
func KubeClient(kubeConfigPath string, kubeContext string) (client.Client, error) {
configFiles := SplitKubeConfigPath(kubeConfigPath)
configOverrides := clientcmd.ConfigOverrides{}
if len(kubeContext) > 0 {
configOverrides.CurrentContext = kubeContext
}
cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{Precedence: configFiles},
&clientcmd.ConfigOverrides{}).ClientConfig()
&configOverrides,
).ClientConfig()
if err != nil {
return nil, fmt.Errorf("kubernetes client initialization failed: %w", err)
}