mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-03 08:04:45 +00:00
Fix in-cluster kubectl --namespace override
Before this change, if the config was empty, ConfirmUsable() would return an "invalid configuration" error instead of examining and honoring the value of the --namespace flag. This change looks at the overrides first, and returns the overridden value if it exists before attempting to check if the config is usable. This is most applicable to in-cluster clients, where they don't have a kubeconfig but they do have a token and can use KUBERNETES_SERVICE_HOST/_PORT. Kubernetes-commit: 23e32b100fb9745b70203c30716697bd03926313
This commit is contained in:
committed by
Kubernetes Publisher
parent
18c8914690
commit
48409ad603
@@ -504,3 +504,25 @@ func matchByteArg(expected, got []byte, t *testing.T) {
|
||||
t.Errorf("Expected %v, got %v", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceOverride(t *testing.T) {
|
||||
config := &DirectClientConfig{
|
||||
overrides: &ConfigOverrides{
|
||||
Context: clientcmdapi.Context{
|
||||
Namespace: "foo",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ns, overridden, err := config.Namespace()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !overridden {
|
||||
t.Errorf("Expected overridden = true")
|
||||
}
|
||||
|
||||
matchStringArg("foo", ns, t)
|
||||
}
|
||||
|
Reference in New Issue
Block a user