@@ -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
487498func (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