diff --git a/src/runtime/pkg/containerd-shim-v2/create_test.go b/src/runtime/pkg/containerd-shim-v2/create_test.go index 121d5ea4db..75638b5186 100644 --- a/src/runtime/pkg/containerd-shim-v2/create_test.go +++ b/src/runtime/pkg/containerd-shim-v2/create_test.go @@ -41,7 +41,7 @@ func TestCreateSandboxSuccess(t *testing.T) { }, } - testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) { return sandbox, nil } diff --git a/src/runtime/pkg/katautils/create_test.go b/src/runtime/pkg/katautils/create_test.go index b1e4cf2a90..2608003784 100644 --- a/src/runtime/pkg/katautils/create_test.go +++ b/src/runtime/pkg/katautils/create_test.go @@ -274,7 +274,7 @@ func TestCreateSandboxAnnotations(t *testing.T) { rootFs := vc.RootFs{Mounted: true} - testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) { return &vcmock.Sandbox{ MockID: testSandboxID, MockContainers: []*vcmock.Container{ diff --git a/src/runtime/virtcontainers/api_test.go b/src/runtime/virtcontainers/api_test.go index 0268ab1259..0af9aec5d6 100644 --- a/src/runtime/virtcontainers/api_test.go +++ b/src/runtime/virtcontainers/api_test.go @@ -145,7 +145,7 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) { config := newTestSandboxConfigNoop() ctx := WithNewAgentFunc(context.Background(), newMockAgent) - p, err := CreateSandbox(ctx, config, nil) + p, err := CreateSandbox(ctx, config, nil, nil) assert.NoError(err) assert.NotNil(p) @@ -178,7 +178,7 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) { defer hybridVSockTTRPCMock.Stop() ctx := WithNewAgentFunc(context.Background(), newMockAgent) - p, err := CreateSandbox(ctx, config, nil) + p, err := CreateSandbox(ctx, config, nil, nil) assert.NoError(err) assert.NotNil(p) @@ -199,7 +199,7 @@ func TestCreateSandboxFailing(t *testing.T) { config := SandboxConfig{} ctx := WithNewAgentFunc(context.Background(), newMockAgent) - p, err := CreateSandbox(ctx, config, nil) + p, err := CreateSandbox(ctx, config, nil, nil) assert.Error(err) assert.Nil(p.(*Sandbox)) } @@ -227,7 +227,7 @@ func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox V err error) { // Create sandbox - sandbox, err = CreateSandbox(ctx, config, nil) + sandbox, err = CreateSandbox(ctx, config, nil, nil) if sandbox == nil || err != nil { return nil, "", err } @@ -260,7 +260,7 @@ func TestReleaseSandbox(t *testing.T) { config := newTestSandboxConfigNoop() ctx := WithNewAgentFunc(context.Background(), newMockAgent) - s, err := CreateSandbox(ctx, config, nil) + s, err := CreateSandbox(ctx, config, nil, nil) assert.NoError(t, err) assert.NotNil(t, s) diff --git a/src/runtime/virtcontainers/example_pod_run_test.go b/src/runtime/virtcontainers/example_pod_run_test.go index cc12ddaed7..79706b0a2e 100644 --- a/src/runtime/virtcontainers/example_pod_run_test.go +++ b/src/runtime/virtcontainers/example_pod_run_test.go @@ -64,7 +64,7 @@ func Example_createAndStartSandbox() { } // Create the sandbox - s, err := vc.CreateSandbox(context.Background(), sandboxConfig, nil) + s, err := vc.CreateSandbox(context.Background(), sandboxConfig, nil, nil) if err != nil { fmt.Printf("Could not create sandbox: %s", err) return diff --git a/src/runtime/virtcontainers/pkg/vcmock/mock.go b/src/runtime/virtcontainers/pkg/vcmock/mock.go index 3b18151669..39305e244e 100644 --- a/src/runtime/virtcontainers/pkg/vcmock/mock.go +++ b/src/runtime/virtcontainers/pkg/vcmock/mock.go @@ -42,9 +42,9 @@ func (m *VCMock) SetFactory(ctx context.Context, factory vc.Factory) { } // CreateSandbox implements the VC function of the same name. -func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { +func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) { if m.CreateSandboxFunc != nil { - return m.CreateSandboxFunc(ctx, sandboxConfig) + return m.CreateSandboxFunc(ctx, sandboxConfig, hookFunc) } return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig) diff --git a/src/runtime/virtcontainers/pkg/vcmock/mock_test.go b/src/runtime/virtcontainers/pkg/vcmock/mock_test.go index 9043b168da..7558b8d1b0 100644 --- a/src/runtime/virtcontainers/pkg/vcmock/mock_test.go +++ b/src/runtime/virtcontainers/pkg/vcmock/mock_test.go @@ -120,22 +120,22 @@ func TestVCMockCreateSandbox(t *testing.T) { assert.Nil(m.CreateSandboxFunc) ctx := context.Background() - _, err := m.CreateSandbox(ctx, vc.SandboxConfig{}) + _, err := m.CreateSandbox(ctx, vc.SandboxConfig{}, nil) assert.Error(err) assert.True(IsMockError(err)) - m.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) { + m.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) { return &Sandbox{}, nil } - sandbox, err := m.CreateSandbox(ctx, vc.SandboxConfig{}) + sandbox, err := m.CreateSandbox(ctx, vc.SandboxConfig{}, nil) assert.NoError(err) assert.Equal(sandbox, &Sandbox{}) // reset m.CreateSandboxFunc = nil - _, err = m.CreateSandbox(ctx, vc.SandboxConfig{}) + _, err = m.CreateSandbox(ctx, vc.SandboxConfig{}, nil) assert.Error(err) assert.True(IsMockError(err)) } diff --git a/src/runtime/virtcontainers/pkg/vcmock/types.go b/src/runtime/virtcontainers/pkg/vcmock/types.go index 05a0a98592..16b811cd52 100644 --- a/src/runtime/virtcontainers/pkg/vcmock/types.go +++ b/src/runtime/virtcontainers/pkg/vcmock/types.go @@ -88,6 +88,6 @@ type VCMock struct { SetLoggerFunc func(ctx context.Context, logger *logrus.Entry) SetFactoryFunc func(ctx context.Context, factory vc.Factory) - CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) + CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error } diff --git a/src/runtime/virtcontainers/sandbox_test.go b/src/runtime/virtcontainers/sandbox_test.go index 59ed24c1aa..3d5154eaea 100644 --- a/src/runtime/virtcontainers/sandbox_test.go +++ b/src/runtime/virtcontainers/sandbox_test.go @@ -1348,7 +1348,7 @@ func TestSandboxCreationFromConfigRollbackFromCreateSandbox(t *testing.T) { // Ensure hypervisor doesn't exist assert.NoError(os.Remove(hConf.HypervisorPath)) - _, err := createSandboxFromConfig(ctx, sConf, nil) + _, err := createSandboxFromConfig(ctx, sConf, nil, nil) // Fail at createSandbox: QEMU path does not exist, it is expected. Then rollback is called assert.Error(err)