Skip to content

Commit

Permalink
use default staticPath (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzhoul authored Oct 10, 2021
1 parent 11cc701 commit 0765d05
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 74 deletions.
11 changes: 11 additions & 0 deletions docs/tutorial/yurtctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,14 @@ 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
```
6 changes: 1 addition & 5 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions pkg/yurtctl/cmd/convert/edgenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/yurtctl/cmd/revert/edgenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/yurtctl/cmd/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 3 additions & 27 deletions pkg/yurtctl/util/edgenode/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package edgenode

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -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
}
29 changes: 1 addition & 28 deletions pkg/yurtctl/util/edgenode/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0765d05

Please sign in to comment.