Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2092 from lifupan/fixmissingwatchconsole
Browse files Browse the repository at this point in the history
virtcontainers: fix the issue of missing watchConsole
  • Loading branch information
bergwolf authored Nov 1, 2019
2 parents 764ba9f + c51d492 commit 254b85a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type agent interface {
// check will check the agent liveness
check() error

// tell whether the agent is long live connected or not
longLiveConn() bool

// disconnect will disconnect the connection to the agent
disconnect() error

Expand Down
6 changes: 3 additions & 3 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ func FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
return nil, err
}

// If the proxy is KataBuiltInProxyType type, it needs to restart the proxy to watch the
// guest console if it hadn't been watched.
if isProxyBuiltIn(s.config.ProxyType) {
// If the agent is long live connection, it needs to restart the proxy to
// watch the guest console if it hadn't been watched.
if s.agent.longLiveConn() {
err = s.startProxy()
if err != nil {
s.Release()
Expand Down
36 changes: 24 additions & 12 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (k *kataAgent) getSharePath(id string) string {
return filepath.Join(kataHostSharedDir(), id)
}

func (k *kataAgent) longLiveConn() bool {
return k.keepConn
}

// KataAgentSetDefaultTraceConfigOptions validates agent trace options and
// sets defaults.
func KataAgentSetDefaultTraceConfigOptions(config *KataAgentConfig) error {
Expand Down Expand Up @@ -617,6 +621,7 @@ func (k *kataAgent) startProxy(sandbox *Sandbox) error {
defer span.Finish()

var err error
var agentURL string

if k.proxy == nil {
return errorMissingProxy
Expand All @@ -627,18 +632,25 @@ func (k *kataAgent) startProxy(sandbox *Sandbox) error {
}

if k.state.URL != "" {
k.Logger().WithFields(logrus.Fields{
"sandbox": sandbox.id,
"proxy-pid": k.state.ProxyPid,
"proxy-url": k.state.URL,
}).Infof("proxy already started")
return nil
}

// Get agent socket path to provide it to the proxy.
agentURL, err := k.agentURL()
if err != nil {
return err
// For keepConn case, when k.state.URL isn't nil, it means shimv2 had disconnected from
// sandbox and try to relaunch sandbox again. Here it needs to start proxy again to watch
// the hypervisor console.
if k.keepConn {
agentURL = k.state.URL
} else {
k.Logger().WithFields(logrus.Fields{
"sandbox": sandbox.id,
"proxy-pid": k.state.ProxyPid,
"proxy-url": k.state.URL,
}).Infof("proxy already started")
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)
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (n *noopAgent) init(ctx context.Context, sandbox *Sandbox, config interface
return false, nil
}

func (n *noopAgent) longLiveConn() bool {
return false
}

// createSandbox is the Noop agent sandbox creation implementation. It does nothing.
func (n *noopAgent) createSandbox(sandbox *Sandbox) error {
return nil
Expand Down

0 comments on commit 254b85a

Please sign in to comment.