Skip to content

Commit

Permalink
kubeconfig: Simplify mergeKubeConfigFile
Browse files Browse the repository at this point in the history
An intermediate `mergedConfig` is not required, we can directly modify
the global kubeconfig.
  • Loading branch information
vyasgun authored and cfergeau committed Dec 11, 2023
1 parent b15f94d commit 382412c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pkg/crc/machine/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,18 @@ func mergeKubeConfigFile(kubeConfigFile string) error {
return err
}
// Merge the currentConf to globalConfig
mergedConfig, err := clientcmd.NewDefaultClientConfig(*globalConf, &clientcmd.ConfigOverrides{}).ConfigAccess().GetStartingConfig()
if err != nil {
return err
}

for name, cluster := range currentConf.Clusters {
mergedConfig.Clusters[name] = cluster
globalConf.Clusters[name] = cluster
}

for name, authInfo := range currentConf.AuthInfos {
mergedConfig.AuthInfos[name] = authInfo
globalConf.AuthInfos[name] = authInfo
}

for name, context := range currentConf.Contexts {
mergedConfig.Contexts[name] = context
globalConf.Contexts[name] = context
}

mergedConfig.CurrentContext = currentConf.CurrentContext
return clientcmd.WriteToFile(*mergedConfig, globalConfigPath)
globalConf.CurrentContext = currentConf.CurrentContext
return clientcmd.WriteToFile(*globalConf, globalConfigPath)
}

0 comments on commit 382412c

Please sign in to comment.