From 692fd198846de64784fcd03a1b3a66e25231b0a4 Mon Sep 17 00:00:00 2001 From: Eli Shvartsman Date: Mon, 15 Jul 2019 18:34:53 +0300 Subject: [PATCH] take NodeID from url in api for node eligibility --- command/agent/node_endpoint.go | 4 ++++ command/agent/node_endpoint_test.go | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/command/agent/node_endpoint.go b/command/agent/node_endpoint.go index 6b6f99750..3b10eb282 100644 --- a/command/agent/node_endpoint.go +++ b/command/agent/node_endpoint.go @@ -166,6 +166,10 @@ func (s *HTTPServer) nodeToggleEligibility(resp http.ResponseWriter, req *http.R if err := decodeBody(req, &eligibilityRequest); err != nil { return nil, CodedError(400, err.Error()) } + if eligibilityRequest.NodeID == "" { + eligibilityRequest.NodeID = nodeID + } + s.parseWriteRequest(req, &eligibilityRequest.WriteRequest) var out structs.NodeEligibilityUpdateResponse diff --git a/command/agent/node_endpoint_test.go b/command/agent/node_endpoint_test.go index 978c266f4..7a881be6a 100644 --- a/command/agent/node_endpoint_test.go +++ b/command/agent/node_endpoint_test.go @@ -370,13 +370,12 @@ func TestHTTP_NodeEligible(t *testing.T) { var resp structs.NodeUpdateResponse require.Nil(s.Agent.RPC("Node.Register", &args, &resp)) - drainReq := api.NodeUpdateEligibilityRequest{ - NodeID: node.ID, + eligibilityReq := api.NodeUpdateEligibilityRequest{ Eligibility: structs.NodeSchedulingIneligible, } // Make the HTTP request - buf := encodeReq(drainReq) + buf := encodeReq(eligibilityReq) req, err := http.NewRequest("POST", "/v1/node/"+node.ID+"/eligibility", buf) require.Nil(err) respW := httptest.NewRecorder() @@ -399,8 +398,8 @@ func TestHTTP_NodeEligible(t *testing.T) { require.Equal(structs.NodeSchedulingIneligible, out.SchedulingEligibility) // Make the HTTP request to set something invalid - drainReq.Eligibility = "foo" - buf = encodeReq(drainReq) + eligibilityReq.Eligibility = "foo" + buf = encodeReq(eligibilityReq) req, err = http.NewRequest("POST", "/v1/node/"+node.ID+"/eligibility", buf) require.Nil(err) respW = httptest.NewRecorder()