mirror of https://github.com/hashicorp/consul
Add X-Consul-ContentHash header; implement removing all proxies; add load/unload test.
parent
2a69663448
commit
d73f079d0f
|
@ -2444,7 +2444,11 @@ func (a *Agent) loadProxies(conf *config.RuntimeConfig) error {
|
||||||
|
|
||||||
// unloadProxies will deregister all proxies known to the local agent.
|
// unloadProxies will deregister all proxies known to the local agent.
|
||||||
func (a *Agent) unloadProxies() error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -918,7 +918,7 @@ func (s *HTTPServer) AgentConnectProxyConfig(resp http.ResponseWriter, req *http
|
||||||
// didn't want to make very general changes right away.
|
// didn't want to make very general changes right away.
|
||||||
hash := req.URL.Query().Get("hash")
|
hash := req.URL.Query().Get("hash")
|
||||||
|
|
||||||
return s.agentLocalBlockingQuery(hash, &queryOpts,
|
return s.agentLocalBlockingQuery(resp, hash, &queryOpts,
|
||||||
func(updateCh chan struct{}) (string, interface{}, error) {
|
func(updateCh chan struct{}) (string, interface{}, error) {
|
||||||
// Retrieve the proxy specified
|
// Retrieve the proxy specified
|
||||||
proxy := s.agent.State.Proxy(id)
|
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)
|
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) {
|
queryOpts *structs.QueryOptions, fn agentLocalBlockingFunc) (interface{}, error) {
|
||||||
|
|
||||||
var timer *time.Timer
|
var timer *time.Timer
|
||||||
|
@ -1011,6 +1015,8 @@ func (s *HTTPServer) agentLocalBlockingQuery(hash string,
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Header().Set("X-Consul-ContentHash", curHash)
|
||||||
return curResp, err
|
return curResp, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2358,6 +2358,8 @@ func TestAgentConnectProxy(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(tt.wantResp, obj)
|
assert.Equal(tt.wantResp, obj)
|
||||||
|
|
||||||
|
assert.Equal(tt.wantResp.ContentHash, resp.Header().Get("X-Consul-ContentHash"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue