mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Allow to configure clustername in creation of kubeconfig using kubeadm command
Signed-off-by: Prabhu Jayakumar <j.prabhu91@gmail.com>
This commit is contained in:
parent
b497fa1d34
commit
bdd0ccaddb
@ -99,6 +99,7 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
|
||||
|
||||
// Add ClusterConfiguration backed flags to the command
|
||||
cmd.Flags().StringVar(&clusterCfg.CertificatesDir, options.CertificatesDir, clusterCfg.CertificatesDir, "The path where certificates are stored")
|
||||
cmd.Flags().StringVar(&clusterCfg.ClusterName, "cluster-name", clusterCfg.ClusterName, "Cluster name to be used in kubeconfig")
|
||||
|
||||
// Add InitConfiguration backed flags to the command
|
||||
cmd.Flags().StringVar(&initCfg.LocalAPIEndpoint.AdvertiseAddress, options.APIServerAdvertiseAddress, initCfg.LocalAPIEndpoint.AdvertiseAddress, "The IP address the API server is accessible on")
|
||||
|
@ -56,6 +56,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
|
||||
command string
|
||||
withClientCert bool
|
||||
withToken bool
|
||||
withClusterName bool
|
||||
additionalFlags []string
|
||||
}{
|
||||
{
|
||||
@ -63,12 +64,26 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
|
||||
command: "user",
|
||||
withClientCert: true,
|
||||
},
|
||||
{
|
||||
name: "user subCommand withClientCert",
|
||||
command: "user",
|
||||
withClientCert: true,
|
||||
withClusterName: true,
|
||||
additionalFlags: []string{"--cluster-name=my-cluster"},
|
||||
},
|
||||
{
|
||||
name: "user subCommand withToken",
|
||||
withToken: true,
|
||||
command: "user",
|
||||
additionalFlags: []string{"--token=123456"},
|
||||
},
|
||||
{
|
||||
name: "user subCommand withToken",
|
||||
withToken: true,
|
||||
command: "user",
|
||||
withClusterName: true,
|
||||
additionalFlags: []string{"--token=123456", "--cluster-name=my-cluster"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@ -104,6 +119,11 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
|
||||
// checks that kubeconfig files have expected token
|
||||
kubeconfigtestutil.AssertKubeConfigCurrentAuthInfoWithToken(t, config, "myUser", "123456")
|
||||
}
|
||||
|
||||
if test.withClusterName {
|
||||
// checks that kubeconfig files have expected cluster name
|
||||
kubeconfigtestutil.AssertKubeConfigCurrentContextWithClusterName(t, config, "my-cluster")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -98,3 +98,15 @@ func AssertKubeConfigCurrentAuthInfoWithToken(t *testing.T, config *clientcmdapi
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// AssertKubeConfigCurrentContextWithClusterName is a utility function for kubeadm testing that asserts if the Current Cluster config in
|
||||
// the given KubeConfig object refers to expected cluster name
|
||||
func AssertKubeConfigCurrentContextWithClusterName(t *testing.T, config *clientcmdapi.Config, expectedClusterName string) {
|
||||
currentContext := config.Contexts[config.CurrentContext]
|
||||
|
||||
// assert cluster name
|
||||
if currentContext.Cluster != expectedClusterName {
|
||||
t.Errorf("kubeconfig.currentContext.clusterName [%s], expected [%s]", currentContext.Cluster, expectedClusterName)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user