Skip to content

Commit 8661300

Browse files
authored
Merge pull request #6901 from zhzhuang-zju/automated-cherry-pick-of-#6866-upstream-release-1.13
Automated cherry pick of #6866: fix: use user-provided bootstrap server endpoint rather than
2 parents 84f5f6c + a781822 commit 8661300

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/karmadactl/register/register.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,17 @@ func (o *CommandRegisterOption) preflight() []error {
483483
return errlist
484484
}
485485

486+
func (o *CommandRegisterOption) getAPIServerEndpoint(clusterInfo *clientcmdapi.Cluster) string {
487+
// if the command has specified a bootstrap API server endpoint, use that instead of the one from the clusterinfo
488+
// since the one from the cluster-info is often local and unreachable from the pull cluster
489+
karmadaServer := clusterInfo.Server
490+
if o.BootstrapToken.APIServerEndpoint != "" {
491+
karmadaServer = fmt.Sprintf("https://%s", o.BootstrapToken.APIServerEndpoint)
492+
}
493+
494+
return karmadaServer
495+
}
496+
486497
// discoveryBootstrapConfigAndClusterInfo get bootstrap-config and cluster-info from control plane
487498
func (o *CommandRegisterOption) discoveryBootstrapConfigAndClusterInfo(parentCommand string) (*kubeclient.Clientset, *clientcmdapi.Cluster, error) {
488499
config, err := retrieveValidatedConfigInfo(nil, o.BootstrapToken, o.Timeout, DiscoveryRetryInterval, parentCommand)
@@ -492,8 +503,9 @@ func (o *CommandRegisterOption) discoveryBootstrapConfigAndClusterInfo(parentCom
492503

493504
klog.V(1).Info("[discovery] Using provided TLSBootstrapToken as authentication credentials for the join process")
494505
clusterinfo := tokenutil.GetClusterFromKubeConfig(config, "")
506+
495507
tlsBootstrapCfg := CreateWithToken(
496-
clusterinfo.Server,
508+
o.getAPIServerEndpoint(clusterinfo),
497509
DefaultClusterName,
498510
TokenUserName,
499511
clusterinfo.CertificateAuthorityData,
@@ -875,7 +887,7 @@ func (o *CommandRegisterOption) constructKubeConfig(bootstrapClient *kubeclient.
875887
}
876888

877889
return CreateWithCert(
878-
karmadaClusterInfo.Server,
890+
o.getAPIServerEndpoint(karmadaClusterInfo),
879891
DefaultClusterName,
880892
o.ClusterName,
881893
karmadaClusterInfo.CertificateAuthorityData,

0 commit comments

Comments
 (0)