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

docs: Automated CherryPick Update for release-v4.4 #4022

Merged
merged 1 commit into from
Sep 29, 2023
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
4 changes: 2 additions & 2 deletions pkg/runtime/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func (k *K3s) ScaleUp(masters []string, nodes []string) error {
func (k *K3s) ScaleDown(masters []string, nodes []string) error {
if len(masters) != 0 {
logger.Info("master %s will be deleted", masters)
if err := k.resetNodes(masters); err != nil {
if err := k.removeNodes(masters); err != nil {
return err
}
}
if len(nodes) != 0 {
logger.Info("worker %s will be deleted", nodes)
return k.resetNodes(nodes)
return k.removeNodes(nodes)
}
return nil
}
Expand Down
18 changes: 16 additions & 2 deletions pkg/runtime/k3s/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ import (
)

func (k *K3s) resetNodes(nodes []string) error {
eg, _ := errgroup.WithContext(context.Background())
for i := range nodes {
node := nodes[i]
eg.Go(func() error {
return k.resetNode(node)
})
}
return eg.Wait()
}

func (k *K3s) removeNodes(nodes []string) error {
eg, _ := errgroup.WithContext(context.Background())
for i := range nodes {
node := nodes[i]
Expand All @@ -50,7 +61,7 @@ func (k *K3s) resetNode(host string) error {
if removeKubeConfigErr != nil {
logger.Error("failed to clean node, exec command %s failed, %v", removeKubeConfig, removeKubeConfigErr)
}
if slices.Contains(k.cluster.GetNodeIPList(), host) {
if slices.Contains(k.cluster.GetNodeIPAndPortList(), host) {
vipAndPort := fmt.Sprintf("%s:%d", k.cluster.GetVIP(), k.config.APIServerPort)
ipvsclearErr := k.remoteUtil.IPVSClean(host, vipAndPort)
if ipvsclearErr != nil {
Expand All @@ -63,7 +74,10 @@ func (k *K3s) resetNode(host string) error {
// TODO: remove from API
func (k *K3s) deleteNode(node string) error {
//remove master
masterIPs := strings.RemoveFromSlice(k.cluster.GetMasterIPList(), node)
masterIPs := k.cluster.GetMasterIPList()
if slices.Contains(k.cluster.GetMasterIPAndPortList(), node) {
masterIPs = strings.RemoveFromSlice(k.cluster.GetMasterIPList(), node)
}
if len(masterIPs) > 0 {
// TODO: do we need draining first?
if err := k.removeNode(node); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/kubernetes/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (k *KubeadmRuntime) resetNode(node string, cleanHook func()) error {
if removeKubeConfigErr != nil {
logger.Error("failed to clean node, exec command %s failed, %v", removeKubeConfig, removeKubeConfigErr)
}
if slices.Contains(k.cluster.GetNodeIPList(), node) {
if slices.Contains(k.cluster.GetNodeIPAndPortList(), node) {
ipvscleanErr := k.execIPVSClean(node)
if ipvscleanErr != nil {
logger.Error("failed to clean node route and ipvs failed, %v", ipvscleanErr)
Expand Down
Loading