-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow Agent Reload with API - /v1/agent/reload #27106
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
dc56e7b
b64afe4
244bcc0
36ea900
6549d98
bb131b5
a53b746
f560f36
295ecd2
5c17fa5
a243a8c
1cbf394
f345955
8297287
906ca21
ddaa00a
ddc4a21
41c6db1
e13400b
dc19697
62de78a
9d8d293
7111dbd
f3e7335
1beb513
10364cb
db5251c
9adfab8
3d6e23d
51a0349
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 |
|---|---|---|
|
|
@@ -564,6 +564,52 @@ func (s *HTTPServer) listServers(resp http.ResponseWriter, req *http.Request) (i | |
| return peers, nil | ||
| } | ||
|
|
||
| type reloadResponse struct { | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| func (s *HTTPServer) AgentReloadRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
| if req.Method != http.MethodPut && req.Method != http.MethodPost { | ||
| return nil, CodedError(405, ErrInvalidMethod) | ||
| } | ||
|
|
||
| aclObj, err := s.ResolveToken(req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !aclObj.AllowAgentWrite() { | ||
| return nil, structs.ErrPermissionDenied | ||
| } | ||
|
|
||
| currConf := s.agent.GetConfig().Copy() | ||
|
|
||
| newConf := DefaultConfig() | ||
|
|
||
| for _, path := range currConf.Files { | ||
|
Member
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. If the
Contributor
Author
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. Thanks for catching this one, wasn't thinking of it or realized when I originally ran through it. Made some modifications to save the curl -k -X PUT \
https://localhost:4646/v1/agent/reload
Error loading /Users/benjamin.lykins/git/nomad/nomad/bin/config1/badfile.hcl: failed to decode HCL file /Users/benjamin.lykins/git/nomad/nomad/bin/config1/badfile.hcl: At 1:6: key 'asdf' expected start of object ('{') or assignment ('=') |
||
| if path == "" { | ||
| continue | ||
| } | ||
| if cfgFromFile, err := LoadConfig(path); err != nil { | ||
| s.logger.Error("failed to load config", "config", path, "error", err, "path", "/v1/agent/reload", "method", req.Method) | ||
| return nil, CodedError(400, error.Error(err)) | ||
| } else if cfgFromFile != nil { | ||
| newConf = newConf.Merge(cfgFromFile) | ||
| } | ||
| } | ||
|
|
||
| newConf.Files = append([]string(nil), currConf.Files...) | ||
|
|
||
| if err := s.agent.Reload(newConf); err != nil { | ||
|
Member
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. If you take a look at the signal handler for reloading, you'll see that this step only reloads the agent configuration and won't push any changes to the server, client, or HTTP server configuration. We should at least have parity with the signal handler here, which calls
Contributor
Author
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. This still needs to be done, and I'll start looking ahead at how to get this going. I saw this when I was mucking around with TLS rotations with server/client, and it was only updating the more general agent config. |
||
| return nil, CodedError(400, err.Error()) | ||
| } | ||
|
|
||
| response := reloadResponse{ | ||
| Message: "agent configuration reloaded", | ||
| } | ||
|
|
||
| return response, nil | ||
| } | ||
|
|
||
| func (s *HTTPServer) updateServers(resp http.ResponseWriter, req *http.Request) (interface{}, error) { | ||
| client := s.agent.Client() | ||
| if client == nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.