-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Support node and service maintenance mode #606
Changes from all commits
2973cd9
3fbb2be
35c10a9
1f749ce
8819d71
9ee1e6e
7748c62
8cf4e98
853cb50
ba2d0fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,3 +176,90 @@ func (s *HTTPServer) AgentDeregisterService(resp http.ResponseWriter, req *http. | |
serviceID := strings.TrimPrefix(req.URL.Path, "/v1/agent/service/deregister/") | ||
return nil, s.agent.RemoveService(serviceID, true) | ||
} | ||
|
||
func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
// Only PUT supported | ||
if req.Method != "PUT" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sooooo if we want to be pedantic, the API method here should technically be PATCH, not PUT. PATCH is used to update a partial resource, but PUT is used to update the entire resource. |
||
resp.WriteHeader(405) | ||
return nil, nil | ||
} | ||
|
||
// Ensure we have a service ID | ||
serviceID := strings.TrimPrefix(req.URL.Path, "/v1/agent/service/maintenance/") | ||
if serviceID == "" { | ||
resp.WriteHeader(400) | ||
resp.Write([]byte("Missing service ID")) | ||
return nil, nil | ||
} | ||
|
||
// Ensure we have some action | ||
params := req.URL.Query() | ||
if _, ok := params["enable"]; !ok { | ||
resp.WriteHeader(400) | ||
resp.Write([]byte("Missing value for enable")) | ||
return nil, nil | ||
} | ||
|
||
var enable bool | ||
raw := params.Get("enable") | ||
switch raw { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use strconv.ParseBool to be a bit more flexible to things like case. |
||
case "true": | ||
enable = true | ||
case "false": | ||
enable = false | ||
default: | ||
resp.WriteHeader(400) | ||
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw))) | ||
return nil, nil | ||
} | ||
|
||
var err error | ||
if enable { | ||
if err = s.agent.EnableServiceMaintenance(serviceID); err != nil { | ||
resp.WriteHeader(404) | ||
resp.Write([]byte(err.Error())) | ||
} | ||
} else { | ||
if err = s.agent.DisableServiceMaintenance(serviceID); err != nil { | ||
resp.WriteHeader(404) | ||
resp.Write([]byte(err.Error())) | ||
} | ||
} | ||
return nil, err | ||
} | ||
|
||
func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
// Only PUT supported | ||
if req.Method != "PUT" { | ||
resp.WriteHeader(405) | ||
return nil, nil | ||
} | ||
|
||
// Ensure we have some action | ||
params := req.URL.Query() | ||
if _, ok := params["enable"]; !ok { | ||
resp.WriteHeader(400) | ||
resp.Write([]byte("Missing value for enable")) | ||
return nil, nil | ||
} | ||
|
||
var enable bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same strconv.ParseBool here |
||
raw := params.Get("enable") | ||
switch raw { | ||
case "true": | ||
enable = true | ||
case "false": | ||
enable = false | ||
default: | ||
resp.WriteHeader(400) | ||
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw))) | ||
return nil, nil | ||
} | ||
|
||
if enable { | ||
s.agent.EnableNodeMaintenance() | ||
} else { | ||
s.agent.DisableNodeMaintenance() | ||
} | ||
return nil, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log something here for information sake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I missed that. Thanks!