Skip to content

Commit

Permalink
feature: yurtadm join add yurthubserveraddr para (#1011)
Browse files Browse the repository at this point in the history
* feature: yurtadm join add yurthubserveraddr para

* Fix: filter nil ip addr
  • Loading branch information
luc99hen authored Sep 20, 2022
1 parent 25d7ffc commit db7ea27
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/node-servant/components/yurthub.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/klog/v2"

"github.com/openyurtio/openyurt/pkg/util/templates"
constants "github.com/openyurtio/openyurt/pkg/yurtadm/constants"
enutil "github.com/openyurtio/openyurt/pkg/yurtadm/util/edgenode"
"github.com/openyurtio/openyurt/pkg/yurthub/certificate/hubself"
"github.com/openyurtio/openyurt/pkg/yurthub/storage/disk"
Expand Down Expand Up @@ -74,6 +75,7 @@ func (op *yurtHubOperator) Install() error {
// 1-1. replace variables in yaml file
klog.Infof("setting up yurthub apiServer addr")
yurthubTemplate, err := templates.SubsituteTemplate(enutil.YurthubTemplate, map[string]string{
"yurthubServerAddr": constants.DefaultYurtHubServerAddr,
"kubernetesServerAddr": op.apiServerAddr,
"image": op.yurthubImage,
"joinToken": op.joinToken,
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func RemoveDupIPs(ips []net.IP) []net.IP {
results := make([]net.IP, 0, len(ips))
temp := map[string]bool{}
for _, ip := range ips {
if _, ok := temp[string(ip)]; !ok {
if _, ok := temp[string(ip)]; ip != nil && !ok {
temp[string(ip)] = true
results = append(results, ip)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/ip/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func TestRemoveDupIPs(t *testing.T) {
nil,
[]net.IP{},
},
{
"nil ip",
[]net.IP{[]byte("1.1.1.1"), nil},
[]net.IP{[]byte("1.1.1.1")},
},
}

for _, test := range tests {
Expand Down
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 db7ea27

Please sign in to comment.