Skip to content

Commit

Permalink
feature: yurtadm join add yurthubserveraddr para
Browse files Browse the repository at this point in the history
  • Loading branch information
luc99hen committed Sep 20, 2022
1 parent 25d7ffc commit 6f2044c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions pkg/yurtadm/cmd/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -80,6 +81,7 @@ func newJoinOptions() *joinOptions {
unsafeSkipCAVerification: false,
ignorePreflightErrors: make([]string, 0),
kubernetesResourceServer: yurtconstants.DefaultKubernetesResourceServer,
yurthubServer: yurtconstants.DefaultYurtHubServerAddr,
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtadm/cmd/join/joindata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type YurtJoinData interface {
JoinToken() string
PauseImage() string
YurtHubImage() string
YurtHubServer() string
KubernetesVersion() string
TLSBootstrapCfg() *clientcmdapi.Config
BootstrapClient() *clientset.Clientset
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtadm/cmd/join/phases/joinnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/yurtadm/cmd/join/phases/postcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/yurtadm/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/yurtadm/constants/join_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
3 changes: 2 additions & 1 deletion pkg/yurtadm/util/edgenode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ spec:
command:
- yurthub
- --v=2
- --bind-address={{.yurthubServerAddr}}
- --server-addr={{.kubernetesServerAddr}}
- --node-name=$(NODE_NAME)
- --join-token={{.joinToken}}
Expand All @@ -102,7 +103,7 @@ spec:
{{end}}
livenessProbe:
httpGet:
host: 127.0.0.1
host: {{.yurthubServerAddr}}
path: /v1/healthz
port: 10267
initialDelaySeconds: 300
Expand Down

0 comments on commit 6f2044c

Please sign in to comment.