diff --git a/hack/mock-gen.sh b/hack/mock-gen.sh index 8c9746b02..5dcdfcc0b 100755 --- a/hack/mock-gen.sh +++ b/hack/mock-gen.sh @@ -46,3 +46,8 @@ mockgen -source vendor/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go \ -imports github.com/koordinator-sh/koordinator/vendor/k8s.io/cri-api/pkg/apis/runtime/v1=k8s.io/cri-api/pkg/apis/runtime/v1 \ -copyright_file ${LICENSE_HEADER_PATH} \ -package mock_client RuntimeServiceClient +mockgen -source vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.pb.go \ + -destination pkg/koordlet/util/runtime/handler/mockv1alpha2client/mock.go \ + -imports github.com/koordinator-sh/koordinator/vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2=k8s.io/cri-api/pkg/apis/runtime/v1alpha2 \ + -copyright_file ${LICENSE_HEADER_PATH} \ + -package mockv1alpha2_client RuntimeServiceClient diff --git a/pkg/koordlet/metricsadvisor/collectors/hostapplication/host_app_collector.go b/pkg/koordlet/metricsadvisor/collectors/hostapplication/host_app_collector.go index e306fe723..23da8c317 100644 --- a/pkg/koordlet/metricsadvisor/collectors/hostapplication/host_app_collector.go +++ b/pkg/koordlet/metricsadvisor/collectors/hostapplication/host_app_collector.go @@ -140,7 +140,7 @@ func (h *hostAppCollector) collectHostAppResUsed() { } metrics = append(metrics, cpuUsageMetric, memUsageMetric) - klog.V(6).Infof("collect host application %v finished, metric %+v", hostApp.Name, metrics) + klog.V(6).Infof("collect host application %v finished, metric cpu=%v, memory=%v", hostApp.Name, cpuUsageValue, memoryUsageValue) count++ allCPUUsageCores.Value += cpuUsageValue allMemoryUsage.Value += float64(memoryUsageValue) diff --git a/pkg/koordlet/runtimehooks/protocol/container_context.go b/pkg/koordlet/runtimehooks/protocol/container_context.go index 6f5fdaae6..5ef45f8b1 100644 --- a/pkg/koordlet/runtimehooks/protocol/container_context.go +++ b/pkg/koordlet/runtimehooks/protocol/container_context.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/containerd/nri/pkg/api" - "k8s.io/klog/v2" apiext "github.com/koordinator-sh/koordinator/apis/extension" @@ -30,6 +29,7 @@ import ( "github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor" "github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer" koordletutil "github.com/koordinator-sh/koordinator/pkg/koordlet/util" + "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system" "github.com/koordinator-sh/koordinator/pkg/util" ) @@ -372,10 +372,10 @@ func (c *ContainerContext) injectForExt() { } func getContainerID(podAnnotations map[string]string, containerUID string) string { - // TODO parse from runtime hook request directly - runtimeType := "containerd" + // TODO parse from runtime hook request directly such as cgroup path format + runtimeType := system.Conf.DefaultRuntimeType if _, exist := podAnnotations["io.kubernetes.docker.type"]; exist { - runtimeType = "docker" + runtimeType = system.RuntimeTypeDocker } return fmt.Sprintf("%s://%s", runtimeType, containerUID) } diff --git a/pkg/koordlet/runtimehooks/protocol/container_context_test.go b/pkg/koordlet/runtimehooks/protocol/container_context_test.go index 68406da6a..8f722d8a3 100644 --- a/pkg/koordlet/runtimehooks/protocol/container_context_test.go +++ b/pkg/koordlet/runtimehooks/protocol/container_context_test.go @@ -28,6 +28,7 @@ import ( "github.com/koordinator-sh/koordinator/apis/extension" "github.com/koordinator-sh/koordinator/pkg/koordlet/resourceexecutor" + "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system" ) func TestContainerContext_FromNri(t *testing.T) { @@ -209,3 +210,65 @@ func TestContainerContext_NriDone(t *testing.T) { }) } } + +func Test_getContainerID(t *testing.T) { + type args struct { + podAnnotations map[string]string + containerUID string + systemConfDefaultRuntime string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "default is containerd", + args: args{ + podAnnotations: nil, + containerUID: "testContainerID", + systemConfDefaultRuntime: system.RuntimeTypeContainerd, + }, + want: "containerd://testContainerID", + }, + { + name: "default is pouch", + args: args{ + podAnnotations: nil, + containerUID: "testContainerID", + systemConfDefaultRuntime: system.RuntimeTypePouch, + }, + want: "pouch://testContainerID", + }, + { + name: "default is docker", + args: args{ + podAnnotations: nil, + containerUID: "testContainerID", + systemConfDefaultRuntime: system.RuntimeTypeDocker, + }, + want: "docker://testContainerID", + }, + { + name: "docker in pod annotation", + args: args{ + podAnnotations: map[string]string{ + "io.kubernetes.docker.type": "true", + }, + containerUID: "testContainerID", + systemConfDefaultRuntime: system.RuntimeTypePouch, + }, + want: "docker://testContainerID", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + system.Conf = &system.Config{ + DefaultRuntimeType: tt.args.systemConfDefaultRuntime, + } + if got := getContainerID(tt.args.podAnnotations, tt.args.containerUID); got != tt.want { + t.Errorf("getContainerID() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/koordlet/util/runtime/handler/mockclient/mock.go b/pkg/koordlet/util/runtime/handler/mockclient/mock.go index 9a2621e25..08c26aa89 100644 --- a/pkg/koordlet/util/runtime/handler/mockclient/mock.go +++ b/pkg/koordlet/util/runtime/handler/mockclient/mock.go @@ -13,12 +13,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +// // Code generated by MockGen. DO NOT EDIT. // Source: vendor/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go -// Package mockclient is a generated GoMock package. -package mockclient +// Package mock_client is a generated GoMock package. +package mock_client import ( context "context" diff --git a/pkg/koordlet/util/runtime/handler/mockv1alpha2client/mock.go b/pkg/koordlet/util/runtime/handler/mockv1alpha2client/mock.go new file mode 100644 index 000000000..57e2d401a --- /dev/null +++ b/pkg/koordlet/util/runtime/handler/mockv1alpha2client/mock.go @@ -0,0 +1,1138 @@ +/* +Copyright 2022 The Koordinator Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// + +// Code generated by MockGen. DO NOT EDIT. +// Source: vendor/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.pb.go + +// Package mockv1alpha2_client is a generated GoMock package. +package mockv1alpha2_client + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + grpc "google.golang.org/grpc" + v1alpha2 "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" +) + +// MockRuntimeServiceClient is a mock of RuntimeServiceClient interface. +type MockRuntimeServiceClient struct { + ctrl *gomock.Controller + recorder *MockRuntimeServiceClientMockRecorder +} + +// MockRuntimeServiceClientMockRecorder is the mock recorder for MockRuntimeServiceClient. +type MockRuntimeServiceClientMockRecorder struct { + mock *MockRuntimeServiceClient +} + +// NewMockRuntimeServiceClient creates a new mock instance. +func NewMockRuntimeServiceClient(ctrl *gomock.Controller) *MockRuntimeServiceClient { + mock := &MockRuntimeServiceClient{ctrl: ctrl} + mock.recorder = &MockRuntimeServiceClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRuntimeServiceClient) EXPECT() *MockRuntimeServiceClientMockRecorder { + return m.recorder +} + +// Attach mocks base method. +func (m *MockRuntimeServiceClient) Attach(ctx context.Context, in *v1alpha2.AttachRequest, opts ...grpc.CallOption) (*v1alpha2.AttachResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Attach", varargs...) + ret0, _ := ret[0].(*v1alpha2.AttachResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Attach indicates an expected call of Attach. +func (mr *MockRuntimeServiceClientMockRecorder) Attach(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Attach", reflect.TypeOf((*MockRuntimeServiceClient)(nil).Attach), varargs...) +} + +// ContainerStats mocks base method. +func (m *MockRuntimeServiceClient) ContainerStats(ctx context.Context, in *v1alpha2.ContainerStatsRequest, opts ...grpc.CallOption) (*v1alpha2.ContainerStatsResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ContainerStats", varargs...) + ret0, _ := ret[0].(*v1alpha2.ContainerStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContainerStats indicates an expected call of ContainerStats. +func (mr *MockRuntimeServiceClientMockRecorder) ContainerStats(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStats", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ContainerStats), varargs...) +} + +// ContainerStatus mocks base method. +func (m *MockRuntimeServiceClient) ContainerStatus(ctx context.Context, in *v1alpha2.ContainerStatusRequest, opts ...grpc.CallOption) (*v1alpha2.ContainerStatusResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ContainerStatus", varargs...) + ret0, _ := ret[0].(*v1alpha2.ContainerStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContainerStatus indicates an expected call of ContainerStatus. +func (mr *MockRuntimeServiceClientMockRecorder) ContainerStatus(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStatus", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ContainerStatus), varargs...) +} + +// CreateContainer mocks base method. +func (m *MockRuntimeServiceClient) CreateContainer(ctx context.Context, in *v1alpha2.CreateContainerRequest, opts ...grpc.CallOption) (*v1alpha2.CreateContainerResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "CreateContainer", varargs...) + ret0, _ := ret[0].(*v1alpha2.CreateContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateContainer indicates an expected call of CreateContainer. +func (mr *MockRuntimeServiceClientMockRecorder) CreateContainer(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateContainer", reflect.TypeOf((*MockRuntimeServiceClient)(nil).CreateContainer), varargs...) +} + +// Exec mocks base method. +func (m *MockRuntimeServiceClient) Exec(ctx context.Context, in *v1alpha2.ExecRequest, opts ...grpc.CallOption) (*v1alpha2.ExecResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Exec", varargs...) + ret0, _ := ret[0].(*v1alpha2.ExecResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Exec indicates an expected call of Exec. +func (mr *MockRuntimeServiceClientMockRecorder) Exec(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exec", reflect.TypeOf((*MockRuntimeServiceClient)(nil).Exec), varargs...) +} + +// ExecSync mocks base method. +func (m *MockRuntimeServiceClient) ExecSync(ctx context.Context, in *v1alpha2.ExecSyncRequest, opts ...grpc.CallOption) (*v1alpha2.ExecSyncResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ExecSync", varargs...) + ret0, _ := ret[0].(*v1alpha2.ExecSyncResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ExecSync indicates an expected call of ExecSync. +func (mr *MockRuntimeServiceClientMockRecorder) ExecSync(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecSync", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ExecSync), varargs...) +} + +// ListContainerStats mocks base method. +func (m *MockRuntimeServiceClient) ListContainerStats(ctx context.Context, in *v1alpha2.ListContainerStatsRequest, opts ...grpc.CallOption) (*v1alpha2.ListContainerStatsResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ListContainerStats", varargs...) + ret0, _ := ret[0].(*v1alpha2.ListContainerStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListContainerStats indicates an expected call of ListContainerStats. +func (mr *MockRuntimeServiceClientMockRecorder) ListContainerStats(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListContainerStats", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ListContainerStats), varargs...) +} + +// ListContainers mocks base method. +func (m *MockRuntimeServiceClient) ListContainers(ctx context.Context, in *v1alpha2.ListContainersRequest, opts ...grpc.CallOption) (*v1alpha2.ListContainersResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ListContainers", varargs...) + ret0, _ := ret[0].(*v1alpha2.ListContainersResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListContainers indicates an expected call of ListContainers. +func (mr *MockRuntimeServiceClientMockRecorder) ListContainers(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListContainers", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ListContainers), varargs...) +} + +// ListPodSandbox mocks base method. +func (m *MockRuntimeServiceClient) ListPodSandbox(ctx context.Context, in *v1alpha2.ListPodSandboxRequest, opts ...grpc.CallOption) (*v1alpha2.ListPodSandboxResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ListPodSandbox", varargs...) + ret0, _ := ret[0].(*v1alpha2.ListPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListPodSandbox indicates an expected call of ListPodSandbox. +func (mr *MockRuntimeServiceClientMockRecorder) ListPodSandbox(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodSandbox", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ListPodSandbox), varargs...) +} + +// ListPodSandboxStats mocks base method. +func (m *MockRuntimeServiceClient) ListPodSandboxStats(ctx context.Context, in *v1alpha2.ListPodSandboxStatsRequest, opts ...grpc.CallOption) (*v1alpha2.ListPodSandboxStatsResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ListPodSandboxStats", varargs...) + ret0, _ := ret[0].(*v1alpha2.ListPodSandboxStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListPodSandboxStats indicates an expected call of ListPodSandboxStats. +func (mr *MockRuntimeServiceClientMockRecorder) ListPodSandboxStats(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodSandboxStats", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ListPodSandboxStats), varargs...) +} + +// PodSandboxStats mocks base method. +func (m *MockRuntimeServiceClient) PodSandboxStats(ctx context.Context, in *v1alpha2.PodSandboxStatsRequest, opts ...grpc.CallOption) (*v1alpha2.PodSandboxStatsResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PodSandboxStats", varargs...) + ret0, _ := ret[0].(*v1alpha2.PodSandboxStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PodSandboxStats indicates an expected call of PodSandboxStats. +func (mr *MockRuntimeServiceClientMockRecorder) PodSandboxStats(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSandboxStats", reflect.TypeOf((*MockRuntimeServiceClient)(nil).PodSandboxStats), varargs...) +} + +// PodSandboxStatus mocks base method. +func (m *MockRuntimeServiceClient) PodSandboxStatus(ctx context.Context, in *v1alpha2.PodSandboxStatusRequest, opts ...grpc.CallOption) (*v1alpha2.PodSandboxStatusResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PodSandboxStatus", varargs...) + ret0, _ := ret[0].(*v1alpha2.PodSandboxStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PodSandboxStatus indicates an expected call of PodSandboxStatus. +func (mr *MockRuntimeServiceClientMockRecorder) PodSandboxStatus(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSandboxStatus", reflect.TypeOf((*MockRuntimeServiceClient)(nil).PodSandboxStatus), varargs...) +} + +// PortForward mocks base method. +func (m *MockRuntimeServiceClient) PortForward(ctx context.Context, in *v1alpha2.PortForwardRequest, opts ...grpc.CallOption) (*v1alpha2.PortForwardResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PortForward", varargs...) + ret0, _ := ret[0].(*v1alpha2.PortForwardResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PortForward indicates an expected call of PortForward. +func (mr *MockRuntimeServiceClientMockRecorder) PortForward(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PortForward", reflect.TypeOf((*MockRuntimeServiceClient)(nil).PortForward), varargs...) +} + +// RemoveContainer mocks base method. +func (m *MockRuntimeServiceClient) RemoveContainer(ctx context.Context, in *v1alpha2.RemoveContainerRequest, opts ...grpc.CallOption) (*v1alpha2.RemoveContainerResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RemoveContainer", varargs...) + ret0, _ := ret[0].(*v1alpha2.RemoveContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemoveContainer indicates an expected call of RemoveContainer. +func (mr *MockRuntimeServiceClientMockRecorder) RemoveContainer(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveContainer", reflect.TypeOf((*MockRuntimeServiceClient)(nil).RemoveContainer), varargs...) +} + +// RemovePodSandbox mocks base method. +func (m *MockRuntimeServiceClient) RemovePodSandbox(ctx context.Context, in *v1alpha2.RemovePodSandboxRequest, opts ...grpc.CallOption) (*v1alpha2.RemovePodSandboxResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RemovePodSandbox", varargs...) + ret0, _ := ret[0].(*v1alpha2.RemovePodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemovePodSandbox indicates an expected call of RemovePodSandbox. +func (mr *MockRuntimeServiceClientMockRecorder) RemovePodSandbox(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemovePodSandbox", reflect.TypeOf((*MockRuntimeServiceClient)(nil).RemovePodSandbox), varargs...) +} + +// ReopenContainerLog mocks base method. +func (m *MockRuntimeServiceClient) ReopenContainerLog(ctx context.Context, in *v1alpha2.ReopenContainerLogRequest, opts ...grpc.CallOption) (*v1alpha2.ReopenContainerLogResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ReopenContainerLog", varargs...) + ret0, _ := ret[0].(*v1alpha2.ReopenContainerLogResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReopenContainerLog indicates an expected call of ReopenContainerLog. +func (mr *MockRuntimeServiceClientMockRecorder) ReopenContainerLog(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReopenContainerLog", reflect.TypeOf((*MockRuntimeServiceClient)(nil).ReopenContainerLog), varargs...) +} + +// RunPodSandbox mocks base method. +func (m *MockRuntimeServiceClient) RunPodSandbox(ctx context.Context, in *v1alpha2.RunPodSandboxRequest, opts ...grpc.CallOption) (*v1alpha2.RunPodSandboxResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RunPodSandbox", varargs...) + ret0, _ := ret[0].(*v1alpha2.RunPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RunPodSandbox indicates an expected call of RunPodSandbox. +func (mr *MockRuntimeServiceClientMockRecorder) RunPodSandbox(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunPodSandbox", reflect.TypeOf((*MockRuntimeServiceClient)(nil).RunPodSandbox), varargs...) +} + +// StartContainer mocks base method. +func (m *MockRuntimeServiceClient) StartContainer(ctx context.Context, in *v1alpha2.StartContainerRequest, opts ...grpc.CallOption) (*v1alpha2.StartContainerResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "StartContainer", varargs...) + ret0, _ := ret[0].(*v1alpha2.StartContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StartContainer indicates an expected call of StartContainer. +func (mr *MockRuntimeServiceClientMockRecorder) StartContainer(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartContainer", reflect.TypeOf((*MockRuntimeServiceClient)(nil).StartContainer), varargs...) +} + +// Status mocks base method. +func (m *MockRuntimeServiceClient) Status(ctx context.Context, in *v1alpha2.StatusRequest, opts ...grpc.CallOption) (*v1alpha2.StatusResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Status", varargs...) + ret0, _ := ret[0].(*v1alpha2.StatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Status indicates an expected call of Status. +func (mr *MockRuntimeServiceClientMockRecorder) Status(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockRuntimeServiceClient)(nil).Status), varargs...) +} + +// StopContainer mocks base method. +func (m *MockRuntimeServiceClient) StopContainer(ctx context.Context, in *v1alpha2.StopContainerRequest, opts ...grpc.CallOption) (*v1alpha2.StopContainerResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "StopContainer", varargs...) + ret0, _ := ret[0].(*v1alpha2.StopContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StopContainer indicates an expected call of StopContainer. +func (mr *MockRuntimeServiceClientMockRecorder) StopContainer(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopContainer", reflect.TypeOf((*MockRuntimeServiceClient)(nil).StopContainer), varargs...) +} + +// StopPodSandbox mocks base method. +func (m *MockRuntimeServiceClient) StopPodSandbox(ctx context.Context, in *v1alpha2.StopPodSandboxRequest, opts ...grpc.CallOption) (*v1alpha2.StopPodSandboxResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "StopPodSandbox", varargs...) + ret0, _ := ret[0].(*v1alpha2.StopPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StopPodSandbox indicates an expected call of StopPodSandbox. +func (mr *MockRuntimeServiceClientMockRecorder) StopPodSandbox(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopPodSandbox", reflect.TypeOf((*MockRuntimeServiceClient)(nil).StopPodSandbox), varargs...) +} + +// UpdateContainerResources mocks base method. +func (m *MockRuntimeServiceClient) UpdateContainerResources(ctx context.Context, in *v1alpha2.UpdateContainerResourcesRequest, opts ...grpc.CallOption) (*v1alpha2.UpdateContainerResourcesResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UpdateContainerResources", varargs...) + ret0, _ := ret[0].(*v1alpha2.UpdateContainerResourcesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateContainerResources indicates an expected call of UpdateContainerResources. +func (mr *MockRuntimeServiceClientMockRecorder) UpdateContainerResources(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainerResources", reflect.TypeOf((*MockRuntimeServiceClient)(nil).UpdateContainerResources), varargs...) +} + +// UpdateRuntimeConfig mocks base method. +func (m *MockRuntimeServiceClient) UpdateRuntimeConfig(ctx context.Context, in *v1alpha2.UpdateRuntimeConfigRequest, opts ...grpc.CallOption) (*v1alpha2.UpdateRuntimeConfigResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UpdateRuntimeConfig", varargs...) + ret0, _ := ret[0].(*v1alpha2.UpdateRuntimeConfigResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateRuntimeConfig indicates an expected call of UpdateRuntimeConfig. +func (mr *MockRuntimeServiceClientMockRecorder) UpdateRuntimeConfig(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRuntimeConfig", reflect.TypeOf((*MockRuntimeServiceClient)(nil).UpdateRuntimeConfig), varargs...) +} + +// Version mocks base method. +func (m *MockRuntimeServiceClient) Version(ctx context.Context, in *v1alpha2.VersionRequest, opts ...grpc.CallOption) (*v1alpha2.VersionResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Version", varargs...) + ret0, _ := ret[0].(*v1alpha2.VersionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Version indicates an expected call of Version. +func (mr *MockRuntimeServiceClientMockRecorder) Version(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockRuntimeServiceClient)(nil).Version), varargs...) +} + +// MockRuntimeServiceServer is a mock of RuntimeServiceServer interface. +type MockRuntimeServiceServer struct { + ctrl *gomock.Controller + recorder *MockRuntimeServiceServerMockRecorder +} + +// MockRuntimeServiceServerMockRecorder is the mock recorder for MockRuntimeServiceServer. +type MockRuntimeServiceServerMockRecorder struct { + mock *MockRuntimeServiceServer +} + +// NewMockRuntimeServiceServer creates a new mock instance. +func NewMockRuntimeServiceServer(ctrl *gomock.Controller) *MockRuntimeServiceServer { + mock := &MockRuntimeServiceServer{ctrl: ctrl} + mock.recorder = &MockRuntimeServiceServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRuntimeServiceServer) EXPECT() *MockRuntimeServiceServerMockRecorder { + return m.recorder +} + +// Attach mocks base method. +func (m *MockRuntimeServiceServer) Attach(arg0 context.Context, arg1 *v1alpha2.AttachRequest) (*v1alpha2.AttachResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Attach", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.AttachResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Attach indicates an expected call of Attach. +func (mr *MockRuntimeServiceServerMockRecorder) Attach(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Attach", reflect.TypeOf((*MockRuntimeServiceServer)(nil).Attach), arg0, arg1) +} + +// ContainerStats mocks base method. +func (m *MockRuntimeServiceServer) ContainerStats(arg0 context.Context, arg1 *v1alpha2.ContainerStatsRequest) (*v1alpha2.ContainerStatsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContainerStats", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ContainerStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContainerStats indicates an expected call of ContainerStats. +func (mr *MockRuntimeServiceServerMockRecorder) ContainerStats(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStats", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ContainerStats), arg0, arg1) +} + +// ContainerStatus mocks base method. +func (m *MockRuntimeServiceServer) ContainerStatus(arg0 context.Context, arg1 *v1alpha2.ContainerStatusRequest) (*v1alpha2.ContainerStatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContainerStatus", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ContainerStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContainerStatus indicates an expected call of ContainerStatus. +func (mr *MockRuntimeServiceServerMockRecorder) ContainerStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContainerStatus", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ContainerStatus), arg0, arg1) +} + +// CreateContainer mocks base method. +func (m *MockRuntimeServiceServer) CreateContainer(arg0 context.Context, arg1 *v1alpha2.CreateContainerRequest) (*v1alpha2.CreateContainerResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateContainer", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.CreateContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateContainer indicates an expected call of CreateContainer. +func (mr *MockRuntimeServiceServerMockRecorder) CreateContainer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateContainer", reflect.TypeOf((*MockRuntimeServiceServer)(nil).CreateContainer), arg0, arg1) +} + +// Exec mocks base method. +func (m *MockRuntimeServiceServer) Exec(arg0 context.Context, arg1 *v1alpha2.ExecRequest) (*v1alpha2.ExecResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Exec", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ExecResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Exec indicates an expected call of Exec. +func (mr *MockRuntimeServiceServerMockRecorder) Exec(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exec", reflect.TypeOf((*MockRuntimeServiceServer)(nil).Exec), arg0, arg1) +} + +// ExecSync mocks base method. +func (m *MockRuntimeServiceServer) ExecSync(arg0 context.Context, arg1 *v1alpha2.ExecSyncRequest) (*v1alpha2.ExecSyncResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExecSync", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ExecSyncResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ExecSync indicates an expected call of ExecSync. +func (mr *MockRuntimeServiceServerMockRecorder) ExecSync(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecSync", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ExecSync), arg0, arg1) +} + +// ListContainerStats mocks base method. +func (m *MockRuntimeServiceServer) ListContainerStats(arg0 context.Context, arg1 *v1alpha2.ListContainerStatsRequest) (*v1alpha2.ListContainerStatsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListContainerStats", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ListContainerStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListContainerStats indicates an expected call of ListContainerStats. +func (mr *MockRuntimeServiceServerMockRecorder) ListContainerStats(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListContainerStats", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ListContainerStats), arg0, arg1) +} + +// ListContainers mocks base method. +func (m *MockRuntimeServiceServer) ListContainers(arg0 context.Context, arg1 *v1alpha2.ListContainersRequest) (*v1alpha2.ListContainersResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListContainers", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ListContainersResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListContainers indicates an expected call of ListContainers. +func (mr *MockRuntimeServiceServerMockRecorder) ListContainers(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListContainers", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ListContainers), arg0, arg1) +} + +// ListPodSandbox mocks base method. +func (m *MockRuntimeServiceServer) ListPodSandbox(arg0 context.Context, arg1 *v1alpha2.ListPodSandboxRequest) (*v1alpha2.ListPodSandboxResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListPodSandbox", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ListPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListPodSandbox indicates an expected call of ListPodSandbox. +func (mr *MockRuntimeServiceServerMockRecorder) ListPodSandbox(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodSandbox", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ListPodSandbox), arg0, arg1) +} + +// ListPodSandboxStats mocks base method. +func (m *MockRuntimeServiceServer) ListPodSandboxStats(arg0 context.Context, arg1 *v1alpha2.ListPodSandboxStatsRequest) (*v1alpha2.ListPodSandboxStatsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListPodSandboxStats", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ListPodSandboxStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListPodSandboxStats indicates an expected call of ListPodSandboxStats. +func (mr *MockRuntimeServiceServerMockRecorder) ListPodSandboxStats(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPodSandboxStats", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ListPodSandboxStats), arg0, arg1) +} + +// PodSandboxStats mocks base method. +func (m *MockRuntimeServiceServer) PodSandboxStats(arg0 context.Context, arg1 *v1alpha2.PodSandboxStatsRequest) (*v1alpha2.PodSandboxStatsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PodSandboxStats", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.PodSandboxStatsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PodSandboxStats indicates an expected call of PodSandboxStats. +func (mr *MockRuntimeServiceServerMockRecorder) PodSandboxStats(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSandboxStats", reflect.TypeOf((*MockRuntimeServiceServer)(nil).PodSandboxStats), arg0, arg1) +} + +// PodSandboxStatus mocks base method. +func (m *MockRuntimeServiceServer) PodSandboxStatus(arg0 context.Context, arg1 *v1alpha2.PodSandboxStatusRequest) (*v1alpha2.PodSandboxStatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PodSandboxStatus", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.PodSandboxStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PodSandboxStatus indicates an expected call of PodSandboxStatus. +func (mr *MockRuntimeServiceServerMockRecorder) PodSandboxStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PodSandboxStatus", reflect.TypeOf((*MockRuntimeServiceServer)(nil).PodSandboxStatus), arg0, arg1) +} + +// PortForward mocks base method. +func (m *MockRuntimeServiceServer) PortForward(arg0 context.Context, arg1 *v1alpha2.PortForwardRequest) (*v1alpha2.PortForwardResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PortForward", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.PortForwardResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PortForward indicates an expected call of PortForward. +func (mr *MockRuntimeServiceServerMockRecorder) PortForward(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PortForward", reflect.TypeOf((*MockRuntimeServiceServer)(nil).PortForward), arg0, arg1) +} + +// RemoveContainer mocks base method. +func (m *MockRuntimeServiceServer) RemoveContainer(arg0 context.Context, arg1 *v1alpha2.RemoveContainerRequest) (*v1alpha2.RemoveContainerResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveContainer", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.RemoveContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemoveContainer indicates an expected call of RemoveContainer. +func (mr *MockRuntimeServiceServerMockRecorder) RemoveContainer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveContainer", reflect.TypeOf((*MockRuntimeServiceServer)(nil).RemoveContainer), arg0, arg1) +} + +// RemovePodSandbox mocks base method. +func (m *MockRuntimeServiceServer) RemovePodSandbox(arg0 context.Context, arg1 *v1alpha2.RemovePodSandboxRequest) (*v1alpha2.RemovePodSandboxResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemovePodSandbox", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.RemovePodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemovePodSandbox indicates an expected call of RemovePodSandbox. +func (mr *MockRuntimeServiceServerMockRecorder) RemovePodSandbox(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemovePodSandbox", reflect.TypeOf((*MockRuntimeServiceServer)(nil).RemovePodSandbox), arg0, arg1) +} + +// ReopenContainerLog mocks base method. +func (m *MockRuntimeServiceServer) ReopenContainerLog(arg0 context.Context, arg1 *v1alpha2.ReopenContainerLogRequest) (*v1alpha2.ReopenContainerLogResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReopenContainerLog", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ReopenContainerLogResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ReopenContainerLog indicates an expected call of ReopenContainerLog. +func (mr *MockRuntimeServiceServerMockRecorder) ReopenContainerLog(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReopenContainerLog", reflect.TypeOf((*MockRuntimeServiceServer)(nil).ReopenContainerLog), arg0, arg1) +} + +// RunPodSandbox mocks base method. +func (m *MockRuntimeServiceServer) RunPodSandbox(arg0 context.Context, arg1 *v1alpha2.RunPodSandboxRequest) (*v1alpha2.RunPodSandboxResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RunPodSandbox", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.RunPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RunPodSandbox indicates an expected call of RunPodSandbox. +func (mr *MockRuntimeServiceServerMockRecorder) RunPodSandbox(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunPodSandbox", reflect.TypeOf((*MockRuntimeServiceServer)(nil).RunPodSandbox), arg0, arg1) +} + +// StartContainer mocks base method. +func (m *MockRuntimeServiceServer) StartContainer(arg0 context.Context, arg1 *v1alpha2.StartContainerRequest) (*v1alpha2.StartContainerResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StartContainer", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.StartContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StartContainer indicates an expected call of StartContainer. +func (mr *MockRuntimeServiceServerMockRecorder) StartContainer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartContainer", reflect.TypeOf((*MockRuntimeServiceServer)(nil).StartContainer), arg0, arg1) +} + +// Status mocks base method. +func (m *MockRuntimeServiceServer) Status(arg0 context.Context, arg1 *v1alpha2.StatusRequest) (*v1alpha2.StatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Status", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.StatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Status indicates an expected call of Status. +func (mr *MockRuntimeServiceServerMockRecorder) Status(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockRuntimeServiceServer)(nil).Status), arg0, arg1) +} + +// StopContainer mocks base method. +func (m *MockRuntimeServiceServer) StopContainer(arg0 context.Context, arg1 *v1alpha2.StopContainerRequest) (*v1alpha2.StopContainerResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StopContainer", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.StopContainerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StopContainer indicates an expected call of StopContainer. +func (mr *MockRuntimeServiceServerMockRecorder) StopContainer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopContainer", reflect.TypeOf((*MockRuntimeServiceServer)(nil).StopContainer), arg0, arg1) +} + +// StopPodSandbox mocks base method. +func (m *MockRuntimeServiceServer) StopPodSandbox(arg0 context.Context, arg1 *v1alpha2.StopPodSandboxRequest) (*v1alpha2.StopPodSandboxResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StopPodSandbox", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.StopPodSandboxResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StopPodSandbox indicates an expected call of StopPodSandbox. +func (mr *MockRuntimeServiceServerMockRecorder) StopPodSandbox(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopPodSandbox", reflect.TypeOf((*MockRuntimeServiceServer)(nil).StopPodSandbox), arg0, arg1) +} + +// UpdateContainerResources mocks base method. +func (m *MockRuntimeServiceServer) UpdateContainerResources(arg0 context.Context, arg1 *v1alpha2.UpdateContainerResourcesRequest) (*v1alpha2.UpdateContainerResourcesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateContainerResources", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.UpdateContainerResourcesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateContainerResources indicates an expected call of UpdateContainerResources. +func (mr *MockRuntimeServiceServerMockRecorder) UpdateContainerResources(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateContainerResources", reflect.TypeOf((*MockRuntimeServiceServer)(nil).UpdateContainerResources), arg0, arg1) +} + +// UpdateRuntimeConfig mocks base method. +func (m *MockRuntimeServiceServer) UpdateRuntimeConfig(arg0 context.Context, arg1 *v1alpha2.UpdateRuntimeConfigRequest) (*v1alpha2.UpdateRuntimeConfigResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateRuntimeConfig", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.UpdateRuntimeConfigResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateRuntimeConfig indicates an expected call of UpdateRuntimeConfig. +func (mr *MockRuntimeServiceServerMockRecorder) UpdateRuntimeConfig(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRuntimeConfig", reflect.TypeOf((*MockRuntimeServiceServer)(nil).UpdateRuntimeConfig), arg0, arg1) +} + +// Version mocks base method. +func (m *MockRuntimeServiceServer) Version(arg0 context.Context, arg1 *v1alpha2.VersionRequest) (*v1alpha2.VersionResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Version", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.VersionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Version indicates an expected call of Version. +func (mr *MockRuntimeServiceServerMockRecorder) Version(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Version", reflect.TypeOf((*MockRuntimeServiceServer)(nil).Version), arg0, arg1) +} + +// MockImageServiceClient is a mock of ImageServiceClient interface. +type MockImageServiceClient struct { + ctrl *gomock.Controller + recorder *MockImageServiceClientMockRecorder +} + +// MockImageServiceClientMockRecorder is the mock recorder for MockImageServiceClient. +type MockImageServiceClientMockRecorder struct { + mock *MockImageServiceClient +} + +// NewMockImageServiceClient creates a new mock instance. +func NewMockImageServiceClient(ctrl *gomock.Controller) *MockImageServiceClient { + mock := &MockImageServiceClient{ctrl: ctrl} + mock.recorder = &MockImageServiceClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockImageServiceClient) EXPECT() *MockImageServiceClientMockRecorder { + return m.recorder +} + +// ImageFsInfo mocks base method. +func (m *MockImageServiceClient) ImageFsInfo(ctx context.Context, in *v1alpha2.ImageFsInfoRequest, opts ...grpc.CallOption) (*v1alpha2.ImageFsInfoResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ImageFsInfo", varargs...) + ret0, _ := ret[0].(*v1alpha2.ImageFsInfoResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ImageFsInfo indicates an expected call of ImageFsInfo. +func (mr *MockImageServiceClientMockRecorder) ImageFsInfo(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsInfo", reflect.TypeOf((*MockImageServiceClient)(nil).ImageFsInfo), varargs...) +} + +// ImageStatus mocks base method. +func (m *MockImageServiceClient) ImageStatus(ctx context.Context, in *v1alpha2.ImageStatusRequest, opts ...grpc.CallOption) (*v1alpha2.ImageStatusResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ImageStatus", varargs...) + ret0, _ := ret[0].(*v1alpha2.ImageStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ImageStatus indicates an expected call of ImageStatus. +func (mr *MockImageServiceClientMockRecorder) ImageStatus(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageStatus", reflect.TypeOf((*MockImageServiceClient)(nil).ImageStatus), varargs...) +} + +// ListImages mocks base method. +func (m *MockImageServiceClient) ListImages(ctx context.Context, in *v1alpha2.ListImagesRequest, opts ...grpc.CallOption) (*v1alpha2.ListImagesResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "ListImages", varargs...) + ret0, _ := ret[0].(*v1alpha2.ListImagesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListImages indicates an expected call of ListImages. +func (mr *MockImageServiceClientMockRecorder) ListImages(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImages", reflect.TypeOf((*MockImageServiceClient)(nil).ListImages), varargs...) +} + +// PullImage mocks base method. +func (m *MockImageServiceClient) PullImage(ctx context.Context, in *v1alpha2.PullImageRequest, opts ...grpc.CallOption) (*v1alpha2.PullImageResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PullImage", varargs...) + ret0, _ := ret[0].(*v1alpha2.PullImageResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PullImage indicates an expected call of PullImage. +func (mr *MockImageServiceClientMockRecorder) PullImage(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullImage", reflect.TypeOf((*MockImageServiceClient)(nil).PullImage), varargs...) +} + +// RemoveImage mocks base method. +func (m *MockImageServiceClient) RemoveImage(ctx context.Context, in *v1alpha2.RemoveImageRequest, opts ...grpc.CallOption) (*v1alpha2.RemoveImageResponse, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, in} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "RemoveImage", varargs...) + ret0, _ := ret[0].(*v1alpha2.RemoveImageResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemoveImage indicates an expected call of RemoveImage. +func (mr *MockImageServiceClientMockRecorder) RemoveImage(ctx, in interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, in}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveImage", reflect.TypeOf((*MockImageServiceClient)(nil).RemoveImage), varargs...) +} + +// MockImageServiceServer is a mock of ImageServiceServer interface. +type MockImageServiceServer struct { + ctrl *gomock.Controller + recorder *MockImageServiceServerMockRecorder +} + +// MockImageServiceServerMockRecorder is the mock recorder for MockImageServiceServer. +type MockImageServiceServerMockRecorder struct { + mock *MockImageServiceServer +} + +// NewMockImageServiceServer creates a new mock instance. +func NewMockImageServiceServer(ctrl *gomock.Controller) *MockImageServiceServer { + mock := &MockImageServiceServer{ctrl: ctrl} + mock.recorder = &MockImageServiceServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockImageServiceServer) EXPECT() *MockImageServiceServerMockRecorder { + return m.recorder +} + +// ImageFsInfo mocks base method. +func (m *MockImageServiceServer) ImageFsInfo(arg0 context.Context, arg1 *v1alpha2.ImageFsInfoRequest) (*v1alpha2.ImageFsInfoResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ImageFsInfo", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ImageFsInfoResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ImageFsInfo indicates an expected call of ImageFsInfo. +func (mr *MockImageServiceServerMockRecorder) ImageFsInfo(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageFsInfo", reflect.TypeOf((*MockImageServiceServer)(nil).ImageFsInfo), arg0, arg1) +} + +// ImageStatus mocks base method. +func (m *MockImageServiceServer) ImageStatus(arg0 context.Context, arg1 *v1alpha2.ImageStatusRequest) (*v1alpha2.ImageStatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ImageStatus", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ImageStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ImageStatus indicates an expected call of ImageStatus. +func (mr *MockImageServiceServerMockRecorder) ImageStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageStatus", reflect.TypeOf((*MockImageServiceServer)(nil).ImageStatus), arg0, arg1) +} + +// ListImages mocks base method. +func (m *MockImageServiceServer) ListImages(arg0 context.Context, arg1 *v1alpha2.ListImagesRequest) (*v1alpha2.ListImagesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListImages", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.ListImagesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListImages indicates an expected call of ListImages. +func (mr *MockImageServiceServerMockRecorder) ListImages(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImages", reflect.TypeOf((*MockImageServiceServer)(nil).ListImages), arg0, arg1) +} + +// PullImage mocks base method. +func (m *MockImageServiceServer) PullImage(arg0 context.Context, arg1 *v1alpha2.PullImageRequest) (*v1alpha2.PullImageResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PullImage", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.PullImageResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PullImage indicates an expected call of PullImage. +func (mr *MockImageServiceServerMockRecorder) PullImage(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullImage", reflect.TypeOf((*MockImageServiceServer)(nil).PullImage), arg0, arg1) +} + +// RemoveImage mocks base method. +func (m *MockImageServiceServer) RemoveImage(arg0 context.Context, arg1 *v1alpha2.RemoveImageRequest) (*v1alpha2.RemoveImageResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveImage", arg0, arg1) + ret0, _ := ret[0].(*v1alpha2.RemoveImageResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RemoveImage indicates an expected call of RemoveImage. +func (mr *MockImageServiceServerMockRecorder) RemoveImage(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveImage", reflect.TypeOf((*MockImageServiceServer)(nil).RemoveImage), arg0, arg1) +} diff --git a/pkg/koordlet/util/runtime/handler/pouch_runtime.go b/pkg/koordlet/util/runtime/handler/pouch_runtime.go new file mode 100644 index 000000000..30d707feb --- /dev/null +++ b/pkg/koordlet/util/runtime/handler/pouch_runtime.go @@ -0,0 +1,107 @@ +/* +Copyright 2022 The Koordinator Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package handler + +import ( + "context" + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" + + "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system" +) + +const ( + PouchEndpointSubFilepath = "pouchcri.sock" +) + +func GetPouchEndpoint() string { + return filepath.Join(system.Conf.VarRunRootDir, PouchEndpointSubFilepath) +} + +type PouchRuntimeHandler struct { + runtimeServiceClient v1alpha2.RuntimeServiceClient + timeout time.Duration + endpoint string +} + +func NewPouchRuntimeHandler(endpoint string) (ContainerRuntimeHandler, error) { + ep := strings.TrimPrefix(endpoint, "unix://") + if _, err := os.Stat(ep); err != nil { + return nil, err + } + // use v1alpha2 protocol + client, err := getRuntimeV1alpha2Client(endpoint) + if err != nil { + return nil, err + } + + return &PouchRuntimeHandler{ + runtimeServiceClient: client, + timeout: defaultConnectionTimeout, + endpoint: endpoint, + }, nil +} + +func (c *PouchRuntimeHandler) StopContainer(containerID string, timeout int64) error { + if containerID == "" { + return fmt.Errorf("containerID cannot be empty") + } + + request := &v1alpha2.StopContainerRequest{ + ContainerId: containerID, + Timeout: timeout, + } + // pouch cannot handle context with timeout + _, err := c.runtimeServiceClient.StopContainer(context.Background(), request) + return err +} + +func (c *PouchRuntimeHandler) UpdateContainerResources(containerID string, opts UpdateOptions) error { + if containerID == "" { + return fmt.Errorf("containerID cannot be empty") + } + ctx, cancel := context.WithTimeout(context.Background(), c.timeout) + defer cancel() + request := &v1alpha2.UpdateContainerResourcesRequest{ + ContainerId: containerID, + Linux: &v1alpha2.LinuxContainerResources{ + CpuPeriod: opts.CPUPeriod, + CpuQuota: opts.CPUQuota, + CpuShares: opts.CPUShares, + CpusetCpus: opts.CpusetCpus, + CpusetMems: opts.CpusetMems, + MemoryLimitInBytes: opts.MemoryLimitInBytes, + OomScoreAdj: opts.OomScoreAdj, + }, + } + _, err := c.runtimeServiceClient.UpdateContainerResources(ctx, request) + return err +} + +func getRuntimeV1alpha2Client(endpoint string) (v1alpha2.RuntimeServiceClient, error) { + conn, err := getClientConnection(endpoint) + if err != nil { + return nil, fmt.Errorf("failed to connect: %v", err) + } + runtimeClient := v1alpha2.NewRuntimeServiceClient(conn) + return runtimeClient, nil +} diff --git a/pkg/koordlet/util/runtime/handler/pouch_runtime_test.go b/pkg/koordlet/util/runtime/handler/pouch_runtime_test.go new file mode 100644 index 000000000..d03276207 --- /dev/null +++ b/pkg/koordlet/util/runtime/handler/pouch_runtime_test.go @@ -0,0 +1,130 @@ +/* +Copyright 2022 The Koordinator Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package handler + +import ( + "context" + "fmt" + "path/filepath" + "testing" + + "github.com/golang/mock/gomock" + "github.com/prashantv/gostub" + "github.com/stretchr/testify/assert" + "google.golang.org/grpc" + + mockv1alpha2_client "github.com/koordinator-sh/koordinator/pkg/koordlet/util/runtime/handler/mockv1alpha2client" + "github.com/koordinator-sh/koordinator/pkg/koordlet/util/system" +) + +func TestNewPouchRuntimeHandler(t *testing.T) { + stubs := gostub.Stub(&GrpcDial, func(context context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { + return &grpc.ClientConn{}, nil + }) + defer stubs.Reset() + + helper := system.NewFileTestUtil(t) + defer helper.Cleanup() + + helper.WriteFileContents("/var/run/pouchcri.sock", "test") + system.Conf.VarRunRootDir = filepath.Join(helper.TempDir, "/var/run") + PouchEndpoint := GetPouchEndpoint() + unixEndPoint := fmt.Sprintf("unix://%s", PouchEndpoint) + pouchRuntime, err := NewPouchRuntimeHandler(unixEndPoint) + assert.NoError(t, err) + assert.NotNil(t, pouchRuntime) + + // custom VarRunRootDir + helper.WriteFileContents("/host-var-run/pouchcri.sock", "test1") + system.Conf.VarRunRootDir = filepath.Join(helper.TempDir, "/host-var-run") + PouchEndpoint = GetPouchEndpoint() + unixEndPoint = fmt.Sprintf("unix://%s", PouchEndpoint) + pouchRuntime, err = NewContainerdRuntimeHandler(unixEndPoint) + assert.NoError(t, err) + assert.NotNil(t, pouchRuntime) +} + +func TestPouchRuntimeHandler_StopContainer(t *testing.T) { + type args struct { + name string + containerId string + runtimeError error + expectError bool + } + tests := []args{ + { + name: "test_stopContainer_success", + containerId: "test_container_id", + runtimeError: nil, + expectError: false, + }, + { + name: "test_stopContainer_fail", + containerId: "test_container_id", + runtimeError: fmt.Errorf("stopContainer error"), + expectError: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctl := gomock.NewController(t) + defer ctl.Finish() + mockRuntimeClient := mockv1alpha2_client.NewMockRuntimeServiceClient(ctl) + mockRuntimeClient.EXPECT().StopContainer(gomock.Any(), gomock.Any()).Return(nil, tt.runtimeError) + + runtimeHandler := PouchRuntimeHandler{runtimeServiceClient: mockRuntimeClient, timeout: 1, endpoint: GetContainerdEndpoint()} + gotErr := runtimeHandler.StopContainer(tt.containerId, 1) + assert.Equal(t, gotErr != nil, tt.expectError) + + }) + } +} + +func TestPouchRuntimeHandler_UpdateContainerResources(t *testing.T) { + type args struct { + name string + containerId string + runtimeError error + expectError bool + } + tests := []args{ + { + name: "test_UpdateContainerResources_success", + containerId: "test_container_id", + runtimeError: nil, + expectError: false, + }, + { + name: "test_UpdateContainerResources_fail", + containerId: "test_container_id", + runtimeError: fmt.Errorf("UpdateContainerResources error"), + expectError: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctl := gomock.NewController(t) + defer ctl.Finish() + mockRuntimeClient := mockv1alpha2_client.NewMockRuntimeServiceClient(ctl) + mockRuntimeClient.EXPECT().UpdateContainerResources(gomock.Any(), gomock.Any()).Return(nil, tt.runtimeError) + + runtimeHandler := PouchRuntimeHandler{runtimeServiceClient: mockRuntimeClient, timeout: 1, endpoint: GetContainerdEndpoint()} + gotErr := runtimeHandler.UpdateContainerResources(tt.containerId, UpdateOptions{}) + assert.Equal(t, tt.expectError, gotErr != nil) + }) + } +} diff --git a/pkg/koordlet/util/runtime/runtime.go b/pkg/koordlet/util/runtime/runtime.go index 63417d882..5db9be180 100644 --- a/pkg/koordlet/util/runtime/runtime.go +++ b/pkg/koordlet/util/runtime/runtime.go @@ -31,6 +31,7 @@ import ( var ( DockerHandler handler.ContainerRuntimeHandler ContainerdHandler handler.ContainerRuntimeHandler + PouchHandler handler.ContainerRuntimeHandler mutex = &sync.Mutex{} ) @@ -39,10 +40,12 @@ func GetRuntimeHandler(runtimeType string) (handler.ContainerRuntimeHandler, err defer mutex.Unlock() switch runtimeType { - case "docker": + case system.RuntimeTypeDocker: return getDockerHandler() - case "containerd": + case system.RuntimeTypeContainerd: return getContainerdHandler() + case system.RuntimeTypePouch: + return getPouchHandler() default: return nil, fmt.Errorf("runtime type %v is not supported", runtimeType) } @@ -116,6 +119,39 @@ func getContainerdEndpoint() (string, error) { return "", fmt.Errorf("containerd endpoint does not exist") } +func getPouchHandler() (handler.ContainerRuntimeHandler, error) { + if PouchHandler != nil { + return PouchHandler, nil + } + + unixEndpoint, err := getPouchEndpoint() + if err != nil { + klog.Errorf("failed to get pouch endpoint, error: %v", err) + return nil, err + } + + PouchHandler, err = handler.NewPouchRuntimeHandler(unixEndpoint) + if err != nil { + klog.Errorf("failed to create pouch runtime handler, error: %v", err) + return nil, err + } + + return PouchHandler, nil +} + +func getPouchEndpoint() (string, error) { + if pouchEndpoint := handler.GetPouchEndpoint(); isFile(pouchEndpoint) { + return fmt.Sprintf("unix://%s", pouchEndpoint), nil + } + + if len(system.Conf.PouchEndpoint) > 0 && isFile(system.Conf.PouchEndpoint) { + klog.Infof("find pouch Endpoint : %v", system.Conf.PouchEndpoint) + return fmt.Sprintf("unix://%s", system.Conf.PouchEndpoint), nil + } + + return "", fmt.Errorf("pouch endpoint does not exist") +} + func isFile(path string) bool { s, err := os.Stat(path) if err != nil || s == nil { diff --git a/pkg/koordlet/util/runtime/runtime_test.go b/pkg/koordlet/util/runtime/runtime_test.go index 4bc0bd414..4e92af885 100644 --- a/pkg/koordlet/util/runtime/runtime_test.go +++ b/pkg/koordlet/util/runtime/runtime_test.go @@ -88,6 +88,13 @@ func Test_GetRuntimeHandler(t *testing.T) { expectRuntimeHandler: "ContainerdRuntimeHandler", expectErr: false, }, + { + name: "test_/var/run/pouchcri.sock", + endPoint: "/var/run/pouchcri.sock", + runtimeType: "pouch", + expectRuntimeHandler: "PouchRuntimeHandler", + expectErr: false, + }, { name: "custom containerd", endPoint: "/var/run/test1/containerd.sock", @@ -104,11 +111,22 @@ func Test_GetRuntimeHandler(t *testing.T) { expectRuntimeHandler: "DockerRuntimeHandler", expectErr: false, }, + { + name: "custom pouch", + endPoint: "/var/run/test3/pouchcri.sock", + flag: "test3/pouchcri.sock", + runtimeType: "pouch", + expectRuntimeHandler: "PouchRuntimeHandler", + expectErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { helper := system.NewFileTestUtil(t) + DockerHandler = nil + ContainerdHandler = nil + PouchHandler = nil system.Conf.VarRunRootDir = filepath.Join(helper.TempDir, "/var/run") if tt.endPoint != "" { helper.CreateFile(tt.endPoint) @@ -119,6 +137,8 @@ func Test_GetRuntimeHandler(t *testing.T) { system.Conf.ContainerdEndPoint = filepath.Join(system.Conf.VarRunRootDir, tt.flag) } else if tt.runtimeType == "docker" { system.Conf.DockerEndPoint = filepath.Join(system.Conf.VarRunRootDir, tt.flag) + } else if tt.runtimeType == "pouch" { + system.Conf.PouchEndpoint = filepath.Join(system.Conf.VarRunRootDir, tt.flag) } } resetEndpoint() @@ -139,7 +159,6 @@ func Test_GetRuntimeHandler(t *testing.T) { assert.True(t, strings.Contains(reflect.TypeOf(gotHandler).String(), tt.expectRuntimeHandler)) // fmt.Printf("handler type: %v ---",reflect.TypeOf(gotHandler).String()) } - }) } } diff --git a/pkg/koordlet/util/system/cgroup_driver.go b/pkg/koordlet/util/system/cgroup_driver.go index a4f84bf1a..c391fdae9 100644 --- a/pkg/koordlet/util/system/cgroup_driver.go +++ b/pkg/koordlet/util/system/cgroup_driver.go @@ -49,6 +49,7 @@ const ( RuntimeTypeDocker = "docker" RuntimeTypeContainerd = "containerd" + RuntimeTypePouch = "pouch" RuntimeTypeUnknown = "unknown" ) @@ -103,6 +104,8 @@ var cgroupPathFormatterInSystemd = Formatter{ return RuntimeTypeDocker, fmt.Sprintf("docker-%s.scope", hashID[1]), nil case RuntimeTypeContainerd: return RuntimeTypeContainerd, fmt.Sprintf("cri-containerd-%s.scope", hashID[1]), nil + case RuntimeTypePouch: + return RuntimeTypePouch, fmt.Sprintf("pouch-%s.scope", hashID[1]), nil default: return RuntimeTypeUnknown, "", fmt.Errorf("unknown container protocol %s", id) } @@ -179,10 +182,8 @@ var cgroupPathFormatterInCgroupfs = Formatter{ if len(hashID) < 2 { return RuntimeTypeUnknown, "", fmt.Errorf("parse container id %s failed", id) } - if hashID[0] == RuntimeTypeDocker { - return RuntimeTypeDocker, fmt.Sprintf("%s", hashID[1]), nil - } else if hashID[0] == RuntimeTypeContainerd { - return RuntimeTypeContainerd, fmt.Sprintf("%s", hashID[1]), nil + if hashID[0] == RuntimeTypeDocker || hashID[0] == RuntimeTypeContainerd || hashID[0] == RuntimeTypePouch { + return hashID[0], fmt.Sprintf("%s", hashID[1]), nil } else { return RuntimeTypeUnknown, "", fmt.Errorf("unknown container protocol %s", id) } diff --git a/pkg/koordlet/util/system/cgroup_driver_test.go b/pkg/koordlet/util/system/cgroup_driver_test.go index 2ae440ee0..a20e21806 100644 --- a/pkg/koordlet/util/system/cgroup_driver_test.go +++ b/pkg/koordlet/util/system/cgroup_driver_test.go @@ -149,3 +149,93 @@ func Test_ParseContainerIDCgroupfs(t *testing.T) { } } } + +func Test_SystemdCgroupPathContainerDirFn(t *testing.T) { + testCases := []struct { + name string + containerID string + wantType string + wantDirName string + wantError bool + }{ + { + name: "docker", + containerID: "docker://testDockerContainerID", + wantType: RuntimeTypeDocker, + wantDirName: "docker-testDockerContainerID.scope", + wantError: false, + }, + { + name: "containerd", + containerID: "containerd://testContainerdContainerID", + wantType: RuntimeTypeContainerd, + wantDirName: "cri-containerd-testContainerdContainerID.scope", + wantError: false, + }, + { + name: "pouch", + containerID: "pouch://testPouchContainerID", + wantType: RuntimeTypePouch, + wantDirName: "pouch-testPouchContainerID.scope", + wantError: false, + }, + { + name: "bad-format", + containerID: "bad-format-id", + wantType: RuntimeTypeUnknown, + wantDirName: "", + wantError: true, + }, + } + for _, tc := range testCases { + runtimeType, dirName, gotErr := cgroupPathFormatterInSystemd.ContainerDirFn(tc.containerID) + assert.Equal(t, tc.wantType, runtimeType) + assert.Equal(t, tc.wantDirName, dirName) + assert.Equal(t, tc.wantError, gotErr != nil) + } +} + +func Test_CgroupfsCgroupPathContainerDirFn(t *testing.T) { + testCases := []struct { + name string + containerID string + wantType string + wantDirName string + wantError bool + }{ + { + name: "docker", + containerID: "docker://testDockerContainerID", + wantType: RuntimeTypeDocker, + wantDirName: "testDockerContainerID", + wantError: false, + }, + { + name: "containerd", + containerID: "containerd://testContainerdContainerID", + wantType: RuntimeTypeContainerd, + wantDirName: "testContainerdContainerID", + wantError: false, + }, + { + name: "pouch", + containerID: "pouch://testPouchContainerID", + wantType: RuntimeTypePouch, + wantDirName: "testPouchContainerID", + wantError: false, + }, + { + name: "bad-format", + containerID: "bad-format-id", + wantType: RuntimeTypeUnknown, + wantDirName: "", + wantError: true, + }, + } + for _, tc := range testCases { + runtimeType, dirName, gotErr := cgroupPathFormatterInCgroupfs.ContainerDirFn(tc.containerID) + assert.Equal(t, tc.wantType, runtimeType) + assert.Equal(t, tc.wantDirName, dirName) + assert.Equal(t, tc.wantError, gotErr != nil) + } +} diff --git a/pkg/koordlet/util/system/config.go b/pkg/koordlet/util/system/config.go index 42dfcc5b0..10f5d0435 100644 --- a/pkg/koordlet/util/system/config.go +++ b/pkg/koordlet/util/system/config.go @@ -44,7 +44,9 @@ type Config struct { RuntimeHooksConfigDir string ContainerdEndPoint string + PouchEndpoint string DockerEndPoint string + DefaultRuntimeType string } func init() { @@ -71,6 +73,7 @@ func NewHostModeConfig() *Config { VarRunRootDir: "/var/run/", RunRootDir: "/run/", RuntimeHooksConfigDir: "/etc/runtime/hookserver.d", + DefaultRuntimeType: "containerd", } } @@ -85,6 +88,7 @@ func NewDsModeConfig() *Config { VarRunRootDir: "/host-var-run/", RunRootDir: "/host-run/", RuntimeHooksConfigDir: "/host-etc-hookserver/", + DefaultRuntimeType: "containerd", } } @@ -103,6 +107,9 @@ func (c *Config) InitFlags(fs *flag.FlagSet) { fs.StringVar(&c.CgroupKubePath, "cgroup-kube-dir", c.CgroupKubePath, "Cgroup kube dir") fs.StringVar(&c.ContainerdEndPoint, "containerd-endpoint", c.ContainerdEndPoint, "containerd endPoint") fs.StringVar(&c.DockerEndPoint, "docker-endpoint", c.DockerEndPoint, "docker endPoint") + fs.StringVar(&c.PouchEndpoint, "pouch-endpoint", c.PouchEndpoint, "pouch endPoint") + + fs.StringVar(&c.DefaultRuntimeType, "default-runtime-type", c.DefaultRuntimeType, "default runtime type during runtime hooks handle request, candidates are containerd/docker/pouch.") initSupportConfigs() } diff --git a/pkg/koordlet/util/system/config_test.go b/pkg/koordlet/util/system/config_test.go index 44f90940c..2d970f22b 100644 --- a/pkg/koordlet/util/system/config_test.go +++ b/pkg/koordlet/util/system/config_test.go @@ -32,6 +32,7 @@ func Test_NewDsModeConfig(t *testing.T) { VarRunRootDir: "/host-var-run/", RunRootDir: "/host-run/", RuntimeHooksConfigDir: "/host-etc-hookserver/", + DefaultRuntimeType: "containerd", } defaultConfig := NewDsModeConfig() assert.Equal(t, expectConfig, defaultConfig) @@ -47,6 +48,7 @@ func Test_NewHostModeConfig(t *testing.T) { VarRunRootDir: "/var/run/", RunRootDir: "/run/", RuntimeHooksConfigDir: "/etc/runtime/hookserver.d", + DefaultRuntimeType: "containerd", } defaultConfig := NewHostModeConfig() assert.Equal(t, expectConfig, defaultConfig)