diff --git a/docs/tutorial/yurtctl.md b/docs/tutorial/yurtctl.md index b750408b77b..aad2fb60ec8 100644 --- a/docs/tutorial/yurtctl.md +++ b/docs/tutorial/yurtctl.md @@ -332,3 +332,13 @@ running the following command in edge node directly: ``` $ sudo sed -i "s|--kubeconfig=.*kubelet.conf|--kubeconfig=/etc/kubernetes/kubelet.conf|g;" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf && sudo systemctl daemon-reload && sudo systemctl restart kubelet.service ``` + +### 3. Failure due to incorrect podManifests path. + +PodManifests path is the dir where k8s static pod YAML file located. +Tools like kubeadm/minikube/kind all set that path to /etc/kubernetes/manifests. And we choose to follow that setting. + +So if you manually change that setting, this will leads to a convert failure. +To fix it, we recommend creating a soft link: + + ln -s $yourSettingPath /etc/kubernetes/manifests \ No newline at end of file diff --git a/pkg/yurtctl/cmd/convert/convert.go b/pkg/yurtctl/cmd/convert/convert.go index 690ecf3d22c..b157d281ce9 100644 --- a/pkg/yurtctl/cmd/convert/convert.go +++ b/pkg/yurtctl/cmd/convert/convert.go @@ -234,11 +234,7 @@ func (co *ConvertOptions) Complete(flags *pflag.FlagSet) error { } co.KubeadmConfPath = kcp - podManifestPath, err := enutil.GetPodManifestPath(co.KubeadmConfPath) - if err != nil { - return err - } - co.PodMainfestPath = podManifestPath + co.PodMainfestPath = enutil.GetPodManifestPath() sa, err := flags.GetString("system-architecture") if err != nil { diff --git a/pkg/yurtctl/cmd/convert/edgenode.go b/pkg/yurtctl/cmd/convert/edgenode.go index 53ab08fa7f5..b4bcf1ced85 100644 --- a/pkg/yurtctl/cmd/convert/edgenode.go +++ b/pkg/yurtctl/cmd/convert/edgenode.go @@ -310,10 +310,7 @@ func (c *ConvertEdgeNodeOptions) SetupYurthub() error { }) // 1-3. create yurthub.yaml - podManifestPath, err := enutil.GetPodManifestPath(c.KubeadmConfPath) - if err != nil { - return err - } + podManifestPath := enutil.GetPodManifestPath() if err = enutil.EnsureDir(podManifestPath); err != nil { return err } diff --git a/pkg/yurtctl/cmd/revert/edgenode.go b/pkg/yurtctl/cmd/revert/edgenode.go index 31798f78881..8711481b855 100644 --- a/pkg/yurtctl/cmd/revert/edgenode.go +++ b/pkg/yurtctl/cmd/revert/edgenode.go @@ -190,11 +190,7 @@ func (r *RevertEdgeNodeOptions) RunRevertEdgeNode() (err error) { klog.Errorf("fail to get file %s, should revise the %s directly", kubeletSvcBk, r.KubeadmConfPath) return err } - podManifestPath, err := enutil.GetPodManifestPath(r.KubeadmConfPath) - if err != nil { - klog.Errorf("get podManifestPath fail: %v", err) - return err - } + podManifestPath := enutil.GetPodManifestPath() yurthubYamlPath := getYurthubYaml(podManifestPath) if ok, err := enutil.FileExists(yurthubYamlPath); !ok { return err diff --git a/pkg/yurtctl/cmd/revert/revert.go b/pkg/yurtctl/cmd/revert/revert.go index 3c6e4a81978..4e23c61ffea 100644 --- a/pkg/yurtctl/cmd/revert/revert.go +++ b/pkg/yurtctl/cmd/revert/revert.go @@ -92,11 +92,7 @@ func (ro *RevertOptions) Complete(flags *pflag.FlagSet) error { } ro.KubeadmConfPath = kcp - podManifestPath, err := enutil.GetPodManifestPath(ro.KubeadmConfPath) - if err != nil { - return err - } - ro.PodMainfestPath = podManifestPath + ro.PodMainfestPath = enutil.GetPodManifestPath() ro.clientSet, err = kubeutil.GenClientSet(flags) if err != nil { diff --git a/pkg/yurtctl/util/edgenode/util.go b/pkg/yurtctl/util/edgenode/util.go index 6af885ee529..98eff8fe93c 100644 --- a/pkg/yurtctl/util/edgenode/util.go +++ b/pkg/yurtctl/util/edgenode/util.go @@ -17,7 +17,6 @@ limitations under the License. package edgenode import ( - "errors" "fmt" "io/ioutil" "os" @@ -201,30 +200,7 @@ func Exec(cmd *exec.Cmd) error { return nil } -// GetPodManifestPath get path string from kubeadmConf file -func GetPodManifestPath(kubeadmConfPath string) (string, error) { - configRegularExpression := "\\-\\-config=.*config.yaml" - podManifestPathRegularExpression := "staticPodPath: .*" - - configPath, err := GetSingleContentFromFile(kubeadmConfPath, configRegularExpression) - if err != nil { - return "", err - } - arr := strings.Split(configPath, "=") - if len(arr) != 2 { - return "", errors.New("kubelet config path format incorrect: " + configPath) - } - configPath = arr[1] - - podManifestPath, err := GetSingleContentFromFile(configPath, podManifestPathRegularExpression) - if err != nil { - return "", err - } - arr = strings.Split(podManifestPath, " ") - if len(arr) != 2 { - return "", errors.New("podManifestPath format incorrect: " + podManifestPath) - } - podManifestPath = arr[1] - - return podManifestPath, nil +// GetPodManifestPath return podManifestPath, use default value of kubeadm/minikube/kind. etc. +func GetPodManifestPath() string { + return StaticPodPath // /etc/kubernetes/manifests } diff --git a/pkg/yurtctl/util/edgenode/util_test.go b/pkg/yurtctl/util/edgenode/util_test.go index 194b70295c2..13bdb0fe849 100644 --- a/pkg/yurtctl/util/edgenode/util_test.go +++ b/pkg/yurtctl/util/edgenode/util_test.go @@ -17,39 +17,12 @@ limitations under the License. package edgenode import ( - "io/ioutil" - "os" "testing" ) -var kubeadmConf = ` -[Service] -Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf" -Environment="KUBELET_CONFIG_ARGS=--config=/tmp/openyurt-test/config.yaml" -EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env -EnvironmentFile=-/etc/default/kubelet -ExecStart= -ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS` - -var confYaml = `serializeImagePulls: true -staticPodPath: /etc/kubernetes/manifests -streamingConnectionIdleTimeout: 4h0m0s -syncFrequency: 1m0s` - func Test_GetPodManifestPath(t *testing.T) { - err := EnsureDir("/tmp/openyurt-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll("/tmp/openyurt-test") - _ = ioutil.WriteFile("/tmp/openyurt-test/kubeadm.conf", []byte(kubeadmConf), 0755) - _ = ioutil.WriteFile("/tmp/openyurt-test/config.yaml", []byte(confYaml), 0755) - - path, err := GetPodManifestPath("/tmp/openyurt-test/kubeadm.conf") - if err != nil { - t.Fatal(err) - } + path := GetPodManifestPath() if path != "/etc/kubernetes/manifests" { t.Fatal("get path err: " + path) }