From 5b8e5313f403c44ecd70c6e705775145c0ae9510 Mon Sep 17 00:00:00 2001 From: "lan.liang" Date: Thu, 28 Jan 2021 00:47:05 +0800 Subject: [PATCH] Feature:Support specified kubeadm conf for join cluster --- pkg/yurtctl/cmd/convert/convert.go | 11 +++++++++++ pkg/yurtctl/cmd/revert/revert.go | 11 +++++++++++ pkg/yurtctl/constants/constants.go | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/pkg/yurtctl/cmd/convert/convert.go b/pkg/yurtctl/cmd/convert/convert.go index 7e3398cfc88..0720dcd75f0 100644 --- a/pkg/yurtctl/cmd/convert/convert.go +++ b/pkg/yurtctl/cmd/convert/convert.go @@ -58,6 +58,7 @@ type ConvertOptions struct { YurttunnelServerImage string YurttunnelAgentImage string PodMainfestPath string + KubeadmConfPath string DeployTunnel bool kubeConfigPath string } @@ -101,6 +102,9 @@ func NewConvertCmd() *cobra.Command { cmd.Flags().String("yurtctl-servant-image", "openyurt/yurtctl-servant:latest", "The yurtctl-servant image.") + cmd.Flags().String("kubeadm-conf-path", + "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf", + "The path to kubelet service conf that is used by kubelet component to join the cluster on the edge node.") cmd.Flags().String("yurt-tunnel-server-image", "openyurt/yurt-tunnel-server:latest", "The yurt-tunnel-server image.") @@ -174,6 +178,12 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error { } co.PodMainfestPath = pmp + kcp, err := flags.GetString("kubeadm-conf-path") + if err != nil { + return err + } + co.KubeadmConfPath = kcp + // parse kubeconfig and generate the clientset co.clientSet, err = kubeutil.GenClientSet(flags) if err != nil { @@ -320,6 +330,7 @@ func (co *ConvertOptions) RunConvert() (err error) { "yurthub_image": co.YurhubImage, "joinToken": joinToken, "pod_manifest_path": co.PodMainfestPath, + "kubeadm_conf_path": co.KubeadmConfPath, }, edgeNodeNames); err != nil { klog.Errorf("fail to run ServantJobs: %s", err) return diff --git a/pkg/yurtctl/cmd/revert/revert.go b/pkg/yurtctl/cmd/revert/revert.go index 9970354da69..a57279f8d64 100644 --- a/pkg/yurtctl/cmd/revert/revert.go +++ b/pkg/yurtctl/cmd/revert/revert.go @@ -39,6 +39,7 @@ import ( type RevertOptions struct { clientSet *kubernetes.Clientset YurtctlServantImage string + KubeadmConfPath string } // NewConvertOptions creates a new RevertOptions @@ -65,6 +66,9 @@ func NewRevertCmd() *cobra.Command { cmd.Flags().String("yurtctl-servant-image", "openyurt/yurtctl-servant:latest", "The yurtctl-servant image.") + cmd.Flags().String("kubeadm-conf-path", + "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf", + "The path to kubelet service conf that is used by kubelet component to join the cluster on the edge node.") return cmd } @@ -77,6 +81,12 @@ func (ro *RevertOptions) Complete(flags *pflag.FlagSet) error { } ro.YurtctlServantImage = ycsi + kcp, err := flags.GetString("kubeadm-conf-path") + if err != nil { + return err + } + ro.KubeadmConfPath = kcp + ro.clientSet, err = kubeutil.GenClientSet(flags) if err != nil { return err @@ -224,6 +234,7 @@ func (ro *RevertOptions) RunRevert() (err error) { map[string]string{ "action": "revert", "yurtctl_servant_image": ro.YurtctlServantImage, + "kubeadm_conf_path": ro.KubeadmConfPath, }, edgeNodeNames); err != nil { klog.Errorf("fail to revert edge node: %s", err) diff --git a/pkg/yurtctl/constants/constants.go b/pkg/yurtctl/constants/constants.go index 42abf518e7a..83879937a55 100644 --- a/pkg/yurtctl/constants/constants.go +++ b/pkg/yurtctl/constants/constants.go @@ -199,5 +199,9 @@ spec: fieldPath: spec.nodeName - name: STATIC_POD_PATH value: {{.pod_manifest_path}} + {{if .kubeadm_conf_path }} + - name: KUBELET_SVC + value: {{.kubeadm_conf_path}} + {{end}} ` )