virtcontainers: share the agent's client between factory's VM and sandbox

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 <lifupan@gmail.com>
This commit is contained in:
fupan 2018-12-10 18:17:36 +08:00
parent a323a87b59
commit 20f2d30ab8
5 changed files with 34 additions and 0 deletions

View File

@ -152,6 +152,9 @@ type agent interface {
// get agent url // get agent url
getAgentURL() (string, error) 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 will tell the agent to perform necessary setup for a Sandbox.
createSandbox(sandbox *Sandbox) error createSandbox(sandbox *Sandbox) error

View File

@ -964,6 +964,17 @@ func (h *hyper) getAgentURL() (string, error) {
return "", nil 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 { func (h *hyper) setProxy(sandbox *Sandbox, proxy proxy, pid int, url string) error {
if url == "" { if url == "" {
return fmt.Errorf("invalid empty proxy url") return fmt.Errorf("invalid empty proxy url")

View File

@ -537,6 +537,17 @@ func (k *kataAgent) getAgentURL() (string, error) {
return k.agentURL() 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 { func (k *kataAgent) setProxy(sandbox *Sandbox, proxy proxy, pid int, url string) error {
if url == "" { if url == "" {
var err error var err error

View File

@ -184,6 +184,11 @@ func (n *noopAgent) reseedRNG(data []byte) error {
return nil 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. // getAgentURL is the Noop agent url getter. It returns nothing.
func (n *noopAgent) getAgentURL() (string, error) { func (n *noopAgent) getAgentURL() (string, error) {
return "", nil return "", nil

View File

@ -319,6 +319,10 @@ func (v *VM) assignSandbox(s *Sandbox) error {
return err return err
} }
if err := s.agent.reuseAgent(v.agent); err != nil {
return err
}
// First make sure the symlinks do not exist // First make sure the symlinks do not exist
os.RemoveAll(sbSharePath) os.RemoveAll(sbSharePath)
os.RemoveAll(sbSockDir) os.RemoveAll(sbSockDir)