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 #996 from lifupan/fixFactory
Browse files Browse the repository at this point in the history
virtcontainers: share the agent's client between factory's VM and san…
  • Loading branch information
bergwolf committed Dec 11, 2018
2 parents 4cc94b6 + 20f2d30 commit 8f22d67
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
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
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
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
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
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 8f22d67

Please sign in to comment.