Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix k0s reset bug. #1753

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/runtime/k0s/delete_masters.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (k *Runtime) deleteMaster(master net.IP) error {
STEP7: delete node though k8s client
*/
remoteCleanCmd := []string{"k0s stop",
fmt.Sprintf("k0s reset --config %s --cri-socket %s", DefaultK0sConfigPath, ExternalCRI),
fmt.Sprintf("k0s reset --cri-socket %s", ExternalCRI),
"rm -rf /etc/k0s/",
fmt.Sprintf("sed -i \"/%s/d\" /etc/hosts", SeaHub),
fmt.Sprintf("sed -i \"/%s/d\" /etc/hosts", k.RegConfig.Domain),
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/k0s/delete_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (k *Runtime) deleteNode(node net.IP) error {
STEP7: delete node though k8s client
*/
remoteCleanCmds := []string{"k0s stop",
fmt.Sprintf("k0s reset --config %s --cri-socket %s", DefaultK0sConfigPath, ExternalCRI),
fmt.Sprintf("k0s reset --cri-socket %s", ExternalCRI),
"rm -rf /etc/k0s/",
fmt.Sprintf("sed -i \"/%s/d\" /etc/hosts", SeaHub),
fmt.Sprintf("sed -i \"/%s/d\" /etc/hosts", k.RegConfig.Domain),
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/k0s/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (k *Runtime) BootstrapMaster0() error {
if err != nil {
return err
}
bootstrapCMD := fmt.Sprintf("k0s install controller -c %s", DefaultK0sConfigPath)
bootstrapCMD := fmt.Sprintf("k0s install controller -c %s --cri-socket %s", DefaultK0sConfigPath, ExternalCRI)
if _, err := ssh.Cmd(master0IP, bootstrapCMD); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/k0s/join_masters.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (k *Runtime) joinMasters(masters []net.IP) error {
if err := k.CopyJoinToken(ControllerRole, masters); err != nil {
return err
}
cmds := k.Command(ControllerRole)
cmds := k.JoinCommand(ControllerRole)
if cmds == nil {
return fmt.Errorf("failed to get join master command")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/k0s/join_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (k *Runtime) joinNodes(nodes []net.IP) error {
if k.RegConfig.Username != "" && k.RegConfig.Password != "" {
addRegistryHostsAndLogin = fmt.Sprintf("%s && %s", addRegistryHostsAndLogin, k.GenLoginCommand())
}
cmds := k.Command(WorkerRole)
cmds := k.JoinCommand(WorkerRole)
if cmds == nil {
return fmt.Errorf("failed to get join node command")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/runtime/k0s/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ func (k *Runtime) resetNode(node net.IP) error {
if err != nil {
return err
}
/** To reset a node, do following command one by one:

/** To reset a node, do following commands one by one:
STEP1: stop k0s service
STEP2: reset the node with install configuration
STEP3: remove k0s cluster config generate by k0s under /etc/k0s
STEP4: remove private registry config in /etc/host
*/
if err := ssh.CmdAsync(node, "k0s stop",
fmt.Sprintf("k0s reset --config %s --cri-socket %s", DefaultK0sConfigPath, ExternalCRI),
fmt.Sprintf("k0s reset --cri-socket %s", ExternalCRI),
"rm -rf /etc/k0s/",
"rm -rf /usr/bin/kube* && rm -rf ~/.kube/",
fmt.Sprintf("sed -i \"/%s/d\" /etc/hosts", SeaHub),
Expand Down
7 changes: 3 additions & 4 deletions pkg/runtime/k0s/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ func (k *Runtime) CopyJoinToken(role string, hosts []net.IP) error {
return nil
}

func (k *Runtime) Command(role string) []string {
func (k *Runtime) JoinCommand(role string) []string {
cmds := map[string][]string{
ControllerRole: {"mkdir -r /etc/k0s", fmt.Sprintf("k0s config create > %s", DefaultK0sConfigPath),
fmt.Sprintf("sed -i '/ images/ a\\ repository: \"%s:%s\"' %s", k.RegConfig.Domain, k.RegConfig.Port, DefaultK0sConfigPath),
fmt.Sprintf("k0s install controller --token-file %s -c %s",
DefaultK0sControllerJoin, DefaultK0sConfigPath),
fmt.Sprintf("k0s install controller --token-file %s -c %s --cri-socket %s",
DefaultK0sControllerJoin, DefaultK0sConfigPath, ExternalCRI),
"k0s start",
},
WorkerRole: {fmt.Sprintf("k0s install worker --cri-socket %s --token-file %s", ExternalCRI, DefaultK0sWorkerJoin),
Expand All @@ -233,7 +233,6 @@ func (k *Runtime) Command(role string) []string {

v, ok := cmds[role]
if !ok {
logrus.Errorf("failed to get k0s command: %v", cmds)
return nil
}
return v
Expand Down