Skip to content

Commit

Permalink
feature(main): reset cluster not delete nodes
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu committed Sep 29, 2023
1 parent 708baf1 commit 6fc0bea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
11 changes: 11 additions & 0 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 Down

0 comments on commit 6fc0bea

Please sign in to comment.