virtcontainers: always pass sandbox as a pointer

Currently we sometimes pass it as a pointer and other times not. As
a result, the view of sandbox across virtcontainers may not be the same
and it costs extra memory copy each time we pass it by value. Fix it
by ensuring sandbox is always passed by pointers.

Fixes: #262

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao 2018-04-24 02:04:54 +08:00
parent 8d897f407f
commit 5fb4768f83
34 changed files with 131 additions and 131 deletions

View File

@ -143,27 +143,27 @@ type agent interface {
exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error)
// startSandbox will tell the agent to start all containers related to the Sandbox. // startSandbox will tell the agent to start all containers related to the Sandbox.
startSandbox(sandbox Sandbox) error startSandbox(sandbox *Sandbox) error
// stopSandbox will tell the agent to stop all containers related to the Sandbox. // stopSandbox will tell the agent to stop all containers related to the Sandbox.
stopSandbox(sandbox Sandbox) error stopSandbox(sandbox *Sandbox) error
// createContainer will tell the agent to create a container related to a Sandbox. // createContainer will tell the agent to create a container related to a Sandbox.
createContainer(sandbox *Sandbox, c *Container) (*Process, error) createContainer(sandbox *Sandbox, c *Container) (*Process, error)
// startContainer will tell the agent to start a container related to a Sandbox. // startContainer will tell the agent to start a container related to a Sandbox.
startContainer(sandbox Sandbox, c *Container) error startContainer(sandbox *Sandbox, c *Container) error
// stopContainer will tell the agent to stop a container related to a Sandbox. // stopContainer will tell the agent to stop a container related to a Sandbox.
stopContainer(sandbox Sandbox, c Container) error stopContainer(sandbox *Sandbox, c Container) error
// killContainer will tell the agent to send a signal to a // killContainer will tell the agent to send a signal to a
// container related to a Sandbox. If all is true, all processes in // container related to a Sandbox. If all is true, all processes in
// the container will be sent the signal. // the container will be sent the signal.
killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error killContainer(sandbox *Sandbox, c Container, signal syscall.Signal, all bool) error
// processListContainer will list the processes running inside the container // processListContainer will list the processes running inside the container
processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) processListContainer(sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error)
// onlineCPUMem will online CPUs and Memory inside the Sandbox. // onlineCPUMem will online CPUs and Memory inside the Sandbox.
// This function should be called after hot adding vCPUs or Memory. // This function should be called after hot adding vCPUs or Memory.

View File

