Skip to content

Commit

Permalink
virtcontainers: fix the issue of missing watchConsole
Browse files Browse the repository at this point in the history
When do the reloading sandbox in shimv2, it's needed to
rewatch the hypervisor's console when debug enabled.

Fixes:kata-containers#2091

Signed-off-by: lifupan <lifupan@gmail.com>
  • Loading branch information
lifupan committed Oct 18, 2019
1 parent 7d484df commit cb1f6e6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 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
41 changes: 28 additions & 13 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type kataAgent struct {
state KataAgentState
keepConn bool
proxyBuiltIn bool
useVsock bool
dynamicTracing bool
dead bool
kmodules []string
Expand Down Expand Up @@ -224,6 +225,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 @@ -297,6 +302,7 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config interface
disableVMShutdown = k.handleTraceSettings(c)
k.keepConn = c.LongLiveConn
k.kmodules = c.KernelModules
k.useVsock = c.UseVSock
default:
return false, vcTypes.ErrInvalidConfigType
}
Expand Down Expand Up @@ -350,6 +356,7 @@ func (k *kataAgent) internalConfigure(h hypervisor, id, sharePath string, builti
if config != nil {
switch c := config.(type) {
case KataAgentConfig:
k.useVsock = c.UseVSock
if k.vmSocket, err = h.generateSocket(id, c.UseVSock); err != nil {
return err
}
Expand Down Expand Up @@ -617,6 +624,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 +635,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 Expand Up @@ -1713,7 +1728,7 @@ func (k *kataAgent) connect() error {
}

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)
client, err := kataclient.NewAgentClient(k.ctx, k.state.URL, !k.useVsock)
if err != nil {
k.dead = true
return err
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func TestKataAgentSendReq(t *testing.T) {
state: KataAgentState{
URL: testKataProxyURL,
},
useVsock: true,
}

for _, req := range reqList {
Expand Down Expand Up @@ -790,6 +791,7 @@ func TestAgentNetworkOperation(t *testing.T) {
state: KataAgentState{
URL: testKataProxyURL,
},
useVsock: true,
}

_, err = k.updateInterface(nil)
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 cb1f6e6

Please sign in to comment.