Skip to content
Open
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
18 changes: 12 additions & 6 deletions mkaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ const (

type MKaaSNodes interface {
NodesList(ctx context.Context, clusterID, poolID int, opts *MKaaSNodeListOptions) ([]MKaaSNode, *Response, error)
NodeDelete(ctx context.Context, clusterID, poolID, nodeID int) (*TaskResponse, *Response, error)

NodesDelete(ctx context.Context, clusterID, poolID int,
reqBody MKaaSNodesDeleteRequest) (*TaskResponse, *Response, error)
}

type MKaaSPools interface {
Expand Down Expand Up @@ -287,6 +289,10 @@ type MKaaSPoolUpdateLabelsRequest struct {
Labels map[string]string `json:"labels,omitempty"`
}

type MKaaSNodesDeleteRequest struct {
NodeIDs []int `json:"node_ids"`
}

type MKaaSPoolUpdateTaintsRequest struct {
Taints []MKaaSTaint `json:"taints"`
}
Expand Down Expand Up @@ -738,22 +744,22 @@ func (m *MKaaSServiceOp) NodesList(
return root.Nodes, resp, nil
}

func (m *MKaaSServiceOp) NodeDelete(
ctx context.Context, clusterID, poolID, nodeID int,
// NodesDelete deletes the specified nodes from a pool.
func (m *MKaaSServiceOp) NodesDelete(
ctx context.Context, clusterID, poolID int, reqBody MKaaSNodesDeleteRequest,
) (*TaskResponse, *Response, error) {
if resp, err := m.client.Validate(); err != nil {
return nil, resp, err
}

path := fmt.Sprintf(
"%s/%d/pools/%d/nodes/%d",
"%s/%d/pools/%d/nodes/delete",
m.client.addProjectRegionPath(MKaaSClustersBasePathV2),
clusterID,
poolID,
nodeID,
)

req, err := m.client.NewRequest(ctx, http.MethodDelete, path, nil)
req, err := m.client.NewRequest(ctx, http.MethodPost, path, reqBody)
if err != nil {
return nil, nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions mkaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,26 +597,26 @@ func TestMKaaSServiceOp_NodesList(t *testing.T) {
require.Equal(t, respActual, expectedResp)
}

func TestMKaaSServiceOp_NodeDelete(t *testing.T) {
func TestMKaaSServiceOp_NodesDelete(t *testing.T) {
setup()
defer teardown()

const testNodeID = testResourceIntID + 1
request := MKaaSNodesDeleteRequest{NodeIDs: []int{testResourceIntID + 1, testResourceIntID + 2}}

expectedResp := &TaskResponse{Tasks: []string{taskID}}
URL := path.Join(MKaaSClustersBasePathV2, strconv.Itoa(projectID), strconv.Itoa(regionID),
strconv.Itoa(testResourceIntID), "pools", strconv.Itoa(mkaasTestPoolID), "nodes", strconv.Itoa(testNodeID))
strconv.Itoa(testResourceIntID), "pools", strconv.Itoa(mkaasTestPoolID), "nodes", "delete")

mux.HandleFunc(URL, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
testMethod(t, r, http.MethodPost)
resp, err := json.Marshal(expectedResp)
if err != nil {
t.Errorf("failed to marshal response: %v", err)
}
_, _ = fmt.Fprint(w, string(resp))
})

respActual, resp, err := client.MkaaS.NodeDelete(ctx, testResourceIntID, mkaasTestPoolID, testNodeID)
respActual, resp, err := client.MkaaS.NodesDelete(ctx, testResourceIntID, mkaasTestPoolID, request)
require.NoError(t, err)
require.Equal(t, resp.StatusCode, 200)
require.Equal(t, respActual, expectedResp)
Expand Down
Loading