Skip to content

Commit

Permalink
resolve domain to service ip
Browse files Browse the repository at this point in the history
  • Loading branch information
JameKeal committed Apr 4, 2023
1 parent 948d8be commit d4bc60b
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions cmd/yurthub/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package app
import (
"context"
"fmt"
"net"
"net/url"
"time"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -320,7 +332,7 @@ func coordinatorRun(ctx context.Context,
coordinatorTransportMgr = coorTransportMgr
coordinatorHealthChecker = coorHealthChecker
coordinator = coor
coordinatorServiceUrl = coordinatorServerURL
coordinatorServiceUrl = cfg.CoordinatorServerURL
}()

return func() healthchecker.HealthChecker {
Expand Down

0 comments on commit d4bc60b

Please sign in to comment.