diff --git a/pkg/build/edgeimage/internal/kube/source.go b/pkg/build/edgeimage/internal/kube/source.go index 30d880c..be4d8ea 100644 --- a/pkg/build/edgeimage/internal/kube/source.go +++ b/pkg/build/edgeimage/internal/kube/source.go @@ -31,6 +31,7 @@ import ( // this is used by FindSource const ImportPath = "kubeedge" +// FindSource attempts to locate a KubeEdge checkout using go's build package func FindSource() (root string, err error) { // look up the source the way go build would pkg, err := build.Default.Import(ImportPath, build.Default.GOPATH, build.FindOnly|build.IgnoreVendor) @@ -44,6 +45,8 @@ func FindSource() (root string, err error) { return "", errors.New("could not find kubeedge source") } +// maybeKubeDir returns true if the dir looks plausibly like a kubernetes +// source directory func maybeKubeDir(dir string) bool { // TODO(bentheelder): consider adding other sanity checks // check if 'go.mod' exists in the directory @@ -60,18 +63,19 @@ func findOrCloneKubeEdge(importPath string) (string, error) { return filepath.Dir(pkg[0].GoFiles[0]), nil } + branch := "release-1.17" localDir := filepath.Join(build.Default.GOPATH, "src", importPath) fmt.Println("Cloning KubeEdge from GitHub to", localDir) - if err := gitClone("https://github.com/kubeedge/kubeedge.git", localDir); err != nil { + if err := gitClone("https://github.com/kubeedge/kubeedge.git", branch, localDir); err != nil { return "", err } return localDir, nil } -func gitClone(repoURL, localDir string) error { - cmd := exec.Command("git", "clone", repoURL, localDir) +func gitClone(repoURL, branch, localDir string) error { + cmd := exec.Command("git", "clone", "--branch", branch, repoURL, localDir) if err := cmd.Run(); err != nil { return fmt.Errorf("failed to clone KubeEdge repository: %w", err) } diff --git a/pkg/cluster/internal/create/actions/kubeedge/kubeedge.go b/pkg/cluster/internal/create/actions/kubeedge/kubeedge.go index dd34b61..12b252e 100644 --- a/pkg/cluster/internal/create/actions/kubeedge/kubeedge.go +++ b/pkg/cluster/internal/create/actions/kubeedge/kubeedge.go @@ -177,7 +177,7 @@ func (a *Action) startCloudcoreWithKeadm(ctx *actions.ActionContext, node nodes. // cloudcore svc use NodePort type, to enable edgecore connect to cloudcore, we may add the below routes on the host //iptables -t nat -A PREROUTING -d ${advertise-address} -p tcp --dport 10000 -j DNAT --to-destination ${NODE_IP}:30000 //iptables -t nat -A PREROUTING -d ${advertise-address} -p tcp --dport 10002 -j DNAT --to-destination ${NODE_IP}:30002 - startCmd := fmt.Sprintf("keadm init --advertise-address=%s --profile version=v1.17.0 --kube-config /etc/kubernetes/admin.conf --set cloudCore.hostNetWork=false", a.AdvertiseAddress) + startCmd := fmt.Sprintf("keadm init --advertise-address=%s --kubeedge-version=v1.15.1 --kube-config /etc/kubernetes/admin.conf --set cloudCore.hostNetWork=false", a.AdvertiseAddress) cmd := node.Command("bash", "-c", startCmd) lines, err := exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) @@ -326,31 +326,39 @@ func (a *Action) runStartEdgecore(ctx *actions.ActionContext, node nodes.Node) e return fmt.Errorf("failed to generate cloudcore config: %v", err) } - cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|token: .*|token: %s|g" /etc/kubeedge/config/edgecore.yaml`, KubeEdgeToken)) + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "/metaServer:/{n;n;s/false/true/;}" /etc/kubeedge/config/edgecore.yaml`)) lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) if err != nil { - return fmt.Errorf("failed to modify token: %v", err) + return fmt.Errorf("failed to modify metaServer: %v", err) + } + + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|runtimeType: .*|runtimeType: remote|g" /etc/kubeedge/config/edgecore.yaml`)) + lines, err = exec.CombinedOutputLines(cmd) + ctx.Logger.V(3).Info(strings.Join(lines, "\n")) + if err != nil { + return fmt.Errorf("failed to modify runtimeType: %v", err) } - // modify runtime to containerd - cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|remoteImageEndpoint: .*|remoteImageEndpoint: %s|g" /etc/kubeedge/config/edgecore.yaml`, "unix:///var/run/containerd/containerd.sock")) + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|cgroupDriver: .*|cgroupDriver: systemd|g" /etc/kubeedge/config/edgecore.yaml`)) lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) if err != nil { - return fmt.Errorf("failed to modify remoteImageEndpoint: %v", err) + return fmt.Errorf("failed to modify cgroupDriver: %v", err) } - cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|remoteRuntimeEndpoint: .*|remoteRuntimeEndpoint: %s|g" /etc/kubeedge/config/edgecore.yaml`, "unix:///var/run/containerd/containerd.sock")) + + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|imageServiceEndpoint: .*|imageServiceEndpoint: %s|g" /etc/kubeedge/config/edgecore.yaml`, "unix:///var/run/containerd/containerd.sock")) lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) if err != nil { - return fmt.Errorf("failed to modify remoteRuntimeEndpoint: %v", err) + return fmt.Errorf("failed to modify imageServiceEndpoint to remote: %v", err) } - cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|containerRuntime: .*|containerRuntime: %s|g" /etc/kubeedge/config/edgecore.yaml`, "remote")) + + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|containerRuntimeEndpoint: .*|containerRuntimeEndpoint: %s|g" /etc/kubeedge/config/edgecore.yaml`, "unix:///var/run/containerd/containerd.sock")) lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) if err != nil { - return fmt.Errorf("failed to modify containerRuntime to remote: %v", err) + return fmt.Errorf("failed to modify containerRuntimeEndpoint to remote: %v", err) } // modify edgeHub.httpServer websocker.server ip cloudcore ip or control-plane ip @@ -381,6 +389,12 @@ func (a *Action) runStartEdgecore(ctx *actions.ActionContext, node nodes.Node) e return fmt.Errorf("failed to modify resolv: %v", err) } + cmd = node.Command("bash", "-c", fmt.Sprintf(`sed -i -e "s|token: .*|token: %s|g" /etc/kubeedge/config/edgecore.yaml`, KubeEdgeToken)) + lines, err = exec.CombinedOutputLines(cmd) + ctx.Logger.V(3).Info(strings.Join(lines, "\n")) + if err != nil { + return fmt.Errorf("failed to modify token: %v", err) + } cmd = node.Command("bash", "-c", "systemctl daemon-reload && systemctl enable edgecore && systemctl start edgecore") lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n")) @@ -405,10 +419,12 @@ func (a *Action) runStartEdgecoreWithKeadm(ctx *actions.ActionContext, node node return fmt.Errorf("failed to cleanup directory /etc/kubeedge: %v", err) } + //keadm join --cloudcore-ipport=172.23.0.3:10000 --token=8d8d0c5a218e93148f4b5a15e06775ff452377ecc2ed984f8e35ea6fd0bea91d.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTY3MzQ0ODN9.VsTIOiLDu49OsTWcSGB8IXsCXltdSj4IoULD_1PkCB0 --cgroupdriver=systemd + // not start MQTT conainer, error: E0728 01:07:37.717267 1429 remote_runtime.go:116] "RunPodSandbox from runtime service failed" err="rpc error: code = Unknown // desc = failed to reserve sandbox name \"mqtt___0\": name \"mqtt___0\" is reserved for \"264c9ad4f0be7271711a21b0c89f958da582e1869a3b18fb07dd719b16989595\"" // TODO: debug why edgecore segmentfault with nothing - joinCmd := fmt.Sprintf("keadm join --cloudcore-ipport %s --certport 30002 --token %s --remote-runtime-endpoint unix:///var/run/containerd/containerd.sock --runtimetype remote --with-mqtt=false", controlPlaneIP+":30000", KubeEdgeToken) + joinCmd := fmt.Sprintf("keadm join --cgroupdriver=systemd --cloudcore-ipport=%s --token=%s --remote-runtime-endpoint=unix:///var/run/containerd/containerd.sock", controlPlaneIP+":10000", KubeEdgeToken) cmd = node.Command("bash", "-c", joinCmd) lines, err = exec.CombinedOutputLines(cmd) ctx.Logger.V(3).Info(strings.Join(lines, "\n"))