update override behavior for kubectl --tls-server-name

Kubernetes-commit: 9dcbc0bf909a794cf77a801bfd29e306791b1e24
This commit is contained in:
David Eads 2020-03-03 13:16:50 -05:00 committed by Kubernetes Publisher
parent 55c8634c3c
commit 257e232d28
2 changed files with 29 additions and 2 deletions

View File

@ -124,6 +124,9 @@ func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluste
if o.server.Provided() {
modifiedCluster.Server = o.server.Value()
// specifying a --server on the command line, overrides the TLSServerName that was specified in the kubeconfig file.
// if both are specified, then the next if block will write the new TLSServerName.
modifiedCluster.TLSServerName = ""
}
if o.tlsServerName.Provided() {
modifiedCluster.TLSServerName = o.tlsServerName.Value()

View File

@ -58,7 +58,7 @@ func TestCreateCluster(t *testing.T) {
func TestModifyCluster(t *testing.T) {
conf := clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
"my-cluster": {Server: "https://192.168.0.1"},
"my-cluster": {Server: "https://192.168.0.1", TLSServerName: "to-be-cleared"},
},
}
test := createClusterTest{
@ -78,6 +78,30 @@ func TestModifyCluster(t *testing.T) {
test.run(t)
}
func TestModifyClusterServerAndTLS(t *testing.T) {
conf := clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
"my-cluster": {Server: "https://192.168.0.1"},
},
}
test := createClusterTest{
description: "Testing 'kubectl config set-cluster' with an existing cluster",
config: conf,
args: []string{"my-cluster"},
flags: []string{
"--server=https://192.168.0.99",
"--tls-server-name=my-cluster-name",
},
expected: `Cluster "my-cluster" set.` + "\n",
expectedConfig: clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
"my-cluster": {Server: "https://192.168.0.99", TLSServerName: "my-cluster-name"},
},
},
}
test.run(t)
}
func (test createClusterTest) run(t *testing.T) {
fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "")
if err != nil {
@ -117,7 +141,7 @@ func (test createClusterTest) run(t *testing.T) {
t.Errorf("Fail in %q\n expected cluster server %v\n but got %v\n ", test.description, test.expectedConfig.Clusters[test.args[0]].Server, cluster.Server)
}
if cluster.TLSServerName != test.expectedConfig.Clusters[test.args[0]].TLSServerName {
t.Errorf("Fail in %q\n expected cluster TLS server name %v\n but got %v\n ", test.description, test.expectedConfig.Clusters[test.args[0]].TLSServerName, cluster.TLSServerName)
t.Errorf("Fail in %q\n expected cluster TLS server name %q\n but got %q\n ", test.description, test.expectedConfig.Clusters[test.args[0]].TLSServerName, cluster.TLSServerName)
}
}
}