From 6f2044c566e8347277e8ed2834c8151fdde71cda Mon Sep 17 00:00:00 2001 From: luc99hen <1813927768@qq.com> Date: Mon, 29 Aug 2022 21:05:50 +0800 Subject: [PATCH] feature: yurtadm join add yurthubserveraddr para --- pkg/yurtadm/cmd/join/join.go | 13 +++++++++++++ pkg/yurtadm/cmd/join/joindata/data.go | 1 + pkg/yurtadm/cmd/join/phases/joinnode.go | 1 + pkg/yurtadm/cmd/join/phases/postcheck.go | 6 +++--- pkg/yurtadm/constants/constants.go | 1 + pkg/yurtadm/constants/join_options.go | 3 +++ pkg/yurtadm/util/edgenode/common.go | 3 ++- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/yurtadm/cmd/join/join.go b/pkg/yurtadm/cmd/join/join.go index 6b14d446597..6fc5403fd7b 100644 --- a/pkg/yurtadm/cmd/join/join.go +++ b/pkg/yurtadm/cmd/join/join.go @@ -67,6 +67,7 @@ type joinOptions struct { ignorePreflightErrors []string nodeLabels string kubernetesResourceServer string + yurthubServer string } // newJoinOptions returns a struct ready for being used for creating cmd join flags. @@ -80,6 +81,7 @@ func newJoinOptions() *joinOptions { unsafeSkipCAVerification: false, ignorePreflightErrors: make([]string, 0), kubernetesResourceServer: yurtconstants.DefaultKubernetesResourceServer, + yurthubServer: yurtconstants.DefaultYurtHubServerAddr, } } @@ -165,6 +167,10 @@ func addJoinConfigFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) { &joinOptions.kubernetesResourceServer, yurtconstants.KubernetesResourceServer, joinOptions.kubernetesResourceServer, "Sets the address for downloading k8s node resources", ) + flagSet.StringVar( + &joinOptions.yurthubServer, yurtconstants.YurtHubServerAddr, joinOptions.yurthubServer, + "Sets the address for yurthub server addr", + ) } type joinData struct { @@ -181,6 +187,7 @@ type joinData struct { caCertHashes sets.String nodeLabels map[string]string kubernetesResourceServer string + yurthubServer string } // newJoinData returns a new joinData struct to be used for the execution of the kubeadm join workflow. @@ -233,6 +240,7 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri ignorePreflightErrors: ignoreErrors, pauseImage: opt.pauseImage, yurthubImage: opt.yurthubImage, + yurthubServer: opt.yurthubServer, caCertHashes: sets.NewString(opt.caCertHashes...), organizations: opt.organizations, nodeLabels: make(map[string]string), @@ -305,6 +313,11 @@ func (j *joinData) YurtHubImage() string { return j.yurthubImage } +// YurtHubServer returns the YurtHub server addr. +func (j *joinData) YurtHubServer() string { + return j.yurthubServer +} + // KubernetesVersion returns the kubernetes version. func (j *joinData) KubernetesVersion() string { return j.kubernetesVersion diff --git a/pkg/yurtadm/cmd/join/joindata/data.go b/pkg/yurtadm/cmd/join/joindata/data.go index 92dc4e085fb..99861337841 100644 --- a/pkg/yurtadm/cmd/join/joindata/data.go +++ b/pkg/yurtadm/cmd/join/joindata/data.go @@ -34,6 +34,7 @@ type YurtJoinData interface { JoinToken() string PauseImage() string YurtHubImage() string + YurtHubServer() string KubernetesVersion() string TLSBootstrapCfg() *clientcmdapi.Config BootstrapClient() *clientset.Clientset diff --git a/pkg/yurtadm/cmd/join/phases/joinnode.go b/pkg/yurtadm/cmd/join/phases/joinnode.go index 91fa7dfa657..0f27ed02b24 100644 --- a/pkg/yurtadm/cmd/join/phases/joinnode.go +++ b/pkg/yurtadm/cmd/join/phases/joinnode.go @@ -183,6 +183,7 @@ func addYurthubStaticYaml(data joindata.YurtJoinData, podManifestPath string) er "joinToken": data.JoinToken(), "workingMode": data.NodeRegistration().WorkingMode, "organizations": data.NodeRegistration().Organizations, + "yurthubServerAddr": data.YurtHubServer(), } yurthubTemplate, err := templates.SubsituteTemplate(edgenode.YurthubTemplate, ctx) diff --git a/pkg/yurtadm/cmd/join/phases/postcheck.go b/pkg/yurtadm/cmd/join/phases/postcheck.go index ac6c482f7da..3a93faa8973 100644 --- a/pkg/yurtadm/cmd/join/phases/postcheck.go +++ b/pkg/yurtadm/cmd/join/phases/postcheck.go @@ -63,7 +63,7 @@ func runPostCheck(c workflow.RunData) error { klog.V(1).Infof("kubelet service is active") klog.V(1).Infof("waiting hub agent ready.") - if err := checkYurthubHealthz(); err != nil { + if err := checkYurthubHealthz(j); err != nil { return err } klog.V(1).Infof("hub agent is ready") @@ -85,8 +85,8 @@ func checkKubeletStatus() error { } //checkYurthubHealthz check if YurtHub is healthy. -func checkYurthubHealthz() error { - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s%s", edgenode.ServerHealthzServer, edgenode.ServerHealthzURLPath), nil) +func checkYurthubHealthz(joinData joindata.YurtJoinData) error { + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s%s", fmt.Sprintf("%s:10267", joinData.YurtHubServer()), edgenode.ServerHealthzURLPath), nil) if err != nil { return err } diff --git a/pkg/yurtadm/constants/constants.go b/pkg/yurtadm/constants/constants.go index d7874cb4021..6e8d9e9b0fe 100644 --- a/pkg/yurtadm/constants/constants.go +++ b/pkg/yurtadm/constants/constants.go @@ -52,6 +52,7 @@ const ( YurtTunnelServer = "yurt-tunnel-server" YurtTunnelAgent = "yurt-tunnel-agent" Yurthub = "yurthub" + DefaultYurtHubServerAddr = "127.0.0.1" YurtAppManager = "yurt-app-manager" YurtAppManagerNamespace = "kube-system" DirMode = 0755 diff --git a/pkg/yurtadm/constants/join_options.go b/pkg/yurtadm/constants/join_options.go index 750e8c5b00b..7781723df51 100644 --- a/pkg/yurtadm/constants/join_options.go +++ b/pkg/yurtadm/constants/join_options.go @@ -35,4 +35,7 @@ const ( // KubernetesResourceServer flag sets the address for download k8s node resources. KubernetesResourceServer = "kubernetes-resource-server" + + // YurtHubServerAddr flag set the address of yurthub server (not proxy server!) + YurtHubServerAddr = "yurthub-server-addr" ) diff --git a/pkg/yurtadm/util/edgenode/common.go b/pkg/yurtadm/util/edgenode/common.go index 38e5619dc34..41c86d4fec1 100644 --- a/pkg/yurtadm/util/edgenode/common.go +++ b/pkg/yurtadm/util/edgenode/common.go @@ -87,6 +87,7 @@ spec: command: - yurthub - --v=2 + - --bind-address={{.yurthubServerAddr}} - --server-addr={{.kubernetesServerAddr}} - --node-name=$(NODE_NAME) - --join-token={{.joinToken}} @@ -102,7 +103,7 @@ spec: {{end}} livenessProbe: httpGet: - host: 127.0.0.1 + host: {{.yurthubServerAddr}} path: /v1/healthz port: 10267 initialDelaySeconds: 300