agent: use hypervisor pid as backup proxy pid for non-kata proxy cases

Then we can check hypervisor liveness in those cases to avoid long
timeout when connecting to the agent when hypervisor is dead.

For kata-agent, we still use the kata-proxy pid for the same purpose.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2019-07-19 03:40:10 -07:00
parent 835b6e9e1b
commit 67c401c059
5 changed files with 13 additions and 11 deletions

View File

@ -616,6 +616,7 @@ func (k *kataAgent) startProxy(sandbox *Sandbox) error {
proxyParams := proxyParams{
id: sandbox.id,
hid: sandbox.hypervisor.pid(),
path: sandbox.config.ProxyConfig.Path,
agentURL: agentURL,
consoleURL: consoleURL,
@ -1600,7 +1601,14 @@ func (k *kataAgent) connect() error {
return nil
}
k.Logger().WithField("url", k.state.URL).Info("New client")
if k.state.ProxyPid > 0 {
// check that proxy is running before talk with it avoiding long timeouts
if err := syscall.Kill(k.state.ProxyPid, syscall.Signal(0)); err != nil {
return errors.New("Proxy is not running")
}
}
k.Logger().WithField("url", k.state.URL).WithField("proxy", k.state.ProxyPid).Info("New client")
client, err := kataclient.NewAgentClient(k.ctx, k.state.URL, k.proxyBuiltIn)
if err != nil {
k.dead = true
@ -1792,13 +1800,6 @@ func (k *kataAgent) sendReq(request interface{}) (interface{}, error) {
span.SetTag("request", request)
defer span.Finish()
if k.state.ProxyPid > 0 {
// check that proxy is running before talk with it avoiding long timeouts
if err := syscall.Kill(k.state.ProxyPid, syscall.Signal(0)); err != nil {
return nil, fmt.Errorf("Proxy is not running: %v", err)
}
}
if err := k.connect(); err != nil {
return nil, err
}

View File

@ -64,7 +64,7 @@ func (p *kataBuiltInProxy) start(params proxyParams) (int, string, error) {
}
}
return -1, params.agentURL, nil
return params.hid, params.agentURL, nil
}
// stop is the proxy stop implementation for kata builtin proxy.

View File

@ -34,7 +34,7 @@ func (p *noProxy) start(params proxyParams) (int, string, error) {
return -1, "", fmt.Errorf("AgentURL cannot be empty")
}
return 0, params.agentURL, nil
return params.hid, params.agentURL, nil
}
// stop is noProxy stop implementation for proxy interface.

View File

@ -14,7 +14,7 @@ var noopProxyURL = "noopProxyURL"
// register is the proxy start implementation for testing purpose.
// It does nothing.
func (p *noopProxy) start(params proxyParams) (int, string, error) {
return 0, noopProxyURL, nil
return params.hid, noopProxyURL, nil
}
// stop is the proxy stop implementation for testing purpose.

View File

@ -28,6 +28,7 @@ type proxyParams struct {
agentURL string
consoleURL string
logger *logrus.Entry
hid int
debug bool
}