mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-14 07:46:51 +00:00
Add a --context option
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
This commit is contained in:
parent
9da7ded976
commit
78d7dca985
126 changed files with 136 additions and 54 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue