Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
shim: Move creation of ShimParams structure into each agent
Browse files Browse the repository at this point in the history
In order to avoid increasing the number of parameters passed to the
shim preparation function, this commit moves the preparation of the
ShimParams structure to each agent implementation.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
  • Loading branch information
Sebastien Boeuf committed Feb 27, 2018
1 parent 8d41db3 commit ed3a0ea
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 22 deletions.
35 changes: 33 additions & 2 deletions hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

proxyClient "github.com/clearcontainers/proxy/client"
"github.com/containers/virtcontainers/pkg/hyperstart"
ns "github.com/containers/virtcontainers/pkg/nsenter"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
)
Expand Down Expand Up @@ -314,7 +315,22 @@ func (h *hyper) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) {
Process: *hyperProcess,
}

process, err := prepareAndStartShim(pod, h.shim, c.id, token, h.state.URL, cmd)
shimParams := ShimParams{
Container: c.id,
Token: token,
URL: h.state.URL,
Console: cmd.Console,
Terminal: cmd.Interactive,
Detach: cmd.Detach,
EnterNS: []ns.Namespace{
{
Path: pod.networkNS.NetNsPath,
Type: ns.NSTypeNet,
},
},
}

process, err := startShimWrapper(*pod, h.shim, shimParams)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -488,7 +504,22 @@ func (h *hyper) createContainer(pod *Pod, c *Container) (*Process, error) {
return nil, err
}

return prepareAndStartShim(pod, h.shim, c.id, token, h.state.URL, c.config.Cmd)
shimParams := ShimParams{
Container: c.id,
Token: token,
URL: h.state.URL,
Console: c.config.Cmd.Console,
Terminal: c.config.Cmd.Interactive,
Detach: c.config.Cmd.Detach,
EnterNS: []ns.Namespace{
{
Path: pod.networkNS.NetNsPath,
Type: ns.NSTypeNet,
},
},
}

return startShimWrapper(*pod, h.shim, shimParams)
}

// startContainer is the agent Container starting implementation for hyperstart.
Expand Down
35 changes: 33 additions & 2 deletions kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"syscall"

vcAnnotations "github.com/containers/virtcontainers/pkg/annotations"
ns "github.com/containers/virtcontainers/pkg/nsenter"
"github.com/containers/virtcontainers/pkg/uuid"
kataclient "github.com/kata-containers/agent/protocols/client"
"github.com/kata-containers/agent/protocols/grpc"
Expand Down Expand Up @@ -297,7 +298,22 @@ func (k *kataAgent) exec(pod *Pod, c Container, cmd Cmd) (*Process, error) {
return nil, err
}

return prepareAndStartShim(pod, k.shim, c.id, req.ExecId, k.state.URL, cmd)
shimParams := ShimParams{
Container: c.id,
Token: req.ExecId,
URL: k.state.URL,
Console: cmd.Console,
Terminal: cmd.Interactive,
Detach: cmd.Detach,
EnterNS: []ns.Namespace{
{
Path: pod.networkNS.NetNsPath,
Type: ns.NSTypeNet,
},
},
}

return startShimWrapper(*pod, k.shim, shimParams)
}

func (k *kataAgent) generateInterfacesAndRoutes(networkNS NetworkNamespace) ([]*grpc.Interface, []*grpc.Route, error) {
Expand Down Expand Up @@ -671,7 +687,22 @@ func (k *kataAgent) createContainer(pod *Pod, c *Container) (*Process, error) {
return nil, err
}

return prepareAndStartShim(pod, k.shim, c.id, req.ExecId, k.state.URL, c.config.Cmd)
shimParams := ShimParams{
Container: c.id,
Token: req.ExecId,
URL: k.state.URL,
Console: c.config.Cmd.Console,
Terminal: c.config.Cmd.Interactive,
Detach: c.config.Cmd.Detach,
EnterNS: []ns.Namespace{
{
Path: pod.networkNS.NetNsPath,
Type: ns.NSTypeNet,
},
},
}

return startShimWrapper(*pod, k.shim, shimParams)
}

func (k *kataAgent) startContainer(pod Pod, c *Container) error {
Expand Down
21 changes: 3 additions & 18 deletions shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,13 @@ func stopShim(pid int) error {
return nil
}

func prepareAndStartShim(pod *Pod, shim shim, cid, token, url string, cmd Cmd) (*Process, error) {
func startShimWrapper(pod Pod, shim shim, params ShimParams) (*Process, error) {
process := &Process{
Token: token,
Token: params.Token,
StartTime: time.Now().UTC(),
}

shimParams := ShimParams{
Container: cid,
Token: token,
URL: url,
Console: cmd.Console,
Terminal: cmd.Interactive,
Detach: cmd.Detach,
EnterNS: []ns.Namespace{
{
Path: pod.networkNS.NetNsPath,
Type: ns.NSTypeNet,
},
},
}

pid, err := shim.start(*pod, shimParams)
pid, err := shim.start(pod, params)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ed3a0ea

Please sign in to comment.