Merge pull request #2092 from lifupan/fixmissingwatchconsole

virtcontainers: fix the issue of missing watchConsole
This commit is contained in:
Peng Tao 2019-11-01 09:47:11 +08:00 committed by GitHub
commit 254b85aec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 15 deletions

View File

@ -126,6 +126,9 @@ type agent interface {
// check will check the agent liveness // check will check the agent liveness
check() error check() error
// tell whether the agent is long live connected or not
longLiveConn() bool
// disconnect will disconnect the connection to the agent // disconnect will disconnect the connection to the agent
disconnect() error disconnect() error

View File

@ -187,9 +187,9 @@ func FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
return nil, err return nil, err
} }
// If the proxy is KataBuiltInProxyType type, it needs to restart the proxy to watch the // If the agent is long live connection, it needs to restart the proxy to
// guest console if it hadn't been watched. // watch the guest console if it hadn't been watched.
if isProxyBuiltIn(s.config.ProxyType) { if s.agent.longLiveConn() {
err = s.startProxy() err = s.startProxy()
if err != nil { if err != nil {
s.Release() s.Release()

View File

@ -224,6 +224,10 @@ func (k *kataAgent) getSharePath(id string) string {
return filepath.Join(kataHostSharedDir(), id) return filepath.Join(kataHostSharedDir(), id)
} }
func (k *kataAgent) longLiveConn() bool {
return k.keepConn
}
// KataAgentSetDefaultTraceConfigOptions validates agent trace options and // KataAgentSetDefaultTraceConfigOptions validates agent trace options and
// sets defaults. // sets defaults.
func KataAgentSetDefaultTraceConfigOptions(config *KataAgentConfig) error { func KataAgentSetDefaultTraceConfigOptions(config *KataAgentConfig) error {
@ -617,6 +621,7 @@ func (k *kataAgent) startProxy(sandbox *Sandbox) error {
defer span.Finish() defer span.Finish()
var err error var err error
var agentURL string
if k.proxy == nil { if k.proxy == nil {
return errorMissingProxy return errorMissingProxy
@ -627,18 +632,25 @@ func (k *kataAgent) startProxy(sandbox *Sandbox) error {
} }
if k.state.URL != "" { if k.state.URL != "" {
k.Logger().WithFields(logrus.Fields{ // For keepConn case, when k.state.URL isn't nil, it means shimv2 had disconnected from
"sandbox": sandbox.id, // sandbox and try to relaunch sandbox again. Here it needs to start proxy again to watch
"proxy-pid": k.state.ProxyPid, // the hypervisor console.
"proxy-url": k.state.URL, if k.keepConn {
}).Infof("proxy already started") agentURL = k.state.URL
return nil } else {
} k.Logger().WithFields(logrus.Fields{
"sandbox": sandbox.id,
// Get agent socket path to provide it to the proxy. "proxy-pid": k.state.ProxyPid,
agentURL, err := k.agentURL() "proxy-url": k.state.URL,
if err != nil { }).Infof("proxy already started")
return err return nil
}
} else {
// Get agent socket path to provide it to the proxy.
agentURL, err = k.agentURL()
if err != nil {
return err
}
} }
consoleURL, err := sandbox.hypervisor.getSandboxConsole(sandbox.id) consoleURL, err := sandbox.hypervisor.getSandboxConsole(sandbox.id)

View File

@ -32,6 +32,10 @@ func (n *noopAgent) init(ctx context.Context, sandbox *Sandbox, config interface
return false, nil return false, nil
} }
func (n *noopAgent) longLiveConn() bool {
return false
}
// createSandbox is the Noop agent sandbox creation implementation. It does nothing. // createSandbox is the Noop agent sandbox creation implementation. It does nothing.
func (n *noopAgent) createSandbox(sandbox *Sandbox) error { func (n *noopAgent) createSandbox(sandbox *Sandbox) error {
return nil return nil