@ -528,7 +528,7 @@ func TestStartSandboxHyperstartAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestStartSandboxKataAgentSuccessful(t *testing.T) { func TestStartSandboxKataAgentSuccessful(t *testing.T) {
@ -568,7 +568,7 @@ func TestStartSandboxKataAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestStartSandboxFailing(t *testing.T) { func TestStartSandboxFailing(t *testing.T) {
@ -800,7 +800,7 @@ func TestRunSandboxHyperstartAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestRunSandboxKataAgentSuccessful(t *testing.T) { func TestRunSandboxKataAgentSuccessful(t *testing.T) {
@ -846,7 +846,7 @@ func TestRunSandboxKataAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestRunSandboxFailing(t *testing.T) { func TestRunSandboxFailing(t *testing.T) {
@ -1392,7 +1392,7 @@ func TestStartStopContainerHyperstartAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestStartStopSandboxHyperstartAgentSuccessfulWithCNINetwork(t *testing.T) { func TestStartStopSandboxHyperstartAgentSuccessfulWithCNINetwork(t *testing.T) {
@ -1649,7 +1649,7 @@ func TestEnterContainerHyperstartAgentSuccessful(t *testing.T) {
pImpl, ok := p.(*Sandbox) pImpl, ok := p.(*Sandbox)
assert.True(t, ok) assert.True(t, ok)
bindUnmountAllRootfs(defaultSharedDir, *pImpl) bindUnmountAllRootfs(defaultSharedDir, pImpl)
} }
func TestEnterContainerFailingNoSandbox(t *testing.T) { func TestEnterContainerFailingNoSandbox(t *testing.T) {

View File

@ -13,7 +13,7 @@ type ccProxy struct {
} }
// start is the proxy start implementation for ccProxy. // start is the proxy start implementation for ccProxy.
func (p *ccProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { func (p *ccProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
config, err := newProxyConfig(sandbox.config) config, err := newProxyConfig(sandbox.config)
if err != nil { if err != nil {
return -1, "", err return -1, "", err
@ -38,6 +38,6 @@ func (p *ccProxy) start(sandbox Sandbox, params proxyParams) (int, string, error
return cmd.Process.Pid, proxyURL, nil return cmd.Process.Pid, proxyURL, nil
} }
func (p *ccProxy) stop(sandbox Sandbox, pid int) error { func (p *ccProxy) stop(sandbox *Sandbox, pid int) error {
return nil return nil
} }

View File

@ -25,7 +25,7 @@ func TestCCProxyStart(t *testing.T) {
proxy := &ccProxy{} proxy := &ccProxy{}
type testData struct { type testData struct {
sandbox Sandbox sandbox *Sandbox
expectedURI string expectedURI string
expectError bool expectError bool
} }
@ -35,16 +35,16 @@ func TestCCProxyStart(t *testing.T) {
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath) expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
data := []testData{ data := []testData{
{Sandbox{}, "", true}, {&Sandbox{}, "", true},
{ {
Sandbox{ &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ProxyType: "invalid", ProxyType: "invalid",
}, },
}, "", true, }, "", true,
}, },
{ {
Sandbox{ &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ProxyType: CCProxyType, ProxyType: CCProxyType,
// invalid - no path // invalid - no path
@ -53,7 +53,7 @@ func TestCCProxyStart(t *testing.T) {
}, "", true, }, "", true,
}, },
{ {
Sandbox{ &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ProxyType: CCProxyType, ProxyType: CCProxyType,
ProxyConfig: ProxyConfig{ ProxyConfig: ProxyConfig{
@ -63,7 +63,7 @@ func TestCCProxyStart(t *testing.T) {
}, "", true, }, "", true,
}, },
{ {
Sandbox{ &Sandbox{
id: testSandboxID, id: testSandboxID,
config: &SandboxConfig{ config: &SandboxConfig{
ProxyType: CCProxyType, ProxyType: CCProxyType,

View File

@ -14,7 +14,7 @@ type ccShim struct{}
// start is the ccShim start implementation. // start is the ccShim start implementation.
// It starts the cc-shim binary with URL and token flags provided by // It starts the cc-shim binary with URL and token flags provided by
// the proxy. // the proxy.
func (s *ccShim) start(sandbox Sandbox, params ShimParams) (int, error) { func (s *ccShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
if sandbox.config == nil { if sandbox.config == nil {
return -1, fmt.Errorf("Sandbox config cannot be nil") return -1, fmt.Errorf("Sandbox config cannot be nil")
} }

View File

@ -35,7 +35,7 @@ func getMockCCShimBinPath() string {
return DefaultMockCCShimBinPath return DefaultMockCCShimBinPath
} }
func testCCShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectFail bool) { func testCCShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFail bool) {
s := &ccShim{} s := &ccShim{}
pid, err := s.start(sandbox, params) pid, err := s.start(sandbox, params)
@ -58,11 +58,11 @@ func testCCShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectFai
} }
func TestCCShimStartNilSandboxConfigFailure(t *testing.T) { func TestCCShimStartNilSandboxConfigFailure(t *testing.T) {
testCCShimStart(t, Sandbox{}, ShimParams{}, true) testCCShimStart(t, &Sandbox{}, ShimParams{}, true)
} }
func TestCCShimStartNilShimConfigFailure(t *testing.T) { func TestCCShimStartNilShimConfigFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{}, config: &SandboxConfig{},
} }
@ -70,7 +70,7 @@ func TestCCShimStartNilShimConfigFailure(t *testing.T) {
} }
func TestCCShimStartShimPathEmptyFailure(t *testing.T) { func TestCCShimStartShimPathEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{}, ShimConfig: ShimConfig{},
@ -81,7 +81,7 @@ func TestCCShimStartShimPathEmptyFailure(t *testing.T) {
} }
func TestCCShimStartShimTypeInvalid(t *testing.T) { func TestCCShimStartShimTypeInvalid(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: "foo", ShimType: "foo",
ShimConfig: ShimConfig{}, ShimConfig: ShimConfig{},
@ -92,7 +92,7 @@ func TestCCShimStartShimTypeInvalid(t *testing.T) {
} }
func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) { func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -105,7 +105,7 @@ func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) {
} }
func TestCCShimStartParamsURLEmptyFailure(t *testing.T) { func TestCCShimStartParamsURLEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -122,7 +122,7 @@ func TestCCShimStartParamsURLEmptyFailure(t *testing.T) {
} }
func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) { func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -148,7 +148,7 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) {
cmd := filepath.Join(dir, "does-not-exist") cmd := filepath.Join(dir, "does-not-exist")
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -165,16 +165,16 @@ func TestCCShimStartParamsInvalidCommand(t *testing.T) {
testCCShimStart(t, sandbox, params, true) testCCShimStart(t, sandbox, params, true)
} }
func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Sandbox, ShimParams, error) { func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, ShimParams, error) {
saveStdout := os.Stdout saveStdout := os.Stdout
rStdout, wStdout, err := os.Pipe() rStdout, wStdout, err := os.Pipe()
if err != nil { if err != nil {
return nil, nil, nil, Sandbox{}, ShimParams{}, err return nil, nil, nil, &Sandbox{}, ShimParams{}, err
} }
os.Stdout = wStdout os.Stdout = wStdout
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -260,7 +260,7 @@ func TestCCShimStartDetachSuccessful(t *testing.T) {
} }
func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) { func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -336,7 +336,7 @@ func TestCCShimStartWithConsoleSuccessful(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: CCShimType, ShimType: CCShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{

View File

@ -59,7 +59,7 @@ func convertCNIResult(cniResult cniTypes.Result) (NetworkInfo, error) {
} }
} }
func (n *cni) invokePluginsAdd(sandbox Sandbox, networkNS *NetworkNamespace) (*NetworkInfo, error) { func (n *cni) invokePluginsAdd(sandbox *Sandbox, networkNS *NetworkNamespace) (*NetworkInfo, error) {
netPlugin, err := cniPlugin.NewNetworkPlugin() netPlugin, err := cniPlugin.NewNetworkPlugin()
if err != nil { if err != nil {
return nil, err return nil, err
@ -86,7 +86,7 @@ func (n *cni) invokePluginsAdd(sandbox Sandbox, networkNS *NetworkNamespace) (*N
return &netInfo, nil return &netInfo, nil
} }
func (n *cni) invokePluginsDelete(sandbox Sandbox, networkNS NetworkNamespace) error { func (n *cni) invokePluginsDelete(sandbox *Sandbox, networkNS NetworkNamespace) error {
netPlugin, err := cniPlugin.NewNetworkPlugin() netPlugin, err := cniPlugin.NewNetworkPlugin()
if err != nil { if err != nil {
return err return err
@ -130,7 +130,7 @@ func (n *cni) run(networkNSPath string, cb func() error) error {
} }
// add adds all needed interfaces inside the network namespace for the CNI network. // add adds all needed interfaces inside the network namespace for the CNI network.
func (n *cni) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { func (n *cni) add(sandbox *Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) {
networkNS := NetworkNamespace{ networkNS := NetworkNamespace{
NetNsPath: netNsPath, NetNsPath: netNsPath,
@ -155,7 +155,7 @@ func (n *cni) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNs
// remove unbridges and deletes TAP interfaces. It also removes virtual network // remove unbridges and deletes TAP interfaces. It also removes virtual network
// interfaces and deletes the network namespace for the CNI network. // interfaces and deletes the network namespace for the CNI network.
func (n *cni) remove(sandbox Sandbox, networkNS NetworkNamespace) error { func (n *cni) remove(sandbox *Sandbox, networkNS NetworkNamespace) error {
if err := removeNetworkCommon(networkNS); err != nil { if err := removeNetworkCommon(networkNS); err != nil {
return err return err
} }

View File

@ -28,7 +28,7 @@ func (n *cnm) run(networkNSPath string, cb func() error) error {
} }
// add adds all needed interfaces inside the network namespace for the CNM network. // add adds all needed interfaces inside the network namespace for the CNM network.
func (n *cnm) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { func (n *cnm) add(sandbox *Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) {
endpoints, err := createEndpointsFromScan(netNsPath, config) endpoints, err := createEndpointsFromScan(netNsPath, config)
if err != nil { if err != nil {
return NetworkNamespace{}, err return NetworkNamespace{}, err
@ -49,7 +49,7 @@ func (n *cnm) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNs
// remove unbridges and deletes TAP interfaces. It also removes virtual network // remove unbridges and deletes TAP interfaces. It also removes virtual network
// interfaces and deletes the network namespace for the CNM network. // interfaces and deletes the network namespace for the CNM network.
func (n *cnm) remove(sandbox Sandbox, networkNS NetworkNamespace) error { func (n *cnm) remove(sandbox *Sandbox, networkNS NetworkNamespace) error {
if err := removeNetworkCommon(networkNS); err != nil { if err := removeNetworkCommon(networkNS); err != nil {
return err return err
} }

View File

@ -598,7 +598,7 @@ func (c *Container) start() error {
return err return err
} }
if err := c.sandbox.agent.startContainer(*(c.sandbox), c); err != nil { if err := c.sandbox.agent.startContainer(c.sandbox, c); err != nil {
c.Logger().WithError(err).Error("Failed to start container") c.Logger().WithError(err).Error("Failed to start container")
if err := c.stop(); err != nil { if err := c.stop(); err != nil {
@ -652,7 +652,7 @@ func (c *Container) stop() error {
// return an error, but instead try to kill it forcefully. // return an error, but instead try to kill it forcefully.
if err := waitForShim(c.process.Pid); err != nil { if err := waitForShim(c.process.Pid); err != nil {
// Force the container to be killed. // Force the container to be killed.
if err := c.sandbox.agent.killContainer(*(c.sandbox), *c, syscall.SIGKILL, true); err != nil { if err := c.sandbox.agent.killContainer(c.sandbox, *c, syscall.SIGKILL, true); err != nil {
return err return err
} }
@ -673,9 +673,9 @@ func (c *Container) stop() error {
// this signal will ensure the container will get killed to match // this signal will ensure the container will get killed to match
// the state of the shim. This will allow the following call to // the state of the shim. This will allow the following call to
// stopContainer() to succeed in such particular case. // stopContainer() to succeed in such particular case.
c.sandbox.agent.killContainer(*(c.sandbox), *c, syscall.SIGKILL, true) c.sandbox.agent.killContainer(c.sandbox, *c, syscall.SIGKILL, true)
if err := c.sandbox.agent.stopContainer(*(c.sandbox), *c); err != nil { if err := c.sandbox.agent.stopContainer(c.sandbox, *c); err != nil {
return err return err
} }
@ -722,7 +722,7 @@ func (c *Container) kill(signal syscall.Signal, all bool) error {
return fmt.Errorf("Container not ready or running, impossible to signal the container") return fmt.Errorf("Container not ready or running, impossible to signal the container")
} }
return c.sandbox.agent.killContainer(*(c.sandbox), *c, signal, all) return c.sandbox.agent.killContainer(c.sandbox, *c, signal, all)
} }
func (c *Container) processList(options ProcessListOptions) (ProcessList, error) { func (c *Container) processList(options ProcessListOptions) (ProcessList, error) {
@ -734,7 +734,7 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, error)
return nil, fmt.Errorf("Container not running, impossible to list processes") return nil, fmt.Errorf("Container not running, impossible to list processes")
} }
return c.sandbox.agent.processListContainer(*(c.sandbox), *c, options) return c.sandbox.agent.processListContainer(c.sandbox, *c, options)
} }
func (c *Container) hotplugDrive() error { func (c *Container) hotplugDrive() error {

View File

@ -95,7 +95,7 @@ var runStoragePath = filepath.Join("/run", storagePathSuffix)
// The default resource storage implementation is filesystem. // The default resource storage implementation is filesystem.
type resourceStorage interface { type resourceStorage interface {
// Create all resources for a sandbox // Create all resources for a sandbox
createAllResources(sandbox Sandbox) error createAllResources(sandbox *Sandbox) error
// Resources URIs functions return both the URI // Resources URIs functions return both the URI
// for the actual resource and the URI base. // for the actual resource and the URI base.
@ -140,7 +140,7 @@ func (fs *filesystem) Logger() *logrus.Entry {
return virtLog.WithField("subsystem", "filesystem") return virtLog.WithField("subsystem", "filesystem")
} }
func (fs *filesystem) createAllResources(sandbox Sandbox) (err error) { func (fs *filesystem) createAllResources(sandbox *Sandbox) (err error) {
for _, resource := range []sandboxResource{stateFileType, configFileType} { for _, resource := range []sandboxResource{stateFileType, configFileType} {
_, path, _ := fs.sandboxURI(sandbox.id, resource) _, path, _ := fs.sandboxURI(sandbox.id, resource)
err = os.MkdirAll(path, dirMode) err = os.MkdirAll(path, dirMode)

View File

@ -27,7 +27,7 @@ func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) {
Containers: contConfigs, Containers: contConfigs,
} }
sandbox := Sandbox{ sandbox := &Sandbox{
id: testSandboxID, id: testSandboxID,
storage: fs, storage: fs,
config: sandboxConfig, config: sandboxConfig,
@ -96,7 +96,7 @@ func TestFilesystemCreateAllResourcesSuccessful(t *testing.T) {
func TestFilesystemCreateAllResourcesFailingSandboxIDEmpty(t *testing.T) { func TestFilesystemCreateAllResourcesFailingSandboxIDEmpty(t *testing.T) {
fs := &filesystem{} fs := &filesystem{}
sandbox := Sandbox{} sandbox := &Sandbox{}
err := fs.createAllResources(sandbox) err := fs.createAllResources(sandbox)
if err == nil { if err == nil {
@ -111,7 +111,7 @@ func TestFilesystemCreateAllResourcesFailingContainerIDEmpty(t *testing.T) {
{id: ""}, {id: ""},
} }
sandbox := Sandbox{ sandbox := &Sandbox{
id: testSandboxID, id: testSandboxID,
containers: containers, containers: containers,
} }

View File

@ -36,7 +36,7 @@ type HyperConfig struct {
SockTtyName string SockTtyName string
} }
func (h *hyper) generateSockets(sandbox Sandbox, c HyperConfig) { func (h *hyper) generateSockets(sandbox *Sandbox, c HyperConfig) {
sandboxSocketPaths := []string{ sandboxSocketPaths := []string{
fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, sandbox.id), fmt.Sprintf(defaultSockPathTemplates[0], runStoragePath, sandbox.id),
fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, sandbox.id), fmt.Sprintf(defaultSockPathTemplates[1], runStoragePath, sandbox.id),
@ -70,7 +70,7 @@ type HyperAgentState struct {
// hyper is the Agent interface implementation for hyperstart. // hyper is the Agent interface implementation for hyperstart.
type hyper struct { type hyper struct {
sandbox Sandbox sandbox *Sandbox
shim shim shim shim
proxy proxy proxy proxy
client *proxyClient.Client client *proxyClient.Client
@ -162,7 +162,7 @@ func (h *hyper) processHyperRoute(route netlink.Route, deviceName string) *hyper
} }
} }
func (h *hyper) buildNetworkInterfacesAndRoutes(sandbox Sandbox) ([]hyperstart.NetworkIface, []hyperstart.Route, error) { func (h *hyper) buildNetworkInterfacesAndRoutes(sandbox *Sandbox) ([]hyperstart.NetworkIface, []hyperstart.Route, error) {
if sandbox.networkNS.NetNsPath == "" { if sandbox.networkNS.NetNsPath == "" {
return []hyperstart.NetworkIface{}, []hyperstart.Route{}, nil return []hyperstart.NetworkIface{}, []hyperstart.Route{}, nil
} }
@ -233,9 +233,9 @@ func (h *hyper) init(sandbox *Sandbox, config interface{}) (err error) {
case HyperConfig: case HyperConfig:
// Create agent sockets from paths provided through // Create agent sockets from paths provided through
// configuration, or generate them from scratch. // configuration, or generate them from scratch.
h.generateSockets(*sandbox, c) h.generateSockets(sandbox, c)
h.sandbox = *sandbox h.sandbox = sandbox
default: default:
return fmt.Errorf("Invalid config type") return fmt.Errorf("Invalid config type")
} }
@ -337,7 +337,7 @@ func (h *hyper) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, error) {
} }
// startSandbox is the agent Sandbox starting implementation for hyperstart. // startSandbox is the agent Sandbox starting implementation for hyperstart.
func (h *hyper) startSandbox(sandbox Sandbox) error { func (h *hyper) startSandbox(sandbox *Sandbox) error {
// Start the proxy here // Start the proxy here
pid, uri, err := h.proxy.start(sandbox, proxyParams{}) pid, uri, err := h.proxy.start(sandbox, proxyParams{})
if err != nil { if err != nil {
@ -385,7 +385,7 @@ func (h *hyper) startSandbox(sandbox Sandbox) error {
} }
// stopSandbox is the agent Sandbox stopping implementation for hyperstart. // stopSandbox is the agent Sandbox stopping implementation for hyperstart.
func (h *hyper) stopSandbox(sandbox Sandbox) error { func (h *hyper) stopSandbox(sandbox *Sandbox) error {
proxyCmd := hyperstartProxyCmd{ proxyCmd := hyperstartProxyCmd{
cmd: hyperstart.DestroySandbox, cmd: hyperstart.DestroySandbox,
message: nil, message: nil,
@ -413,7 +413,7 @@ func (h *hyper) handleBlockVolumes(c *Container) {
} }
} }
func (h *hyper) startOneContainer(sandbox Sandbox, c *Container) error { func (h *hyper) startOneContainer(sandbox *Sandbox, c *Container) error {
process, err := h.buildHyperContainerProcess(c.config.Cmd) process, err := h.buildHyperContainerProcess(c.config.Cmd)
if err != nil { if err != nil {
return err return err
@ -530,12 +530,12 @@ func (h *hyper) createContainer(sandbox *Sandbox, c *Container) (*Process, error
} }
// startContainer is the agent Container starting implementation for hyperstart. // startContainer is the agent Container starting implementation for hyperstart.
func (h *hyper) startContainer(sandbox Sandbox, c *Container) error { func (h *hyper) startContainer(sandbox *Sandbox, c *Container) error {
return h.startOneContainer(sandbox, c) return h.startOneContainer(sandbox, c)
} }
// stopContainer is the agent Container stopping implementation for hyperstart. // stopContainer is the agent Container stopping implementation for hyperstart.
func (h *hyper) stopContainer(sandbox Sandbox, c Container) error { func (h *hyper) stopContainer(sandbox *Sandbox, c Container) error {
// Nothing to be done in case the container has not been started. // Nothing to be done in case the container has not been started.
if c.state.State == StateReady { if c.state.State == StateReady {
return nil return nil
@ -572,7 +572,7 @@ func (h *hyper) stopOneContainer(sandboxID string, c Container) error {
} }
// killContainer is the agent process signal implementation for hyperstart. // killContainer is the agent process signal implementation for hyperstart.
func (h *hyper) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { func (h *hyper) killContainer(sandbox *Sandbox, c Container, signal syscall.Signal, all bool) error {
// Send the signal to the shim directly in case the container has not // Send the signal to the shim directly in case the container has not
// been started yet. // been started yet.
if c.state.State == StateReady { if c.state.State == StateReady {
@ -601,7 +601,7 @@ func (h *hyper) killOneContainer(cID string, signal syscall.Signal, all bool) er
return nil return nil
} }
func (h *hyper) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { func (h *hyper) processListContainer(sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error) {
return h.processListOneContainer(sandbox.id, c.id, options) return h.processListOneContainer(sandbox.id, c.id, options)
} }

View File

@ -26,7 +26,7 @@ func TestHyperstartGenerateSocketsSuccessful(t *testing.T) {
SockTtyName: "ttySock", SockTtyName: "ttySock",
} }
sandbox := Sandbox{ sandbox := &Sandbox{
id: testSandboxID, id: testSandboxID,
} }
@ -57,7 +57,7 @@ func TestHyperstartGenerateSocketsSuccessful(t *testing.T) {
func TestHyperstartGenerateSocketsSuccessfulNoPathProvided(t *testing.T) { func TestHyperstartGenerateSocketsSuccessfulNoPathProvided(t *testing.T) {
config := HyperConfig{} config := HyperConfig{}
sandbox := Sandbox{ sandbox := &Sandbox{
id: testSandboxID, id: testSandboxID,
} }

View File

@ -105,7 +105,7 @@ func parseVSOCKAddr(sock string) (uint32, uint32, error) {
return uint32(cid), uint32(port), nil return uint32(cid), uint32(port), nil
} }
func (k *kataAgent) generateVMSocket(sandbox Sandbox, c KataAgentConfig) error { func (k *kataAgent) generateVMSocket(sandbox *Sandbox, c KataAgentConfig) error {
cid, port, err := parseVSOCKAddr(c.GRPCSocket) cid, port, err := parseVSOCKAddr(c.GRPCSocket)
if err != nil { if err != nil {
// We need to generate a host UNIX socket path for the emulated serial port. // We need to generate a host UNIX socket path for the emulated serial port.
@ -129,7 +129,7 @@ func (k *kataAgent) generateVMSocket(sandbox Sandbox, c KataAgentConfig) error {
func (k *kataAgent) init(sandbox *Sandbox, config interface{}) (err error) { func (k *kataAgent) init(sandbox *Sandbox, config interface{}) (err error) {
switch c := config.(type) { switch c := config.(type) {
case KataAgentConfig: case KataAgentConfig:
if err := k.generateVMSocket(*sandbox, c); err != nil { if err := k.generateVMSocket(sandbox, c); err != nil {
return err return err
} }
k.keepConn = c.LongLiveConn k.keepConn = c.LongLiveConn
@ -401,7 +401,7 @@ func (k *kataAgent) generateInterfacesAndRoutes(networkNS NetworkNamespace) ([]*
return ifaces, routes, nil return ifaces, routes, nil
} }
func (k *kataAgent) startSandbox(sandbox Sandbox) error { func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
if k.proxy == nil { if k.proxy == nil {
return errorMissingProxy return errorMissingProxy
} }
@ -505,7 +505,7 @@ func (k *kataAgent) startSandbox(sandbox Sandbox) error {
return err return err
} }
func (k *kataAgent) stopSandbox(sandbox Sandbox) error { func (k *kataAgent) stopSandbox(sandbox *Sandbox) error {
if k.proxy == nil { if k.proxy == nil {
return errorMissingProxy return errorMissingProxy
} }
@ -840,7 +840,7 @@ func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage {
return volumeStorages return volumeStorages
} }
func (k *kataAgent) startContainer(sandbox Sandbox, c *Container) error { func (k *kataAgent) startContainer(sandbox *Sandbox, c *Container) error {
req := &grpc.StartContainerRequest{ req := &grpc.StartContainerRequest{
ContainerId: c.id, ContainerId: c.id,
} }
@ -849,7 +849,7 @@ func (k *kataAgent) startContainer(sandbox Sandbox, c *Container) error {
return err return err
} }
func (k *kataAgent) stopContainer(sandbox Sandbox, c Container) error { func (k *kataAgent) stopContainer(sandbox *Sandbox, c Container) error {
req := &grpc.RemoveContainerRequest{ req := &grpc.RemoveContainerRequest{
ContainerId: c.id, ContainerId: c.id,
} }
@ -865,7 +865,7 @@ func (k *kataAgent) stopContainer(sandbox Sandbox, c Container) error {
return bindUnmountContainerRootfs(kataHostSharedDir, sandbox.id, c.id) return bindUnmountContainerRootfs(kataHostSharedDir, sandbox.id, c.id)
} }
func (k *kataAgent) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { func (k *kataAgent) killContainer(sandbox *Sandbox, c Container, signal syscall.Signal, all bool) error {
req := &grpc.SignalProcessRequest{ req := &grpc.SignalProcessRequest{
ContainerId: c.id, ContainerId: c.id,
ExecId: c.process.Token, ExecId: c.process.Token,
@ -876,7 +876,7 @@ func (k *kataAgent) killContainer(sandbox Sandbox, c Container, signal syscall.S
return err return err
} }
func (k *kataAgent) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { func (k *kataAgent) processListContainer(sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error) {
req := &grpc.ListProcessesRequest{ req := &grpc.ListProcessesRequest{
ContainerId: c.id, ContainerId: c.id,
Format: options.Format, Format: options.Format,

View File

@ -24,7 +24,7 @@ type kataBuiltInProxy struct {
// start is the proxy start implementation for kata builtin proxy. // start is the proxy start implementation for kata builtin proxy.
// It starts the console watcher for the guest. // It starts the console watcher for the guest.
// It returns agentURL to let agent connect directly. // It returns agentURL to let agent connect directly.
func (p *kataBuiltInProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { func (p *kataBuiltInProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
if p.conn != nil { if p.conn != nil {
return -1, "", fmt.Errorf("kata builtin proxy running for sandbox %s", p.sandboxID) return -1, "", fmt.Errorf("kata builtin proxy running for sandbox %s", p.sandboxID)
} }
@ -40,7 +40,7 @@ func (p *kataBuiltInProxy) start(sandbox Sandbox, params proxyParams) (int, stri
} }
// stop is the proxy stop implementation for kata builtin proxy. // stop is the proxy stop implementation for kata builtin proxy.
func (p *kataBuiltInProxy) stop(sandbox Sandbox, pid int) error { func (p *kataBuiltInProxy) stop(sandbox *Sandbox, pid int) error {
if p.conn != nil { if p.conn != nil {
p.conn.Close() p.conn.Close()
p.conn = nil p.conn = nil

View File

@ -10,6 +10,6 @@ type kataBuiltInShim struct{}
// start is the kataBuiltInShim start implementation for kata builtin shim. // start is the kataBuiltInShim start implementation for kata builtin shim.
// It does nothing. The shim functionality is provided by the virtcontainers // It does nothing. The shim functionality is provided by the virtcontainers
// library. // library.
func (s *kataBuiltInShim) start(sandbox Sandbox, params ShimParams) (int, error) { func (s *kataBuiltInShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
return -1, nil return -1, nil
} }

View File

@ -18,7 +18,7 @@ type kataProxy struct {
} }
// start is kataProxy start implementation for proxy interface. // start is kataProxy start implementation for proxy interface.
func (p *kataProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { func (p *kataProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
if sandbox.agent == nil { if sandbox.agent == nil {
return -1, "", fmt.Errorf("No agent") return -1, "", fmt.Errorf("No agent")
} }
@ -53,7 +53,7 @@ func (p *kataProxy) start(sandbox Sandbox, params proxyParams) (int, string, err
} }
// stop is kataProxy stop implementation for proxy interface. // stop is kataProxy stop implementation for proxy interface.
func (p *kataProxy) stop(sandbox Sandbox, pid int) error { func (p *kataProxy) stop(sandbox *Sandbox, pid int) error {
// Signal the proxy with SIGTERM. // Signal the proxy with SIGTERM.
return syscall.Kill(pid, syscall.SIGTERM) return syscall.Kill(pid, syscall.SIGTERM)
} }

View File

@ -21,7 +21,7 @@ type KataShimConfig struct {
// start is the ccShim start implementation. // start is the ccShim start implementation.
// It starts the cc-shim binary with URL and token flags provided by // It starts the cc-shim binary with URL and token flags provided by
// the proxy. // the proxy.
func (s *kataShim) start(sandbox Sandbox, params ShimParams) (int, error) { func (s *kataShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
if sandbox.config == nil { if sandbox.config == nil {
return -1, fmt.Errorf("Sandbox config cannot be nil") return -1, fmt.Errorf("Sandbox config cannot be nil")
} }

View File

@ -29,7 +29,7 @@ func getMockKataShimBinPath() string {
return DefaultMockKataShimBinPath return DefaultMockKataShimBinPath
} }
func testKataShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectFail bool) { func testKataShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFail bool) {
s := &kataShim{} s := &kataShim{}
pid, err := s.start(sandbox, params) pid, err := s.start(sandbox, params)
@ -52,11 +52,11 @@ func testKataShimStart(t *testing.T, sandbox Sandbox, params ShimParams, expectF
} }
func TestKataShimStartNilSandboxConfigFailure(t *testing.T) { func TestKataShimStartNilSandboxConfigFailure(t *testing.T) {
testKataShimStart(t, Sandbox{}, ShimParams{}, true) testKataShimStart(t, &Sandbox{}, ShimParams{}, true)
} }
func TestKataShimStartNilShimConfigFailure(t *testing.T) { func TestKataShimStartNilShimConfigFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{}, config: &SandboxConfig{},
} }
@ -64,7 +64,7 @@ func TestKataShimStartNilShimConfigFailure(t *testing.T) {
} }
func TestKataShimStartShimPathEmptyFailure(t *testing.T) { func TestKataShimStartShimPathEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{}, ShimConfig: ShimConfig{},
@ -75,7 +75,7 @@ func TestKataShimStartShimPathEmptyFailure(t *testing.T) {
} }
func TestKataShimStartShimTypeInvalid(t *testing.T) { func TestKataShimStartShimTypeInvalid(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: "foo", ShimType: "foo",
ShimConfig: ShimConfig{}, ShimConfig: ShimConfig{},
@ -86,7 +86,7 @@ func TestKataShimStartShimTypeInvalid(t *testing.T) {
} }
func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) { func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -99,7 +99,7 @@ func TestKataShimStartParamsTokenEmptyFailure(t *testing.T) {
} }
func TestKataShimStartParamsURLEmptyFailure(t *testing.T) { func TestKataShimStartParamsURLEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -116,7 +116,7 @@ func TestKataShimStartParamsURLEmptyFailure(t *testing.T) {
} }
func TestKataShimStartParamsContainerEmptyFailure(t *testing.T) { func TestKataShimStartParamsContainerEmptyFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -142,7 +142,7 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) {
cmd := filepath.Join(dir, "does-not-exist") cmd := filepath.Join(dir, "does-not-exist")
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -159,16 +159,16 @@ func TestKataShimStartParamsInvalidCommand(t *testing.T) {
testKataShimStart(t, sandbox, params, true) testKataShimStart(t, sandbox, params, true)
} }
func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, Sandbox, ShimParams, error) { func startKataShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, ShimParams, error) {
saveStdout := os.Stdout saveStdout := os.Stdout
rStdout, wStdout, err := os.Pipe() rStdout, wStdout, err := os.Pipe()
if err != nil { if err != nil {
return nil, nil, nil, Sandbox{}, ShimParams{}, err return nil, nil, nil, &Sandbox{}, ShimParams{}, err
} }
os.Stdout = wStdout os.Stdout = wStdout
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -254,7 +254,7 @@ func TestKataShimStartDetachSuccessful(t *testing.T) {
} }
func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) { func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{
@ -282,7 +282,7 @@ func TestKataShimStartWithConsoleSuccessful(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
sandbox := Sandbox{ sandbox := &Sandbox{
config: &SandboxConfig{ config: &SandboxConfig{
ShimType: KataShimType, ShimType: KataShimType,
ShimConfig: ShimConfig{ ShimConfig: ShimConfig{

View File

@ -324,7 +324,7 @@ func bindUnmountContainerRootfs(sharedDir, sandboxID, cID string) error {
return nil return nil
} }
func bindUnmountAllRootfs(sharedDir string, sandbox Sandbox) { func bindUnmountAllRootfs(sharedDir string, sandbox *Sandbox) {
for _, c := range sandbox.containers { for _, c := range sandbox.containers {
c.unmountHostMounts() c.unmountHostMounts()
if c.state.Fstype == "" { if c.state.Fstype == "" {

View File

@ -589,7 +589,7 @@ func runNetworkCommon(networkNSPath string, cb func() error) error {
}) })
} }
func addNetworkCommon(sandbox Sandbox, networkNS *NetworkNamespace) error { func addNetworkCommon(sandbox *Sandbox, networkNS *NetworkNamespace) error {
err := doNetNS(networkNS.NetNsPath, func(_ ns.NetNS) error { err := doNetNS(networkNS.NetNsPath, func(_ ns.NetNS) error {
for _, endpoint := range networkNS.Endpoints { for _, endpoint := range networkNS.Endpoints {
if err := endpoint.Attach(sandbox.hypervisor); err != nil { if err := endpoint.Attach(sandbox.hypervisor); err != nil {
@ -1365,9 +1365,9 @@ type network interface {
run(networkNSPath string, cb func() error) error run(networkNSPath string, cb func() error) error
// add adds all needed interfaces inside the network namespace. // add adds all needed interfaces inside the network namespace.
add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) add(sandbox *Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error)
// remove unbridges and deletes TAP interfaces. It also removes virtual network // remove unbridges and deletes TAP interfaces. It also removes virtual network
// interfaces and deletes the network namespace. // interfaces and deletes the network namespace.
remove(sandbox Sandbox, networkNS NetworkNamespace) error remove(sandbox *Sandbox, networkNS NetworkNamespace) error
} }

View File

@ -23,7 +23,7 @@ type noProxy struct {
} }
// start is noProxy start implementation for proxy interface. // start is noProxy start implementation for proxy interface.
func (p *noProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { func (p *noProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
if params.agentURL == "" { if params.agentURL == "" {
return -1, "", fmt.Errorf("AgentURL cannot be empty") return -1, "", fmt.Errorf("AgentURL cannot be empty")
} }
@ -32,6 +32,6 @@ func (p *noProxy) start(sandbox Sandbox, params proxyParams) (int, string, error
} }
// stop is noProxy stop implementation for proxy interface. // stop is noProxy stop implementation for proxy interface.
func (p *noProxy) stop(sandbox Sandbox, pid int) error { func (p *noProxy) stop(sandbox *Sandbox, pid int) error {
return nil return nil
} }

View File

@ -10,7 +10,7 @@ import (
) )
func TestNoProxyStart(t *testing.T) { func TestNoProxyStart(t *testing.T) {
sandbox := Sandbox{ sandbox := &Sandbox{
agent: newAgent(NoopAgentType), agent: newAgent(NoopAgentType),
} }
@ -34,7 +34,7 @@ func TestNoProxyStart(t *testing.T) {
func TestNoProxyStop(t *testing.T) { func TestNoProxyStop(t *testing.T) {
p := &noProxy{} p := &noProxy{}
if err := p.stop(Sandbox{}, 0); err != nil { if err := p.stop(&Sandbox{}, 0); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }

View File

@ -40,12 +40,12 @@ func (n *noopAgent) exec(sandbox *Sandbox, c Container, cmd Cmd) (*Process, erro
} }
// startSandbox is the Noop agent Sandbox starting implementation. It does nothing. // startSandbox is the Noop agent Sandbox starting implementation. It does nothing.
func (n *noopAgent) startSandbox(sandbox Sandbox) error { func (n *noopAgent) startSandbox(sandbox *Sandbox) error {
return nil return nil
} }
// stopSandbox is the Noop agent Sandbox stopping implementation. It does nothing. // stopSandbox is the Noop agent Sandbox stopping implementation. It does nothing.
func (n *noopAgent) stopSandbox(sandbox Sandbox) error { func (n *noopAgent) stopSandbox(sandbox *Sandbox) error {
return nil return nil
} }
@ -55,22 +55,22 @@ func (n *noopAgent) createContainer(sandbox *Sandbox, c *Container) (*Process, e
} }
// startContainer is the Noop agent Container starting implementation. It does nothing. // startContainer is the Noop agent Container starting implementation. It does nothing.
func (n *noopAgent) startContainer(sandbox Sandbox, c *Container) error { func (n *noopAgent) startContainer(sandbox *Sandbox, c *Container) error {
return nil return nil
} }
// stopContainer is the Noop agent Container stopping implementation. It does nothing. // stopContainer is the Noop agent Container stopping implementation. It does nothing.
func (n *noopAgent) stopContainer(sandbox Sandbox, c Container) error { func (n *noopAgent) stopContainer(sandbox *Sandbox, c Container) error {
return nil return nil
} }
// killContainer is the Noop agent Container signaling implementation. It does nothing. // killContainer is the Noop agent Container signaling implementation. It does nothing.
func (n *noopAgent) killContainer(sandbox Sandbox, c Container, signal syscall.Signal, all bool) error { func (n *noopAgent) killContainer(sandbox *Sandbox, c Container, signal syscall.Signal, all bool) error {
return nil return nil
} }
// processListContainer is the Noop agent Container ps implementation. It does nothing. // processListContainer is the Noop agent Container ps implementation. It does nothing.
func (n *noopAgent) processListContainer(sandbox Sandbox, c Container, options ProcessListOptions) (ProcessList, error) { func (n *noopAgent) processListContainer(sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error) {
return nil, nil return nil, nil
} }

View File

@ -55,7 +55,7 @@ func TestNoopAgentExec(t *testing.T) {
func TestNoopAgentStartSandbox(t *testing.T) { func TestNoopAgentStartSandbox(t *testing.T) {
n := &noopAgent{} n := &noopAgent{}
sandbox := Sandbox{} sandbox := &Sandbox{}
err := n.startSandbox(sandbox) err := n.startSandbox(sandbox)
if err != nil { if err != nil {
@ -65,7 +65,7 @@ func TestNoopAgentStartSandbox(t *testing.T) {
func TestNoopAgentStopSandbox(t *testing.T) { func TestNoopAgentStopSandbox(t *testing.T) {
n := &noopAgent{} n := &noopAgent{}
sandbox := Sandbox{} sandbox := &Sandbox{}
err := n.stopSandbox(sandbox) err := n.stopSandbox(sandbox)
if err != nil { if err != nil {
@ -81,7 +81,7 @@ func TestNoopAgentCreateContainer(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
if err := n.startSandbox(*sandbox); err != nil { if err := n.startSandbox(sandbox); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -98,7 +98,7 @@ func TestNoopAgentStartContainer(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
err = n.startContainer(*sandbox, container) err = n.startContainer(sandbox, container)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -112,7 +112,7 @@ func TestNoopAgentStopContainer(t *testing.T) {
} }
defer cleanUp() defer cleanUp()
err = n.stopContainer(*sandbox, *container) err = n.stopContainer(sandbox, *container)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -25,13 +25,13 @@ func (n *noopNetwork) run(networkNSPath string, cb func() error) error {
// add adds all needed interfaces inside the network namespace the Noop network. // add adds all needed interfaces inside the network namespace the Noop network.
// It does nothing. // It does nothing.
func (n *noopNetwork) add(sandbox Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) { func (n *noopNetwork) add(sandbox *Sandbox, config NetworkConfig, netNsPath string, netNsCreated bool) (NetworkNamespace, error) {
return NetworkNamespace{}, nil return NetworkNamespace{}, nil
} }
// remove unbridges and deletes TAP interfaces. It also removes virtual network // remove unbridges and deletes TAP interfaces. It also removes virtual network
// interfaces and deletes the network namespace for the Noop network. // interfaces and deletes the network namespace for the Noop network.
// It does nothing. // It does nothing.
func (n *noopNetwork) remove(sandbox Sandbox, networkNS NetworkNamespace) error { func (n *noopNetwork) remove(sandbox *Sandbox, networkNS NetworkNamespace) error {
return nil return nil
} }

View File

@ -13,12 +13,12 @@ var noopProxyURL = "noopProxyURL"
// register is the proxy start implementation for testing purpose. // register is the proxy start implementation for testing purpose.
// It does nothing. // It does nothing.
func (p *noopProxy) start(sandbox Sandbox, params proxyParams) (int, string, error) { func (p *noopProxy) start(sandbox *Sandbox, params proxyParams) (int, string, error) {
return 0, noopProxyURL, nil return 0, noopProxyURL, nil
} }
// stop is the proxy stop implementation for testing purpose. // stop is the proxy stop implementation for testing purpose.
// It does nothing. // It does nothing.
func (p *noopProxy) stop(sandbox Sandbox, pid int) error { func (p *noopProxy) stop(sandbox *Sandbox, pid int) error {
return nil return nil
} }

View File

@ -9,6 +9,6 @@ type noopShim struct{}
// start is the noopShim start implementation for testing purpose. // start is the noopShim start implementation for testing purpose.
// It does nothing. // It does nothing.
func (s *noopShim) start(sandbox Sandbox, params ShimParams) (int, error) { func (s *noopShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
return 0, nil return 0, nil
} }

View File

@ -11,7 +11,7 @@ import (
func TestNoopShimStart(t *testing.T) { func TestNoopShimStart(t *testing.T) {
s := &noopShim{} s := &noopShim{}
sandbox := Sandbox{} sandbox := &Sandbox{}
params := ShimParams{} params := ShimParams{}
expected := 0 expected := 0

View File

@ -144,7 +144,7 @@ func newProxyConfig(sandboxConfig *SandboxConfig) (ProxyConfig, error) {
return config, nil return config, nil
} }
func defaultProxyURL(sandbox Sandbox, socketType string) (string, error) { func defaultProxyURL(sandbox *Sandbox, socketType string) (string, error) {
switch socketType { switch socketType {
case SocketTypeUNIX: case SocketTypeUNIX:
socketPath := filepath.Join(runStoragePath, sandbox.id, "proxy.sock") socketPath := filepath.Join(runStoragePath, sandbox.id, "proxy.sock")
@ -165,9 +165,9 @@ func isProxyBuiltIn(pType ProxyType) bool {
type proxy interface { type proxy interface {
// start launches a proxy instance for the specified sandbox, returning // start launches a proxy instance for the specified sandbox, returning
// the PID of the process and the URL used to connect to it. // the PID of the process and the URL used to connect to it.
start(sandbox Sandbox, params proxyParams) (int, string, error) start(sandbox *Sandbox, params proxyParams) (int, string, error)
// stop terminates a proxy instance after all communications with the // stop terminates a proxy instance after all communications with the
// agent inside the VM have been properly stopped. // agent inside the VM have been properly stopped.
stop(sandbox Sandbox, pid int) error stop(sandbox *Sandbox, pid int) error
} }

View File

@ -213,7 +213,7 @@ func testDefaultProxyURL(expectedURL string, socketType string, sandboxID string
id: sandboxID, id: sandboxID,
} }
url, err := defaultProxyURL(*sandbox, socketType) url, err := defaultProxyURL(sandbox, socketType)
if err != nil { if err != nil {
return err return err
} }

View File

@ -674,7 +674,7 @@ func newSandbox(sandboxConfig SandboxConfig) (*Sandbox, error) {
} }
}() }()
if err = s.storage.createAllResources(*s); err != nil { if err = s.storage.createAllResources(s); err != nil {
return nil, err return nil, err
} }
@ -826,7 +826,7 @@ func (s *Sandbox) createNetwork() error {
} }
// Add the network // Add the network
networkNS, err := s.network.add(*s, s.config.NetworkConfig, netNsPath, netNsCreated) networkNS, err := s.network.add(s, s.config.NetworkConfig, netNsPath, netNsCreated)
if err != nil { if err != nil {
return err return err
} }
@ -838,7 +838,7 @@ func (s *Sandbox) createNetwork() error {
func (s *Sandbox) removeNetwork() error { func (s *Sandbox) removeNetwork() error {
if s.networkNS.NetNsCreated { if s.networkNS.NetNsCreated {
return s.network.remove(*s, s.networkNS) return s.network.remove(s, s.networkNS)
} }
return nil return nil
@ -863,7 +863,7 @@ func (s *Sandbox) startVM() error {
// Once startVM is done, we want to guarantee // Once startVM is done, we want to guarantee
// that the sandbox is manageable. For that we need // that the sandbox is manageable. For that we need
// to start the sandbox inside the VM. // to start the sandbox inside the VM.
return s.agent.startSandbox(*s) return s.agent.startSandbox(s)
} }
func (s *Sandbox) addContainer(c *Container) error { func (s *Sandbox) addContainer(c *Container) error {
@ -1065,7 +1065,7 @@ func (s *Sandbox) stop() error {
} }
} }
if err := s.agent.stopSandbox(*s); err != nil { if err := s.agent.stopSandbox(s); err != nil {
return err return err
} }

View File

@ -51,7 +51,7 @@ func testCreateSandbox(t *testing.T, id string,
return nil, fmt.Errorf("Could not create sandbox: %s", err) return nil, fmt.Errorf("Could not create sandbox: %s", err)
} }
if err := sandbox.agent.startSandbox(*sandbox); err != nil { if err := sandbox.agent.startSandbox(sandbox); err != nil {
return nil, err return nil, err
} }

View File

@ -172,7 +172,7 @@ func prepareAndStartShim(sandbox *Sandbox, shim shim, cid, token, url string, cm
EnterNS: enterNSList, EnterNS: enterNSList,
} }
pid, err := shim.start(*sandbox, shimParams) pid, err := shim.start(sandbox, shimParams)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -282,5 +282,5 @@ func waitForShim(pid int) error {
type shim interface { type shim interface {
// start starts the shim relying on its configuration and on // start starts the shim relying on its configuration and on
// parameters provided. // parameters provided.
start(sandbox Sandbox, params ShimParams) (int, error) start(sandbox *Sandbox, params ShimParams) (int, error)
} }