From 0322139e6225bddfd62a9342df5937120b5f8967 Mon Sep 17 00:00:00 2001 From: Pilipalaca <85749695@qq.com> Date: Wed, 24 Nov 2021 23:46:06 +0800 Subject: [PATCH] feat: can specify the provider manually Signed-off-by: Pilipalaca <85749695@qq.com> change the params Signed-off-by: Pilipalaca <85749695@qq.com> --- pkg/karmadactl/join.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/karmadactl/join.go b/pkg/karmadactl/join.go index 4a3ee1775..1160f861b 100644 --- a/pkg/karmadactl/join.go +++ b/pkg/karmadactl/join.go @@ -99,6 +99,9 @@ type CommandJoinOption struct { // ClusterKubeConfig is the cluster's kubeconfig path. ClusterKubeConfig string + + // ClusterProvider is the cluster's provider. + ClusterProvider string } // Complete ensures that options are valid and marshals them if necessary. @@ -134,6 +137,7 @@ func (j *CommandJoinOption) AddFlags(flags *pflag.FlagSet) { "Context name of cluster in kubeconfig. Only works when there are multiple contexts in the kubeconfig.") flags.StringVar(&j.ClusterKubeConfig, "cluster-kubeconfig", "", "Path of the cluster's kubeconfig.") + flags.StringVar(&j.ClusterProvider, "cluster-provider", "", "Provider of the joining cluster.") } // RunJoin is the implementation of the 'join' command. @@ -194,7 +198,7 @@ func JoinCluster(controlPlaneRestConfig, clusterConfig *rest.Config, opts Comman return fmt.Errorf("failed to create secret in control plane. error: %v", err) } - cluster, err := generateClusterInControllerPlane(controlPlaneRestConfig, clusterConfig, opts.ClusterName, *secret) + cluster, err := generateClusterInControllerPlane(controlPlaneRestConfig, clusterConfig, opts, *secret) if err != nil { return err } @@ -278,9 +282,9 @@ func generateSecretInMemberCluster(clusterKubeClient kubeclient.Interface, clust return clusterSecret, nil } -func generateClusterInControllerPlane(controlPlaneConfig, clusterConfig *rest.Config, clusterName string, secret corev1.Secret) (*clusterv1alpha1.Cluster, error) { +func generateClusterInControllerPlane(controlPlaneConfig, clusterConfig *rest.Config, opts CommandJoinOption, secret corev1.Secret) (*clusterv1alpha1.Cluster, error) { clusterObj := &clusterv1alpha1.Cluster{} - clusterObj.Name = clusterName + clusterObj.Name = opts.ClusterName clusterObj.Spec.SyncMode = clusterv1alpha1.Push clusterObj.Spec.APIEndpoint = clusterConfig.Host clusterObj.Spec.SecretRef = &clusterv1alpha1.LocalSecretReference{ @@ -288,6 +292,10 @@ func generateClusterInControllerPlane(controlPlaneConfig, clusterConfig *rest.Co Name: secret.Name, } + if opts.ClusterProvider != "" { + clusterObj.Spec.Provider = opts.ClusterProvider + } + if clusterConfig.TLSClientConfig.Insecure { clusterObj.Spec.InsecureSkipTLSVerification = true } @@ -303,7 +311,7 @@ func generateClusterInControllerPlane(controlPlaneConfig, clusterConfig *rest.Co controlPlaneKarmadaClient := karmadaclientset.NewForConfigOrDie(controlPlaneConfig) cluster, err := CreateClusterObject(controlPlaneKarmadaClient, clusterObj, false) if err != nil { - return nil, fmt.Errorf("failed to create cluster object. cluster name: %s, error: %v", clusterName, err) + return nil, fmt.Errorf("failed to create cluster object. cluster name: %s, error: %v", opts.ClusterName, err) } return cluster, nil