Use passed-in context in pluginutils config initializer
This commit is contained in:
parent
ad5d307237
commit
b8ef16af1e
|
|
@ -82,7 +82,16 @@ func clientFromConfig(path string) (*restclient.Config, string, error) {
|
|||
return nil, "", fmt.Errorf("the provided credentials %q could not be loaded: %v", path, err)
|
||||
}
|
||||
|
||||
cfg := clientcmd.NewDefaultClientConfig(*credentials, &clientcmd.ConfigOverrides{})
|
||||
overrides := &clientcmd.ConfigOverrides{}
|
||||
var cfg clientcmd.ClientConfig
|
||||
context := os.Getenv("KUBECTL_PLUGINS_GLOBAL_FLAG_CONTEXT")
|
||||
if len(context) > 0 {
|
||||
rules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
cfg = clientcmd.NewNonInteractiveClientConfig(*credentials, context, overrides, rules)
|
||||
} else {
|
||||
cfg = clientcmd.NewDefaultClientConfig(*credentials, overrides)
|
||||
}
|
||||
|
||||
config, err := cfg.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("the provided credentials %q could not be used: %v", path, err)
|
||||
|
|
@ -132,11 +141,6 @@ func applyGlobalOptionsToConfig(config *restclient.Config) error {
|
|||
// TODO(jvallejo): figure out how to override kubeconfig options
|
||||
}
|
||||
|
||||
context := os.Getenv("KUBECTL_PLUGINS_GLOBAL_FLAG_CONTEXT")
|
||||
if len(context) > 0 {
|
||||
// TODO(jvallejo): figure out how to override kubeconfig options
|
||||
}
|
||||
|
||||
user := os.Getenv("KUBECTL_PLUGINS_GLOBAL_FLAG_USER")
|
||||
if len(user) > 0 {
|
||||
// TODO(jvallejo): figure out how to override kubeconfig options
|
||||
|
|
|
|||
|
|
@ -42,12 +42,11 @@ var _ = Describe("InitConfig", func() {
|
|||
os.Setenv("KUBECTL_PLUGINS_GLOBAL_FLAG_USERNAME", "date")
|
||||
os.Setenv("KUBECTL_PLUGINS_GLOBAL_FLAG_PASSWORD", "elderberry")
|
||||
|
||||
os.Setenv("KUBECTL_PLUGINS_GLOBAL_FLAG_CLUSTER", "")
|
||||
os.Setenv("KUBECTL_PLUGINS_GLOBAL_FLAG_CONTEXT", "california")
|
||||
})
|
||||
It("overrides the config settings with the passed in settings", func() {
|
||||
config, err := pluginutils.InitConfig()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(config.Impersonate.UserName).To(Equal("apple"))
|
||||
Expect(config.Impersonate.Groups).Should(ConsistOf("banana", "cherry"))
|
||||
|
||||
|
|
@ -61,6 +60,8 @@ var _ = Describe("InitConfig", func() {
|
|||
|
||||
Expect(config.Username).To(Equal("date"))
|
||||
Expect(config.Password).To(Equal("elderberry"))
|
||||
|
||||
Expect(config.Host).To(Equal("https://notrealincalifornia.com:1234"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,11 +4,19 @@ clusters:
|
|||
certificate-authority:
|
||||
server: https://notreal.com:1234
|
||||
name: local
|
||||
- cluster:
|
||||
certificate-authority:
|
||||
server: https://notrealincalifornia.com:1234
|
||||
name: california
|
||||
contexts:
|
||||
- context:
|
||||
cluster: local
|
||||
user: myself
|
||||
name: local
|
||||
- context:
|
||||
cluster: california
|
||||
user: myself
|
||||
name: california
|
||||
current-context: local
|
||||
kind: Config
|
||||
preferences: {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue