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:
Andy Goldstein
2017-05-23 15:31:40 -04:00
committed by Kubernetes Publisher
parent 18c8914690
commit 48409ad603
2 changed files with 31 additions and 5 deletions

View File

@@ -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)
}