Merge pull request #1025 from 2hangchen/feat_providerwithjoin

Specify the provider manually.
This commit is contained in:
karmada-bot 2021-11-25 20:36:03 +08:00 committed by GitHub
commit 76c7514724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -102,6 +102,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.
@ -139,6 +142,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.
@ -199,7 +203,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
}
@ -283,9 +287,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{
@ -293,6 +297,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
}
@ -308,7 +316,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