Add X-Consul-ContentHash header; implement removing all proxies; add load/unload test.

This commit is contained in:
Paul Banks 2018-04-18 21:48:58 +01:00 committed by Mitchell Hashimoto
parent 44afb5c699
commit cbd8606651
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 15 additions and 3 deletions

View File

@ -2444,7 +2444,11 @@ func (a *Agent) loadProxies(conf *config.RuntimeConfig) error {
// unloadProxies will deregister all proxies known to the local agent.
func (a *Agent) unloadProxies() error {
// TODO(banks): implement me
for id := range a.State.Proxies() {
if err := a.RemoveProxy(id, false); err != nil {
return fmt.Errorf("Failed deregistering proxy '%s': %s", id, err)
}
}
return nil
}

View File

@ -918,7 +918,7 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
// didn't want to make very general changes right away.
hash := req.URL.Query().Get("hash")
return s.agentLocalBlockingQuery(hash, &queryOpts,
return s.agentLocalBlockingQuery(resp, hash, &queryOpts,
func(updateCh chan struct{}) (string, interface{}, error) {
// Retrieve the proxy specified
proxy := s.agent.State.Proxy(id)
@ -972,7 +972,11 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
type agentLocalBlockingFunc func(updateCh chan struct{}) (string, interface{}, error)
func (s *HTTPServer) agentLocalBlockingQuery(hash string,
// agentLocalBlockingQuery performs a blocking query in a generic way against
// local agent state that has no RPC or raft to back it. It uses `hash` paramter
// instead of an `index`. The resp is needed to write the `X-Consul-ContentHash`
// header back on return no Status nor body content is ever written to it.
func (s *HTTPServer) agentLocalBlockingQuery(resp http.ResponseWriter, hash string,
queryOpts *structs.QueryOptions, fn agentLocalBlockingFunc) (interface{}, error) {
var timer *time.Timer
@ -1011,6 +1015,8 @@ func (s *HTTPServer) agentLocalBlockingQuery(hash string,
break
}
}
resp.Header().Set("X-Consul-ContentHash", curHash)
return curResp, err
}
}

View File

@ -2358,6 +2358,8 @@ func TestAgentConnectProxy(t *testing.T) {
}
assert.Equal(tt.wantResp, obj)
assert.Equal(tt.wantResp.ContentHash, resp.Header().Get("X-Consul-ContentHash"))
})
}
}