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

Adds a node delete command #3716

Merged
merged 2 commits into from
Apr 2, 2024
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
17 changes: 17 additions & 0 deletions cmd/cli/node/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (s *NodeActionSuite) TestListNodes() {
)
s.Require().NoError(err)
s.Require().Contains(out, "Ok")

// Delete the node
_, out, err = s.ExecuteTestCobraCommand(
"node",
"delete",
nodeID,
)
s.Require().NoError(err)
s.Require().Contains(out, "Ok")

_, out, err = s.ExecuteTestCobraCommand(
"node",
"list",
"--output", "csv",
)
s.Require().NoError(err)
s.Require().NotContains(out, nodeID)
}

func getCells(output string, lineNo int) []string {
Expand Down
3 changes: 3 additions & 0 deletions cmd/cli/node/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ func NewCmd() *cobra.Command {
// Reject Action
cmd.AddCommand(NewActionCmd(apimodels.NodeActionReject))

// Reject Action
cmd.AddCommand(NewActionCmd(apimodels.NodeActionDelete))

return cmd
}
20 changes: 18 additions & 2 deletions pkg/node/manager/node_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (n *NodeManager) Delete(ctx context.Context, nodeID string) error {
// Approve is used to approve a node for joining the cluster along with a specific
// reason for the approval (for audit). The return values denote success and any
// failure of the operation as a human readable string.
func (n *NodeManager) Approve(ctx context.Context, nodeID string, reason string) (bool, string) {
func (n *NodeManager) ApproveAction(ctx context.Context, nodeID string, reason string) (bool, string) {
info, err := n.nodeInfo.GetByPrefix(ctx, nodeID)
if err != nil {
return false, err.Error()
Expand All @@ -212,7 +212,7 @@ func (n *NodeManager) Approve(ctx context.Context, nodeID string, reason string)
// Reject is used to reject a node from joining the cluster along with a specific
// reason for the rejection (for audit). The return values denote success and any
// failure of the operation as a human readable string.
func (n *NodeManager) Reject(ctx context.Context, nodeID string, reason string) (bool, string) {
func (n *NodeManager) RejectAction(ctx context.Context, nodeID string, reason string) (bool, string) {
info, err := n.nodeInfo.GetByPrefix(ctx, nodeID)
if err != nil {
return false, err.Error()
Expand All @@ -232,5 +232,21 @@ func (n *NodeManager) Reject(ctx context.Context, nodeID string, reason string)
return true, ""
}

// Reject is used to reject a node from joining the cluster along with a specific
// reason for the rejection (for audit). The return values denote success and any
// failure of the operation as a human readable string.
func (n *NodeManager) DeleteAction(ctx context.Context, nodeID string, reason string) (bool, string) {
info, err := n.nodeInfo.GetByPrefix(ctx, nodeID)
if err != nil {
return false, err.Error()
}

if err := n.nodeInfo.Delete(ctx, info.NodeID); err != nil {
return false, fmt.Sprintf("failed to delete nodeinfo: %s", err)
}

return true, ""
}

var _ compute.ManagementEndpoint = (*NodeManager)(nil)
var _ routing.NodeInfoStore = (*NodeManager)(nil)
5 changes: 4 additions & 1 deletion pkg/publicapi/apimodels/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type NodeAction string
const (
NodeActionApprove NodeAction = "approve"
NodeActionReject NodeAction = "reject"
NodeActionDelete NodeAction = "delete"
)

func (n NodeAction) Description() string {
Expand All @@ -67,10 +68,12 @@ func (n NodeAction) Description() string {
return "Approve a node whose membership is pending"
case NodeActionReject:
return "Reject a node whose membership is pending"
case NodeActionDelete:
return "Delete a node from the cluster."
}
return ""
}

func (n NodeAction) IsValid() bool {
return n == NodeActionApprove || n == NodeActionReject
return n == NodeActionApprove || n == NodeActionReject || n == NodeActionDelete
}
6 changes: 4 additions & 2 deletions pkg/publicapi/endpoint/orchestrator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ func (e *Endpoint) updateNode(c echo.Context) error {

var action func(context.Context, string, string) (bool, string)
if args.Action == string(apimodels.NodeActionApprove) {
action = e.nodeManager.Approve
action = e.nodeManager.ApproveAction
} else if args.Action == string(apimodels.NodeActionReject) {
action = e.nodeManager.Reject
action = e.nodeManager.RejectAction
} else if args.Action == string(apimodels.NodeActionDelete) {
action = e.nodeManager.DeleteAction
} else {
action = func(context.Context, string, string) (bool, string) {
return false, "unsupported action"
Expand Down
Loading