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

Commit

Permalink
virtcontainers: share the agent's client between factory's VM and san…
Browse files Browse the repository at this point in the history
…dbox

When agent is configured as longLive, the VM's agent created
by factory will not close it's client once it connected, thus
the sandbox's agent cannot re-connect successfully.

Sharing the agent's client between VM's agent and sandbox
can fix this issue.

Fixes: #995

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Dec 10, 2018
1 parent a323a87 commit 20f2d30
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ type agent interface {
// get agent url
getAgentURL() (string, error)

// update the agent using some elements from another agent
reuseAgent(agent agent) error

// createSandbox will tell the agent to perform necessary setup for a Sandbox.
createSandbox(sandbox *Sandbox) error

Expand Down
11 changes: 11 additions & 0 deletions virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,17 @@ func (h *hyper) getAgentURL() (string, error) {
return "", nil
}

func (h *hyper) reuseAgent(agent agent) error {
a, ok := agent.(*hyper)
if !ok {
return fmt.Errorf("Bug: get a wrong type of agent")
}

h.client = a.client

return nil
}

func (h *hyper) setProxy(sandbox *Sandbox, proxy proxy, pid int, url string) error {
if url == "" {
return fmt.Errorf("invalid empty proxy url")
Expand Down
11 changes: 11 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ func (k *kataAgent) getAgentURL() (string, error) {
return k.agentURL()
}

func (k *kataAgent) reuseAgent(agent agent) error {
a, ok := agent.(*kataAgent)
if !ok {
return fmt.Errorf("Bug: get a wrong type of agent")
}

k.installReqFunc(a.client)
k.client = a.client
return nil
}

func (k *kataAgent) setProxy(sandbox *Sandbox, proxy proxy, pid int, url string) error {
if url == "" {
var err error
Expand Down
5 changes: 5 additions & 0 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (n *noopAgent) reseedRNG(data []byte) error {
return nil
}

// reuseAgent is the Noop agent reuser. It does nothing.
func (n *noopAgent) reuseAgent(agent agent) error {
return nil
}

// getAgentURL is the Noop agent url getter. It returns nothing.
func (n *noopAgent) getAgentURL() (string, error) {
return "", nil
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func (v *VM) assignSandbox(s *Sandbox) error {
return err
}

if err := s.agent.reuseAgent(v.agent); err != nil {
return err
}

// First make sure the symlinks do not exist
os.RemoveAll(sbSharePath)
os.RemoveAll(sbSockDir)
Expand Down

0 comments on commit 20f2d30

Please sign in to comment.