-
Notifications
You must be signed in to change notification settings - Fork 40
/
delete_nodes.go
26 lines (22 loc) · 1.01 KB
/
delete_nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package usecases
import (
"context"
"fmt"
"github.com/berops/claudie/internal/utils"
"github.com/berops/claudie/proto/pb"
"github.com/berops/claudie/services/kuber/server/domain/utils/nodes"
)
// DeleteNodes gracefully removes nodes from specified cluster.
func (u *Usecases) DeleteNodes(ctx context.Context, request *pb.DeleteNodesRequest) (*pb.DeleteNodesResponse, error) {
clusterID := utils.GetClusterID(request.Cluster.ClusterInfo)
logger := utils.CreateLoggerWithClusterName(clusterID)
logger.Info().Msgf("Deleting nodes - control nodes [%d], compute nodes[%d]", len(request.MasterNodes), len(request.WorkerNodes))
deleter := nodes.NewDeleter(request.MasterNodes, request.WorkerNodes, request.Cluster)
cluster, err := deleter.DeleteNodes()
if err != nil {
logger.Err(err).Msgf("Error while deleting nodes")
return nil, fmt.Errorf("error while deleting nodes for cluster %s : %w", clusterID, err)
}
logger.Info().Msgf("Nodes were successfully deleted")
return &pb.DeleteNodesResponse{Cluster: cluster}, nil
}