diff --git a/cmd/yurthub/app/start.go b/cmd/yurthub/app/start.go index c6cccf17933..e680683bc6a 100644 --- a/cmd/yurthub/app/start.go +++ b/cmd/yurthub/app/start.go @@ -19,6 +19,7 @@ package app import ( "context" "fmt" + "net" "net/url" "time" @@ -259,26 +260,37 @@ func coordinatorRun(ctx context.Context, // resolve pool-coordinator-apiserver and etcd from domain to ips serviceList := cfg.SharedFactory.Core().V1().Services().Lister() - apiServerService, err := serviceList.Services(util.YurtHubNamespace).Get(util.DefaultPoolCoordinatorAPIServerSvcName) + // if pool-coordinator-apiserver and pool-coordinator-etcd address is ip, don't need to resolve + apiServerIP := net.ParseIP(cfg.CoordinatorServerURL.Hostname()) + etcdUrl, err := url.Parse(cfg.CoordinatorStorageAddr) if err != nil { - klog.Errorf("coordinator failed to get apiServer service, %v", err) + klog.Errorf("coordinator parse etcd address failed: %+v", err) return } - etcdService, err := serviceList.Services(util.YurtHubNamespace).Get(util.DefaultPoolCoordinatorEtcdSvcName) - if err != nil { - klog.Errorf("coordinator failed to get etcd service, %v", err) - return + etcdIP := net.ParseIP(etcdUrl.Hostname()) + if apiServerIP == nil { + apiServerService, err := serviceList.Services(util.YurtHubNamespace).Get(cfg.CoordinatorServerURL.Hostname()) + if err != nil { + klog.Errorf("coordinator failed to get apiServer service, %v", err) + return + } + // rewrite coordinator service info for cfg + coordinatorServerURL, err := + url.Parse(fmt.Sprintf("https://%s:%s", apiServerService.Spec.ClusterIP, cfg.CoordinatorServerURL.Port())) + if err != nil { + klog.Errorf("coordinator failed to parse apiServer service, %v", err) + return + } + cfg.CoordinatorServerURL = coordinatorServerURL } - - // rewrite coordinator service info for cfg - coordinatorServerURL, err := - url.Parse(fmt.Sprintf("https://%s:%s", apiServerService.Spec.ClusterIP, util.DefaultPoolCoordinatorAPIServerSvcPort)) - if err != nil { - klog.Errorf("coordinator failed to parse apiServer service, %v", err) - return + if etcdIP == nil { + etcdService, err := serviceList.Services(util.YurtHubNamespace).Get(etcdUrl.Hostname()) + if err != nil { + klog.Errorf("coordinator failed to get etcd service, %v", err) + return + } + cfg.CoordinatorStorageAddr = fmt.Sprintf("https://%s:%s", etcdService.Spec.ClusterIP, etcdUrl.Port()) } - cfg.CoordinatorServerURL = coordinatorServerURL - cfg.CoordinatorStorageAddr = fmt.Sprintf("https://%s:%s", etcdService.Spec.ClusterIP, util.DefaultPoolCoordinatorEtcdSvcPort) coorTransportMgr, err := poolCoordinatorTransportMgrGetter(coorCertManager, ctx.Done()) if err != nil { @@ -320,7 +332,7 @@ func coordinatorRun(ctx context.Context, coordinatorTransportMgr = coorTransportMgr coordinatorHealthChecker = coorHealthChecker coordinator = coor - coordinatorServiceUrl = coordinatorServerURL + coordinatorServiceUrl = cfg.CoordinatorServerURL }() return func() healthchecker.HealthChecker {