From 387da59ee57943970a7dd3cee716abdbbecfd273 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Mon, 19 Mar 2018 21:59:32 +0000 Subject: [PATCH] Rename all variables to remove "cricontainerd". Signed-off-by: Lantao Liu --- cli/cli.go | 2 +- cri.go | 2 +- hack/update-proto.sh | 2 +- integration/image_load_test.go | 2 +- integration/test_utils.go | 18 ++++---- integration/volume_copy_up_test.go | 2 +- pkg/api/v1/api.pb.go | 57 ++++++++++++------------ pkg/api/v1/api.proto | 4 +- pkg/client/client.go | 6 +-- pkg/config/config.go | 2 +- pkg/server/container_attach.go | 4 +- pkg/server/container_create.go | 12 ++--- pkg/server/container_create_test.go | 22 ++++----- pkg/server/container_exec.go | 2 +- pkg/server/container_execsync.go | 4 +- pkg/server/container_list.go | 6 +-- pkg/server/container_list_test.go | 4 +- pkg/server/container_log_reopen.go | 2 +- pkg/server/container_remove.go | 2 +- pkg/server/container_start.go | 4 +- pkg/server/container_stats.go | 2 +- pkg/server/container_stats_list.go | 10 ++--- pkg/server/container_status.go | 2 +- pkg/server/container_status_test.go | 2 +- pkg/server/container_stop.go | 6 +-- pkg/server/container_stop_test.go | 2 +- pkg/server/container_update_resources.go | 4 +- pkg/server/helpers.go | 4 +- pkg/server/image_list.go | 2 +- pkg/server/image_list_test.go | 2 +- pkg/server/image_load.go | 2 +- pkg/server/image_pull.go | 6 +-- pkg/server/image_remove.go | 2 +- pkg/server/image_status.go | 4 +- pkg/server/image_status_test.go | 2 +- pkg/server/imagefs_info.go | 2 +- pkg/server/imagefs_info_test.go | 2 +- pkg/server/instrumented_service.go | 4 +- pkg/server/restart.go | 2 +- pkg/server/sandbox_list.go | 6 +-- pkg/server/sandbox_list_test.go | 2 +- pkg/server/sandbox_portforward.go | 4 +- pkg/server/sandbox_remove.go | 2 +- pkg/server/sandbox_run.go | 10 ++--- pkg/server/sandbox_run_test.go | 4 +- pkg/server/sandbox_status.go | 4 +- pkg/server/sandbox_stop.go | 8 ++-- pkg/server/sandbox_stop_test.go | 2 +- pkg/server/service.go | 32 ++++++------- pkg/server/service_test.go | 6 +-- pkg/server/status.go | 2 +- pkg/server/streaming.go | 6 +-- pkg/server/update_runtime_config.go | 2 +- pkg/server/version.go | 2 +- 54 files changed, 156 insertions(+), 157 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 4c8759a84..103b1c229 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -49,7 +49,7 @@ var loadCommand = cli.Command{ timeout = context.GlobalDuration("timeout") cancel gocontext.CancelFunc ) - cl, err := client.NewCRIContainerdClient(address, timeout) + cl, err := client.NewCRIPluginClient(address, timeout) if err != nil { return errors.Wrap(err, "failed to create grpc client") } diff --git a/cri.go b/cri.go index e1dba68ea..57320c32a 100644 --- a/cri.go +++ b/cri.go @@ -92,7 +92,7 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) { return nil, errors.Wrap(err, "failed to create containerd client") } - s, err := server.NewCRIContainerdService(c, client) + s, err := server.NewCRIService(c, client) if err != nil { return nil, errors.Wrap(err, "failed to create CRI service") } diff --git a/hack/update-proto.sh b/hack/update-proto.sh index b330d6195..20a93c7c0 100755 --- a/hack/update-proto.sh +++ b/hack/update-proto.sh @@ -41,6 +41,6 @@ protoc \ # Update boilerplate for the generated file. echo "$(cat hack/boilerplate/boilerplate.go.txt ${API_ROOT}/api.pb.go)" > ${API_ROOT}/api.pb.go -sed -i".bak" "s/Copyright YEAR/Copyright $(date '+%Y')/g" ${API_ROOT}/api.pb.go +sed -i".bak" "s/Copyright YEAR AUTHORS/Copyright $(date '+%Y') The containerd Authors/g" ${API_ROOT}/api.pb.go gofmt -l -s -w ${API_ROOT}/api.pb.go diff --git a/integration/image_load_test.go b/integration/image_load_test.go index 029e2d29e..32b53e5af 100644 --- a/integration/image_load_test.go +++ b/integration/image_load_test.go @@ -58,7 +58,7 @@ func TestImageLoad(t *testing.T) { } t.Logf("load image in cri") - res, err := criContainerdClient.LoadImage(context.Background(), &api.LoadImageRequest{FilePath: tar}) + res, err := criPluginClient.LoadImage(context.Background(), &api.LoadImageRequest{FilePath: tar}) require.NoError(t, err) require.Equal(t, []string{loadedImage}, res.GetImages()) diff --git a/integration/test_utils.go b/integration/test_utils.go index 03e6e8130..66912ea17 100644 --- a/integration/test_utils.go +++ b/integration/test_utils.go @@ -45,14 +45,14 @@ const ( ) var ( - runtimeService cri.RuntimeService - imageService cri.ImageManagerService - containerdClient *containerd.Client - criContainerdClient api.CRIContainerdServiceClient + runtimeService cri.RuntimeService + imageService cri.ImageManagerService + containerdClient *containerd.Client + criPluginClient api.CRIPluginServiceClient ) -var criContainerdEndpoint = flag.String("cri-endpoint", "/run/containerd/containerd.sock", "The endpoint of cri plugin.") -var criContainerdRoot = flag.String("cri-root", "/var/lib/containerd/io.containerd.grpc.v1.cri", "The root directory of cri plugin.") +var criEndpoint = flag.String("cri-endpoint", "/run/containerd/containerd.sock", "The endpoint of cri plugin.") +var criRoot = flag.String("cri-root", "/var/lib/containerd/io.containerd.grpc.v1.cri", "The root directory of cri plugin.") func init() { flag.Parse() @@ -64,11 +64,11 @@ func init() { // ConnectDaemons connect cri plugin and containerd, and initialize the clients. func ConnectDaemons() error { var err error - runtimeService, err = remote.NewRemoteRuntimeService(*criContainerdEndpoint, timeout) + runtimeService, err = remote.NewRemoteRuntimeService(*criEndpoint, timeout) if err != nil { return errors.Wrap(err, "failed to create runtime service") } - imageService, err = remote.NewRemoteImageService(*criContainerdEndpoint, timeout) + imageService, err = remote.NewRemoteImageService(*criEndpoint, timeout) if err != nil { return errors.Wrap(err, "failed to create image service") } @@ -87,7 +87,7 @@ func ConnectDaemons() error { if err != nil { return errors.Wrap(err, "failed to connect containerd") } - criContainerdClient, err = client.NewCRIContainerdClient(*criContainerdEndpoint, timeout) + criPluginClient, err = client.NewCRIPluginClient(*criEndpoint, timeout) if err != nil { return errors.Wrap(err, "failed to connect cri plugin") } diff --git a/integration/volume_copy_up_test.go b/integration/volume_copy_up_test.go index 27bc02cbb..2830bb18a 100644 --- a/integration/volume_copy_up_test.go +++ b/integration/volume_copy_up_test.go @@ -70,7 +70,7 @@ func TestVolumeCopyUp(t *testing.T) { assert.Equal(t, "test_content\n", string(stdout)) t.Logf("Check host path of the volume") - hostCmd := fmt.Sprintf("ls %s/containers/%s/volumes/*/test_file | xargs cat", *criContainerdRoot, cn) + hostCmd := fmt.Sprintf("ls %s/containers/%s/volumes/*/test_file | xargs cat", *criRoot, cn) output, err := exec.Command("sh", "-c", hostCmd).CombinedOutput() require.NoError(t, err) assert.Equal(t, "test_content\n", string(output)) diff --git a/pkg/api/v1/api.pb.go b/pkg/api/v1/api.pb.go index c44c1774c..19fabf3ce 100644 --- a/pkg/api/v1/api.pb.go +++ b/pkg/api/v1/api.pb.go @@ -1,5 +1,5 @@ /* -Copyright 2017 The Kubernetes Authors. +Copyright 2018 The containerd Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ 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 protoc-gen-gogo. // source: api.proto // DO NOT EDIT! @@ -101,66 +100,66 @@ var _ grpc.ClientConn // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 -// Client API for CRIContainerdService service +// Client API for CRIPluginService service -type CRIContainerdServiceClient interface { +type CRIPluginServiceClient interface { // LoadImage loads a image into containerd. LoadImage(ctx context.Context, in *LoadImageRequest, opts ...grpc.CallOption) (*LoadImageResponse, error) } -type cRIContainerdServiceClient struct { +type cRIPluginServiceClient struct { cc *grpc.ClientConn } -func NewCRIContainerdServiceClient(cc *grpc.ClientConn) CRIContainerdServiceClient { - return &cRIContainerdServiceClient{cc} +func NewCRIPluginServiceClient(cc *grpc.ClientConn) CRIPluginServiceClient { + return &cRIPluginServiceClient{cc} } -func (c *cRIContainerdServiceClient) LoadImage(ctx context.Context, in *LoadImageRequest, opts ...grpc.CallOption) (*LoadImageResponse, error) { +func (c *cRIPluginServiceClient) LoadImage(ctx context.Context, in *LoadImageRequest, opts ...grpc.CallOption) (*LoadImageResponse, error) { out := new(LoadImageResponse) - err := grpc.Invoke(ctx, "/api.v1.CRIContainerdService/LoadImage", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/api.v1.CRIPluginService/LoadImage", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } -// Server API for CRIContainerdService service +// Server API for CRIPluginService service -type CRIContainerdServiceServer interface { +type CRIPluginServiceServer interface { // LoadImage loads a image into containerd. LoadImage(context.Context, *LoadImageRequest) (*LoadImageResponse, error) } -func RegisterCRIContainerdServiceServer(s *grpc.Server, srv CRIContainerdServiceServer) { - s.RegisterService(&_CRIContainerdService_serviceDesc, srv) +func RegisterCRIPluginServiceServer(s *grpc.Server, srv CRIPluginServiceServer) { + s.RegisterService(&_CRIPluginService_serviceDesc, srv) } -func _CRIContainerdService_LoadImage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _CRIPluginService_LoadImage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(LoadImageRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CRIContainerdServiceServer).LoadImage(ctx, in) + return srv.(CRIPluginServiceServer).LoadImage(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/api.v1.CRIContainerdService/LoadImage", + FullMethod: "/api.v1.CRIPluginService/LoadImage", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CRIContainerdServiceServer).LoadImage(ctx, req.(*LoadImageRequest)) + return srv.(CRIPluginServiceServer).LoadImage(ctx, req.(*LoadImageRequest)) } return interceptor(ctx, in, info, handler) } -var _CRIContainerdService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "api.v1.CRIContainerdService", - HandlerType: (*CRIContainerdServiceServer)(nil), +var _CRIPluginService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "api.v1.CRIPluginService", + HandlerType: (*CRIPluginServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "LoadImage", - Handler: _CRIContainerdService_LoadImage_Handler, + Handler: _CRIPluginService_LoadImage_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -580,7 +579,7 @@ var ( func init() { proto.RegisterFile("api.proto", fileDescriptorApi) } var fileDescriptorApi = []byte{ - // 223 bytes of a gzipped FileDescriptorProto + // 219 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x03, 0x31, 0xcb, 0x0c, 0xa5, 0x74, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xd3, 0xf3, 0xd3, 0xf3, 0xf5, 0xc1, 0xd2, 0x49, @@ -588,11 +587,11 @@ var fileDescriptorApi = []byte{ 0xa6, 0x78, 0xe6, 0x26, 0xa6, 0xa7, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x49, 0x71, 0x71, 0xb8, 0x65, 0xe6, 0xa4, 0x06, 0x24, 0x96, 0x64, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xf9, 0x4a, 0xda, 0x5c, 0x82, 0x48, 0xea, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xc4, - 0xb8, 0xd8, 0xc0, 0x02, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x50, 0x9e, 0x51, 0x14, - 0x97, 0x88, 0x73, 0x90, 0xa7, 0x73, 0x7e, 0x5e, 0x49, 0x62, 0x66, 0x5e, 0x6a, 0x51, 0x4a, 0x70, - 0x6a, 0x51, 0x59, 0x66, 0x72, 0xaa, 0x90, 0x13, 0x17, 0x27, 0xdc, 0x10, 0x21, 0x09, 0x3d, 0x88, - 0xcb, 0xf5, 0xd0, 0xdd, 0x21, 0x25, 0x89, 0x45, 0x06, 0x62, 0xa3, 0x12, 0x83, 0x93, 0xcc, 0x89, - 0x87, 0x72, 0x8c, 0x37, 0x1e, 0xca, 0x31, 0x34, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, - 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xfb, - 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x6a, 0xfe, 0x35, 0x81, 0x21, 0x01, 0x00, 0x00, + 0xb8, 0xd8, 0xc0, 0x02, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x50, 0x9e, 0x51, 0x18, + 0x97, 0x80, 0x73, 0x90, 0x67, 0x40, 0x4e, 0x69, 0x7a, 0x66, 0x5e, 0x70, 0x6a, 0x51, 0x59, 0x66, + 0x72, 0xaa, 0x90, 0x13, 0x17, 0x27, 0xdc, 0x00, 0x21, 0x09, 0x3d, 0x88, 0xab, 0xf5, 0xd0, 0xdd, + 0x20, 0x25, 0x89, 0x45, 0x06, 0x62, 0x9b, 0x12, 0x83, 0x93, 0xcc, 0x89, 0x87, 0x72, 0x8c, 0x37, + 0x1e, 0xca, 0x31, 0x34, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, + 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xfb, 0xcc, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0xfc, 0x6f, 0xec, 0xf4, 0x1d, 0x01, 0x00, 0x00, } diff --git a/pkg/api/v1/api.proto b/pkg/api/v1/api.proto index f5671abaa..25a3be0ac 100644 --- a/pkg/api/v1/api.proto +++ b/pkg/api/v1/api.proto @@ -13,8 +13,8 @@ option (gogoproto.sizer_all) = true; option (gogoproto.unmarshaler_all) = true; option (gogoproto.goproto_unrecognized_all) = false; -// CRIContainerdService defines non-CRI APIs for cri-containerd. -service CRIContainerdService{ +// CRIPluginService defines non-CRI APIs for cri plugin. +service CRIPluginService{ // LoadImage loads a image into containerd. rpc LoadImage(LoadImageRequest) returns (LoadImageResponse) {} } diff --git a/pkg/client/client.go b/pkg/client/client.go index 344731996..c575bcccf 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -26,9 +26,9 @@ import ( api "github.com/containerd/cri/pkg/api/v1" ) -// NewCRIContainerdClient creates grpc client of cri-containerd +// NewCRIPluginClient creates grpc client of cri plugin // TODO(random-liu): Wrap grpc functions. -func NewCRIContainerdClient(endpoint string, timeout time.Duration) (api.CRIContainerdServiceClient, error) { +func NewCRIPluginClient(endpoint string, timeout time.Duration) (api.CRIPluginServiceClient, error) { addr, dialer, err := util.GetAddressAndDialer(endpoint) if err != nil { return nil, errors.Wrap(err, "failed to get dialer") @@ -43,5 +43,5 @@ func NewCRIContainerdClient(endpoint string, timeout time.Duration) (api.CRICont if err != nil { return nil, errors.Wrap(err, "failed to dial") } - return api.NewCRIContainerdServiceClient(conn), nil + return api.NewCRIPluginServiceClient(conn), nil } diff --git a/pkg/config/config.go b/pkg/config/config.go index fb3071ebe..17e01b175 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -88,7 +88,7 @@ type Config struct { ContainerdRootDir string `json:"containerdRootDir,omitempty"` // ContainerdEndpoint is the containerd endpoint path. ContainerdEndpoint string `json:"containerdEndpoint,omitempty"` - // RootDir is the root directory path for managing cri-containerd files + // RootDir is the root directory path for managing cri plugin files // (metadata checkpoint etc.) RootDir string `json:"rootDir,omitempty"` } diff --git a/pkg/server/container_attach.go b/pkg/server/container_attach.go index 246294d7f..91cdaacc5 100644 --- a/pkg/server/container_attach.go +++ b/pkg/server/container_attach.go @@ -30,7 +30,7 @@ import ( ) // Attach prepares a streaming endpoint to attach to a running container, and returns the address. -func (c *criContainerdService) Attach(ctx context.Context, r *runtime.AttachRequest) (*runtime.AttachResponse, error) { +func (c *criService) Attach(ctx context.Context, r *runtime.AttachRequest) (*runtime.AttachResponse, error) { cntr, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrap(err, "failed to find container in store") @@ -42,7 +42,7 @@ func (c *criContainerdService) Attach(ctx context.Context, r *runtime.AttachRequ return c.streamServer.GetAttach(r) } -func (c *criContainerdService) attachContainer(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser, +func (c *criService) attachContainer(ctx context.Context, id string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { // Get container from our container store. cntr, err := c.containerStore.Get(id) diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index 7b3fbbb3e..b06abb0d5 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -73,7 +73,7 @@ func init() { } // CreateContainer creates a new container in the given PodSandbox. -func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (_ *runtime.CreateContainerResponse, retErr error) { +func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (_ *runtime.CreateContainerResponse, retErr error) { config := r.GetConfig() sandboxConfig := r.GetSandboxConfig() sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId()) @@ -274,7 +274,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C return &runtime.CreateContainerResponse{ContainerId: id}, nil } -func (c *criContainerdService) generateContainerSpec(id string, sandboxID string, sandboxPid uint32, config *runtime.ContainerConfig, +func (c *criService) generateContainerSpec(id string, sandboxID string, sandboxPid uint32, config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, extraMounts []*runtime.Mount) (*runtimespec.Spec, error) { // Creates a spec Generator with the default spec. spec, err := defaultRuntimeSpec(id) @@ -377,7 +377,7 @@ func (c *criContainerdService) generateContainerSpec(id string, sandboxID string // generateVolumeMounts sets up image volumes for container. Rely on the removal of container // root directory to do cleanup. Note that image volume will be skipped, if there is criMounts // specified with the same destination. -func (c *criContainerdService) generateVolumeMounts(containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount { +func (c *criService) generateVolumeMounts(containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount { if len(config.Volumes) == 0 { return nil } @@ -405,7 +405,7 @@ func (c *criContainerdService) generateVolumeMounts(containerRootDir string, cri // generateContainerMounts sets up necessary container mounts including /dev/shm, /etc/hosts // and /etc/resolv.conf. -func (c *criContainerdService) generateContainerMounts(sandboxRootDir string, config *runtime.ContainerConfig) []*runtime.Mount { +func (c *criService) generateContainerMounts(sandboxRootDir string, config *runtime.ContainerConfig) []*runtime.Mount { var mounts []*runtime.Mount securityContext := config.GetLinux().GetSecurityContext() if !isInCRIMounts(etcHosts, config.GetMounts()) { @@ -496,7 +496,7 @@ func clearReadOnly(m *runtimespec.Mount) { } // addDevices set device mapping without privilege. -func (c *criContainerdService) addOCIDevices(g *generate.Generator, devs []*runtime.Device) error { +func (c *criService) addOCIDevices(g *generate.Generator, devs []*runtime.Device) error { spec := g.Spec() for _, device := range devs { path, err := c.os.ResolveSymbolicLink(device.HostPath) @@ -559,7 +559,7 @@ func setOCIDevicesPrivileged(g *generate.Generator) error { } // addOCIBindMounts adds bind mounts. -func (c *criContainerdService) addOCIBindMounts(g *generate.Generator, mounts []*runtime.Mount, mountLabel string) error { +func (c *criService) addOCIBindMounts(g *generate.Generator, mounts []*runtime.Mount, mountLabel string) error { // Mount cgroup into the container as readonly, which inherits docker's behavior. g.AddCgroupsMount("ro") // nolint: errcheck for _, mount := range mounts { diff --git a/pkg/server/container_create_test.go b/pkg/server/container_create_test.go index b02c3219d..73b346fb2 100644 --- a/pkg/server/container_create_test.go +++ b/pkg/server/container_create_test.go @@ -188,7 +188,7 @@ func TestGeneralContainerSpec(t *testing.T) { testID := "test-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() testSandboxID := "sandbox-id" spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil) require.NoError(t, err) @@ -200,7 +200,7 @@ func TestContainerCapabilities(t *testing.T) { testSandboxID := "sandbox-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() for desc, test := range map[string]struct { capability *runtime.Capability includes []string @@ -269,7 +269,7 @@ func TestContainerSpecTty(t *testing.T) { testSandboxID := "sandbox-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() for _, tty := range []bool{true, false} { config.Tty = tty spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil) @@ -289,7 +289,7 @@ func TestContainerSpecReadonlyRootfs(t *testing.T) { testSandboxID := "sandbox-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() for _, readonly := range []bool{true, false} { config.Linux.SecurityContext.ReadonlyRootfs = readonly spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil) @@ -304,7 +304,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) { testSandboxID := "sandbox-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() mountInConfig := &runtime.Mount{ ContainerPath: "test-container-path", HostPath: "test-host-path", @@ -338,7 +338,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) { testSandboxID := "sandbox-id" testPid := uint32(1234) config, sandboxConfig, imageConfig, _ := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() for desc, test := range map[string]struct { containerPrivileged bool sandboxPrivileged bool @@ -477,7 +477,7 @@ func TestGenerateVolumeMounts(t *testing.T) { config := &imagespec.ImageConfig{ Volumes: test.imageVolumes, } - c := newTestCRIContainerdService() + c := newTestCRIService() got := c.generateVolumeMounts(testContainerRootDir, test.criMounts, config) assert.Len(t, got, len(test.expectedMountDest)) for _, dest := range test.expectedMountDest { @@ -596,7 +596,7 @@ func TestGenerateContainerMounts(t *testing.T) { SecurityContext: test.securityContext, }, } - c := newTestCRIContainerdService() + c := newTestCRIService() mounts := c.generateContainerMounts(testSandboxRootDir, config) assert.Equal(t, test.expectedMounts, mounts, desc) } @@ -628,7 +628,7 @@ func TestPrivilegedBindMount(t *testing.T) { t.Logf("TestCase %q", desc) g := generate.New() g.SetRootReadonly(test.readonlyRootFS) - c := newTestCRIContainerdService() + c := newTestCRIService() c.addOCIBindMounts(&g, nil, "") if test.privileged { setOCIBindMountsPrivileged(&g) @@ -736,7 +736,7 @@ func TestMountPropagation(t *testing.T) { } { t.Logf("TestCase %q", desc) g := generate.New() - c := newTestCRIContainerdService() + c := newTestCRIService() c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn err := c.addOCIBindMounts(&g, []*runtime.Mount{test.criMount}, "") if test.expectErr { @@ -753,7 +753,7 @@ func TestPidNamespace(t *testing.T) { testPid := uint32(1234) testSandboxID := "sandbox-id" config, sandboxConfig, imageConfig, _ := getCreateContainerTestData() - c := newTestCRIContainerdService() + c := newTestCRIService() for desc, test := range map[string]struct { pidNS runtime.NamespaceMode expected runtimespec.LinuxNamespace diff --git a/pkg/server/container_exec.go b/pkg/server/container_exec.go index ef65b46a6..c5d89b250 100644 --- a/pkg/server/container_exec.go +++ b/pkg/server/container_exec.go @@ -23,7 +23,7 @@ import ( ) // Exec prepares a streaming endpoint to execute a command in the container, and returns the address. -func (c *criContainerdService) Exec(ctx context.Context, r *runtime.ExecRequest) (*runtime.ExecResponse, error) { +func (c *criService) Exec(ctx context.Context, r *runtime.ExecRequest) (*runtime.ExecResponse, error) { cntr, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrapf(err, "failed to find container %q in store", r.GetContainerId()) diff --git a/pkg/server/container_execsync.go b/pkg/server/container_execsync.go index df887e813..bf4efffd5 100644 --- a/pkg/server/container_execsync.go +++ b/pkg/server/container_execsync.go @@ -39,7 +39,7 @@ import ( // ExecSync executes a command in the container, and returns the stdout output. // If command exits with a non-zero exit code, an error is returned. -func (c *criContainerdService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (*runtime.ExecSyncResponse, error) { +func (c *criService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (*runtime.ExecSyncResponse, error) { var stdout, stderr bytes.Buffer exitCode, err := c.execInContainer(ctx, r.GetContainerId(), execOptions{ cmd: r.GetCmd(), @@ -71,7 +71,7 @@ type execOptions struct { // execInContainer executes a command inside the container synchronously, and // redirects stdio stream properly. -func (c *criContainerdService) execInContainer(ctx context.Context, id string, opts execOptions) (*uint32, error) { +func (c *criService) execInContainer(ctx context.Context, id string, opts execOptions) (*uint32, error) { // Cancel the context before returning to ensure goroutines are stopped. // This is important, because if `Start` returns error, `Wait` will hang // forever unless we cancel the context. diff --git a/pkg/server/container_list.go b/pkg/server/container_list.go index 01bd4fa1a..0adfa6719 100644 --- a/pkg/server/container_list.go +++ b/pkg/server/container_list.go @@ -25,7 +25,7 @@ import ( ) // ListContainers lists all containers matching the filter. -func (c *criContainerdService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (*runtime.ListContainersResponse, error) { +func (c *criService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (*runtime.ListContainersResponse, error) { // List all containers from store. containersInStore := c.containerStore.List() @@ -54,7 +54,7 @@ func toCRIContainer(container containerstore.Container) *runtime.Container { } } -func (c *criContainerdService) normalizeContainerFilter(filter *runtime.ContainerFilter) { +func (c *criService) normalizeContainerFilter(filter *runtime.ContainerFilter) { if cntr, err := c.containerStore.Get(filter.GetId()); err == nil { filter.Id = cntr.ID } @@ -64,7 +64,7 @@ func (c *criContainerdService) normalizeContainerFilter(filter *runtime.Containe } // filterCRIContainers filters CRIContainers. -func (c *criContainerdService) filterCRIContainers(containers []*runtime.Container, filter *runtime.ContainerFilter) []*runtime.Container { +func (c *criService) filterCRIContainers(containers []*runtime.Container, filter *runtime.ContainerFilter) []*runtime.Container { if filter == nil { return containers } diff --git a/pkg/server/container_list_test.go b/pkg/server/container_list_test.go index 5c90cda09..f01374248 100644 --- a/pkg/server/container_list_test.go +++ b/pkg/server/container_list_test.go @@ -77,7 +77,7 @@ func TestToCRIContainer(t *testing.T) { } func TestFilterContainers(t *testing.T) { - c := newTestCRIContainerdService() + c := newTestCRIService() testContainers := []*runtime.Container{ { @@ -168,7 +168,7 @@ func (c containerForTest) toContainer() (containerstore.Container, error) { } func TestListContainers(t *testing.T) { - c := newTestCRIContainerdService() + c := newTestCRIService() sandboxesInStore := []sandboxstore.Sandbox{ sandboxstore.NewSandbox( sandboxstore.Metadata{ diff --git a/pkg/server/container_log_reopen.go b/pkg/server/container_log_reopen.go index f39257641..144cc2cc5 100644 --- a/pkg/server/container_log_reopen.go +++ b/pkg/server/container_log_reopen.go @@ -25,7 +25,7 @@ import ( // ReopenContainerLog asks the cri plugin to reopen the stdout/stderr log file for the container. // This is often called after the log file has been rotated. -func (c *criContainerdService) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (*runtime.ReopenContainerLogResponse, error) { +func (c *criService) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (*runtime.ReopenContainerLogResponse, error) { container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId()) diff --git a/pkg/server/container_remove.go b/pkg/server/container_remove.go index 39092f41e..83fec6522 100644 --- a/pkg/server/container_remove.go +++ b/pkg/server/container_remove.go @@ -32,7 +32,7 @@ import ( // RemoveContainer removes the container. // TODO(random-liu): Forcibly stop container if it's running. -func (c *criContainerdService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (_ *runtime.RemoveContainerResponse, retErr error) { +func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (_ *runtime.RemoveContainerResponse, retErr error) { container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { if err != store.ErrNotExist { diff --git a/pkg/server/container_start.go b/pkg/server/container_start.go index cd1e3909d..26e3d216d 100644 --- a/pkg/server/container_start.go +++ b/pkg/server/container_start.go @@ -35,7 +35,7 @@ import ( ) // StartContainer starts the container. -func (c *criContainerdService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (retRes *runtime.StartContainerResponse, retErr error) { +func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (retRes *runtime.StartContainerResponse, retErr error) { container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId()) @@ -58,7 +58,7 @@ func (c *criContainerdService) StartContainer(ctx context.Context, r *runtime.St // startContainer actually starts the container. The function needs to be run in one transaction. Any updates // to the status passed in will be applied no matter the function returns error or not. -func (c *criContainerdService) startContainer(ctx context.Context, +func (c *criService) startContainer(ctx context.Context, cntr containerstore.Container, status *containerstore.Status) (retErr error) { id := cntr.ID diff --git a/pkg/server/container_stats.go b/pkg/server/container_stats.go index 176fe2f51..77b77227c 100644 --- a/pkg/server/container_stats.go +++ b/pkg/server/container_stats.go @@ -25,7 +25,7 @@ import ( // ContainerStats returns stats of the container. If the container does not // exist, the call returns an error. -func (c *criContainerdService) ContainerStats(ctx context.Context, in *runtime.ContainerStatsRequest) (*runtime.ContainerStatsResponse, error) { +func (c *criService) ContainerStats(ctx context.Context, in *runtime.ContainerStatsRequest) (*runtime.ContainerStatsResponse, error) { cntr, err := c.containerStore.Get(in.GetContainerId()) if err != nil { return nil, errors.Wrap(err, "failed to find container") diff --git a/pkg/server/container_stats_list.go b/pkg/server/container_stats_list.go index b69817deb..3b4d8c93d 100644 --- a/pkg/server/container_stats_list.go +++ b/pkg/server/container_stats_list.go @@ -29,7 +29,7 @@ import ( ) // ListContainerStats returns stats of all running containers. -func (c *criContainerdService) ListContainerStats( +func (c *criService) ListContainerStats( ctx context.Context, in *runtime.ListContainerStatsRequest, ) (*runtime.ListContainerStatsResponse, error) { @@ -48,7 +48,7 @@ func (c *criContainerdService) ListContainerStats( return criStats, nil } -func (c *criContainerdService) toCRIContainerStats( +func (c *criService) toCRIContainerStats( stats []*types.Metric, containers []containerstore.Container, ) (*runtime.ListContainerStatsResponse, error) { @@ -67,7 +67,7 @@ func (c *criContainerdService) toCRIContainerStats( return containerStats, nil } -func (c *criContainerdService) getContainerMetrics( +func (c *criService) getContainerMetrics( meta containerstore.Metadata, stats *types.Metric, ) (*runtime.ContainerStats, error) { @@ -118,7 +118,7 @@ func (c *criContainerdService) getContainerMetrics( return &cs, nil } -func (c *criContainerdService) normalizeContainerStatsFilter(filter *runtime.ContainerStatsFilter) { +func (c *criService) normalizeContainerStatsFilter(filter *runtime.ContainerStatsFilter) { if cntr, err := c.containerStore.Get(filter.GetId()); err == nil { filter.Id = cntr.ID } @@ -129,7 +129,7 @@ func (c *criContainerdService) normalizeContainerStatsFilter(filter *runtime.Con // buildTaskMetricsRequest constructs a tasks.MetricsRequest based on // the information in the stats request and the containerStore -func (c *criContainerdService) buildTaskMetricsRequest( +func (c *criService) buildTaskMetricsRequest( r *runtime.ListContainerStatsRequest, ) (tasks.MetricsRequest, []containerstore.Container, error) { var req tasks.MetricsRequest diff --git a/pkg/server/container_status.go b/pkg/server/container_status.go index 18e4a3b3f..20507e42d 100644 --- a/pkg/server/container_status.go +++ b/pkg/server/container_status.go @@ -29,7 +29,7 @@ import ( ) // ContainerStatus inspects the container and returns the status. -func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (*runtime.ContainerStatusResponse, error) { +func (c *criService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (*runtime.ContainerStatusResponse, error) { container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId()) diff --git a/pkg/server/container_status_test.go b/pkg/server/container_status_test.go index eb25eb5d4..78f8d2d54 100644 --- a/pkg/server/container_status_test.go +++ b/pkg/server/container_status_test.go @@ -193,7 +193,7 @@ func TestContainerStatus(t *testing.T) { }, } { t.Logf("TestCase %q", desc) - c := newTestCRIContainerdService() + c := newTestCRIService() metadata, status, image, expected := getContainerStatusTestData() // Update status with test case. status.FinishedAt = test.finishedAt diff --git a/pkg/server/container_stop.go b/pkg/server/container_stop.go index fa8db2756..b8f980a42 100644 --- a/pkg/server/container_stop.go +++ b/pkg/server/container_stop.go @@ -36,7 +36,7 @@ import ( const killContainerTimeout = 2 * time.Minute // StopContainer stops a running container with a grace period (i.e., timeout). -func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (*runtime.StopContainerResponse, error) { +func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (*runtime.StopContainerResponse, error) { // Get container config from container store. container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { @@ -51,7 +51,7 @@ func (c *criContainerdService) StopContainer(ctx context.Context, r *runtime.Sto } // stopContainer stops a container based on the container metadata. -func (c *criContainerdService) stopContainer(ctx context.Context, container containerstore.Container, timeout time.Duration) error { +func (c *criService) stopContainer(ctx context.Context, container containerstore.Container, timeout time.Duration) error { id := container.ID // Return without error if container is not running. This makes sure that @@ -130,7 +130,7 @@ func (c *criContainerdService) stopContainer(ctx context.Context, container cont } // waitContainerStop waits for container to be stopped until timeout exceeds or context is cancelled. -func (c *criContainerdService) waitContainerStop(ctx context.Context, container containerstore.Container, timeout time.Duration) error { +func (c *criService) waitContainerStop(ctx context.Context, container containerstore.Container, timeout time.Duration) error { timeoutTimer := time.NewTimer(timeout) defer timeoutTimer.Stop() select { diff --git a/pkg/server/container_stop_test.go b/pkg/server/container_stop_test.go index 399f477f2..9da58a0c4 100644 --- a/pkg/server/container_stop_test.go +++ b/pkg/server/container_stop_test.go @@ -61,7 +61,7 @@ func TestWaitContainerStop(t *testing.T) { expectErr: false, }, } { - c := newTestCRIContainerdService() + c := newTestCRIService() container, err := containerstore.NewContainer( containerstore.Metadata{ID: id}, containerstore.WithFakeStatus(*test.status), diff --git a/pkg/server/container_update_resources.go b/pkg/server/container_update_resources.go index 88cbd53cf..632570592 100644 --- a/pkg/server/container_update_resources.go +++ b/pkg/server/container_update_resources.go @@ -35,7 +35,7 @@ import ( ) // UpdateContainerResources updates ContainerConfig of the container. -func (c *criContainerdService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (retRes *runtime.UpdateContainerResourcesResponse, retErr error) { +func (c *criService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (retRes *runtime.UpdateContainerResourcesResponse, retErr error) { container, err := c.containerStore.Get(r.GetContainerId()) if err != nil { return nil, errors.Wrap(err, "failed to find container") @@ -51,7 +51,7 @@ func (c *criContainerdService) UpdateContainerResources(ctx context.Context, r * return &runtime.UpdateContainerResourcesResponse{}, nil } -func (c *criContainerdService) updateContainerResources(ctx context.Context, +func (c *criService) updateContainerResources(ctx context.Context, cntr containerstore.Container, resources *runtime.LinuxContainerResources, status containerstore.Status) (retErr error) { diff --git a/pkg/server/helpers.go b/pkg/server/helpers.go index b81fccb25..8a19c0407 100644 --- a/pkg/server/helpers.go +++ b/pkg/server/helpers.go @@ -219,7 +219,7 @@ func getRepoDigestAndTag(namedRef reference.Named, digest imagedigest.Digest, sc // localResolve resolves image reference locally and returns corresponding image metadata. It returns // nil without error if the reference doesn't exist. -func (c *criContainerdService) localResolve(ctx context.Context, refOrID string) (*imagestore.Image, error) { +func (c *criService) localResolve(ctx context.Context, refOrID string) (*imagestore.Image, error) { getImageID := func(refOrId string) string { if _, err := imagedigest.Parse(refOrID); err == nil { return refOrID @@ -278,7 +278,7 @@ func getUserFromImage(user string) (*int64, string) { // ensureImageExists returns corresponding metadata of the image reference, if image is not // pulled yet, the function will pull the image. -func (c *criContainerdService) ensureImageExists(ctx context.Context, ref string) (*imagestore.Image, error) { +func (c *criService) ensureImageExists(ctx context.Context, ref string) (*imagestore.Image, error) { image, err := c.localResolve(ctx, ref) if err != nil { return nil, errors.Wrapf(err, "failed to resolve image %q", ref) diff --git a/pkg/server/image_list.go b/pkg/server/image_list.go index e770bfe28..28abbecaa 100644 --- a/pkg/server/image_list.go +++ b/pkg/server/image_list.go @@ -26,7 +26,7 @@ import ( // ListImages lists existing images. // TODO(random-liu): Add image list filters after CRI defines this more clear, and kubelet // actually needs it. -func (c *criContainerdService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (*runtime.ListImagesResponse, error) { +func (c *criService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (*runtime.ListImagesResponse, error) { imagesInStore := c.imageStore.List() var images []*runtime.Image diff --git a/pkg/server/image_list_test.go b/pkg/server/image_list_test.go index c51b88705..f690eb286 100644 --- a/pkg/server/image_list_test.go +++ b/pkg/server/image_list_test.go @@ -29,7 +29,7 @@ import ( ) func TestListImages(t *testing.T) { - c := newTestCRIContainerdService() + c := newTestCRIService() imagesInStore := []imagestore.Image{ { ID: "sha256:1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", diff --git a/pkg/server/image_load.go b/pkg/server/image_load.go index 036595398..2bd430716 100644 --- a/pkg/server/image_load.go +++ b/pkg/server/image_load.go @@ -30,7 +30,7 @@ import ( ) // LoadImage loads a image into containerd. -func (c *criContainerdService) LoadImage(ctx context.Context, r *api.LoadImageRequest) (*api.LoadImageResponse, error) { +func (c *criService) LoadImage(ctx context.Context, r *api.LoadImageRequest) (*api.LoadImageResponse, error) { path := r.GetFilePath() if !filepath.IsAbs(path) { return nil, errors.Errorf("path %q is not an absolute path", path) diff --git a/pkg/server/image_pull.go b/pkg/server/image_pull.go index bd6c2ca3a..aea3db8c9 100644 --- a/pkg/server/image_pull.go +++ b/pkg/server/image_pull.go @@ -77,7 +77,7 @@ import ( // contents are missing but snapshots are ready, is the image still "READY"? // PullImage pulls an image with authentication config. -func (c *criContainerdService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (*runtime.PullImageResponse, error) { +func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (*runtime.PullImageResponse, error) { imageRef := r.GetImage().GetImage() namedRef, err := util.NormalizeImageRef(imageRef) if err != nil { @@ -194,7 +194,7 @@ func ParseAuth(auth *runtime.AuthConfig) (string, string, error) { // Note that because create and update are not finished in one transaction, there could be race. E.g. // the image reference is deleted by someone else after create returns already exists, but before update // happens. -func (c *criContainerdService) createImageReference(ctx context.Context, name string, desc imagespec.Descriptor) error { +func (c *criService) createImageReference(ctx context.Context, name string, desc imagespec.Descriptor) error { img := containerdimages.Image{ Name: name, Target: desc, @@ -212,7 +212,7 @@ func (c *criContainerdService) createImageReference(ctx context.Context, name st return err } -func (c *criContainerdService) getResolverOptions() map[string][]string { +func (c *criService) getResolverOptions() map[string][]string { options := make(map[string][]string) for ns, mirror := range c.config.Mirrors { options[ns] = append(options[ns], mirror.Endpoints...) diff --git a/pkg/server/image_remove.go b/pkg/server/image_remove.go index 759ac0150..c27695bc4 100644 --- a/pkg/server/image_remove.go +++ b/pkg/server/image_remove.go @@ -31,7 +31,7 @@ import ( // TODO(random-liu): We should change CRI to distinguish image id and image spec. // Remove the whole image no matter the it's image id or reference. This is the // semantic defined in CRI now. -func (c *criContainerdService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) { +func (c *criService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (*runtime.RemoveImageResponse, error) { image, err := c.localResolve(ctx, r.GetImage().GetImage()) if err != nil { return nil, errors.Wrapf(err, "can not resolve %q locally", r.GetImage().GetImage()) diff --git a/pkg/server/image_status.go b/pkg/server/image_status.go index 35525830a..b3b39ed90 100644 --- a/pkg/server/image_status.go +++ b/pkg/server/image_status.go @@ -31,7 +31,7 @@ import ( // ImageStatus returns the status of the image, returns nil if the image isn't present. // TODO(random-liu): We should change CRI to distinguish image id and image spec. (See // kubernetes/kubernetes#46255) -func (c *criContainerdService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (*runtime.ImageStatusResponse, error) { +func (c *criService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (*runtime.ImageStatusResponse, error) { image, err := c.localResolve(ctx, r.GetImage().GetImage()) if err != nil { return nil, errors.Wrapf(err, "can not resolve %q locally", r.GetImage().GetImage()) @@ -79,7 +79,7 @@ type verboseImageInfo struct { } // toCRIImageInfo converts internal image object information to CRI image status response info map. -func (c *criContainerdService) toCRIImageInfo(ctx context.Context, image *imagestore.Image, verbose bool) (map[string]string, error) { +func (c *criService) toCRIImageInfo(ctx context.Context, image *imagestore.Image, verbose bool) (map[string]string, error) { if !verbose { return nil, nil } diff --git a/pkg/server/image_status_test.go b/pkg/server/image_status_test.go index 30931d9bb..3be5ff1e9 100644 --- a/pkg/server/image_status_test.go +++ b/pkg/server/image_status_test.go @@ -50,7 +50,7 @@ func TestImageStatus(t *testing.T) { Username: "user", } - c := newTestCRIContainerdService() + c := newTestCRIService() t.Logf("should return nil image spec without error for non-exist image") resp, err := c.ImageStatus(context.Background(), &runtime.ImageStatusRequest{ Image: &runtime.ImageSpec{Image: testID}, diff --git a/pkg/server/imagefs_info.go b/pkg/server/imagefs_info.go index d55f2e1a3..55b3d260b 100644 --- a/pkg/server/imagefs_info.go +++ b/pkg/server/imagefs_info.go @@ -25,7 +25,7 @@ import ( ) // ImageFsInfo returns information of the filesystem that is used to store images. -func (c *criContainerdService) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (*runtime.ImageFsInfoResponse, error) { +func (c *criService) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (*runtime.ImageFsInfoResponse, error) { snapshots := c.snapshotStore.List() timestamp := time.Now().UnixNano() var usedBytes, inodesUsed uint64 diff --git a/pkg/server/imagefs_info_test.go b/pkg/server/imagefs_info_test.go index 2cdc529ba..51cd9f7e7 100644 --- a/pkg/server/imagefs_info_test.go +++ b/pkg/server/imagefs_info_test.go @@ -29,7 +29,7 @@ import ( ) func TestImageFsInfo(t *testing.T) { - c := newTestCRIContainerdService() + c := newTestCRIService() snapshots := []snapshotstore.Snapshot{ { Key: "key1", diff --git a/pkg/server/instrumented_service.go b/pkg/server/instrumented_service.go index f3adc6433..43fb6eaa9 100644 --- a/pkg/server/instrumented_service.go +++ b/pkg/server/instrumented_service.go @@ -30,10 +30,10 @@ import ( // instrumentedService wraps service with containerd namespace and logs. type instrumentedService struct { - c *criContainerdService + c *criService } -func newInstrumentedService(c *criContainerdService) grpcServices { +func newInstrumentedService(c *criService) grpcServices { return &instrumentedService{c: c} } diff --git a/pkg/server/restart.go b/pkg/server/restart.go index f1394d0e5..9912a5854 100644 --- a/pkg/server/restart.go +++ b/pkg/server/restart.go @@ -51,7 +51,7 @@ import ( // tolerant tasks being created or started, we prefer that not to happen. // recover recovers system state from containerd and status checkpoint. -func (c *criContainerdService) recover(ctx context.Context) error { +func (c *criService) recover(ctx context.Context) error { // Recover all sandboxes. sandboxes, err := c.client.Containers(ctx, filterLabel(containerKindLabel, containerKindSandbox)) if err != nil { diff --git a/pkg/server/sandbox_list.go b/pkg/server/sandbox_list.go index f81888840..3a0879715 100644 --- a/pkg/server/sandbox_list.go +++ b/pkg/server/sandbox_list.go @@ -24,7 +24,7 @@ import ( ) // ListPodSandbox returns a list of Sandbox. -func (c *criContainerdService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (*runtime.ListPodSandboxResponse, error) { +func (c *criService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (*runtime.ListPodSandboxResponse, error) { // List all sandboxes from store. sandboxesInStore := c.sandboxStore.List() var sandboxes []*runtime.PodSandbox @@ -56,14 +56,14 @@ func toCRISandbox(meta sandboxstore.Metadata, status sandboxstore.Status) *runti } } -func (c *criContainerdService) normalizePodSandboxFilter(filter *runtime.PodSandboxFilter) { +func (c *criService) normalizePodSandboxFilter(filter *runtime.PodSandboxFilter) { if sb, err := c.sandboxStore.Get(filter.GetId()); err == nil { filter.Id = sb.ID } } // filterCRISandboxes filters CRISandboxes. -func (c *criContainerdService) filterCRISandboxes(sandboxes []*runtime.PodSandbox, filter *runtime.PodSandboxFilter) []*runtime.PodSandbox { +func (c *criService) filterCRISandboxes(sandboxes []*runtime.PodSandbox, filter *runtime.PodSandboxFilter) []*runtime.PodSandbox { if filter == nil { return sandboxes } diff --git a/pkg/server/sandbox_list_test.go b/pkg/server/sandbox_list_test.go index b6d0dd984..ff0126129 100644 --- a/pkg/server/sandbox_list_test.go +++ b/pkg/server/sandbox_list_test.go @@ -75,7 +75,7 @@ func TestToCRISandbox(t *testing.T) { } func TestFilterSandboxes(t *testing.T) { - c := newTestCRIContainerdService() + c := newTestCRIService() sandboxes := []sandboxstore.Sandbox{ sandboxstore.NewSandbox( sandboxstore.Metadata{ diff --git a/pkg/server/sandbox_portforward.go b/pkg/server/sandbox_portforward.go index 790dc345a..f8d9146a7 100644 --- a/pkg/server/sandbox_portforward.go +++ b/pkg/server/sandbox_portforward.go @@ -33,7 +33,7 @@ import ( ) // PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address. -func (c *criContainerdService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (retRes *runtime.PortForwardResponse, retErr error) { +func (c *criService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (retRes *runtime.PortForwardResponse, retErr error) { // TODO(random-liu): Run a socat container inside the sandbox to do portforward. sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId()) if err != nil { @@ -49,7 +49,7 @@ func (c *criContainerdService) PortForward(ctx context.Context, r *runtime.PortF // portForward requires `nsenter` and `socat` on the node, it uses `nsenter` to enter the // sandbox namespace, and run `socat` inside the namespace to forward stream for a specific // port. The `socat` command keeps running until it exits or client disconnect. -func (c *criContainerdService) portForward(id string, port int32, stream io.ReadWriteCloser) error { +func (c *criService) portForward(id string, port int32, stream io.ReadWriteCloser) error { s, err := c.sandboxStore.Get(id) if err != nil { return errors.Wrapf(err, "failed to find sandbox %q in store", id) diff --git a/pkg/server/sandbox_remove.go b/pkg/server/sandbox_remove.go index 343605115..4f8e0a858 100644 --- a/pkg/server/sandbox_remove.go +++ b/pkg/server/sandbox_remove.go @@ -31,7 +31,7 @@ import ( // RemovePodSandbox removes the sandbox. If there are running containers in the // sandbox, they should be forcibly removed. -func (c *criContainerdService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (*runtime.RemovePodSandboxResponse, error) { +func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (*runtime.RemovePodSandboxResponse, error) { sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId()) if err != nil { if err != store.ErrNotExist { diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 9daaa7be0..bb61830f7 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -51,7 +51,7 @@ func init() { // RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure // the sandbox is in ready state. -func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (_ *runtime.RunPodSandboxResponse, retErr error) { +func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (_ *runtime.RunPodSandboxResponse, retErr error) { config := r.GetConfig() // Generate unique id and name for the sandbox and reserve the name. @@ -296,7 +296,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run return &runtime.RunPodSandboxResponse{PodSandboxId: id}, nil } -func (c *criContainerdService) generateSandboxContainerSpec(id string, config *runtime.PodSandboxConfig, +func (c *criService) generateSandboxContainerSpec(id string, config *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, nsPath string) (*runtimespec.Spec, error) { // Creates a spec Generator with the default spec. // TODO(random-liu): [P1] Compare the default settings with docker and containerd default. @@ -391,7 +391,7 @@ func (c *criContainerdService) generateSandboxContainerSpec(id string, config *r // setupSandboxFiles sets up necessary sandbox files including /dev/shm, /etc/hosts // and /etc/resolv.conf. -func (c *criContainerdService) setupSandboxFiles(rootDir string, config *runtime.PodSandboxConfig) error { +func (c *criService) setupSandboxFiles(rootDir string, config *runtime.PodSandboxConfig) error { // TODO(random-liu): Consider whether we should maintain /etc/hosts and /etc/resolv.conf in kubelet. sandboxEtcHosts := getSandboxHosts(rootDir) if err := c.os.CopyFile(etcHosts, sandboxEtcHosts, 0644); err != nil { @@ -468,7 +468,7 @@ func parseDNSOptions(servers, searches, options []string) (string, error) { // remove these files. Unmount should *NOT* return error when: // 1) The mount point is already unmounted. // 2) The mount point doesn't exist. -func (c *criContainerdService) unmountSandboxFiles(rootDir string, config *runtime.PodSandboxConfig) error { +func (c *criService) unmountSandboxFiles(rootDir string, config *runtime.PodSandboxConfig) error { if config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetIpc() != runtime.NamespaceMode_NODE { if err := c.os.Unmount(getSandboxDevShm(rootDir), unix.MNT_DETACH); err != nil && !os.IsNotExist(err) { return err @@ -478,7 +478,7 @@ func (c *criContainerdService) unmountSandboxFiles(rootDir string, config *runti } // setupPod setups up the network for a pod -func (c *criContainerdService) setupPod(id string, path string, config *runtime.PodSandboxConfig) (string, error) { +func (c *criService) setupPod(id string, path string, config *runtime.PodSandboxConfig) (string, error) { if c.netPlugin == nil { return "", errors.New("cni config not intialized") } diff --git a/pkg/server/sandbox_run_test.go b/pkg/server/sandbox_run_test.go index 3e55f24b7..18aea395e 100644 --- a/pkg/server/sandbox_run_test.go +++ b/pkg/server/sandbox_run_test.go @@ -152,7 +152,7 @@ func TestGenerateSandboxContainerSpec(t *testing.T) { }, } { t.Logf("TestCase %q", desc) - c := newTestCRIContainerdService() + c := newTestCRIService() config, imageConfig, specCheck := getRunPodSandboxTestData() if test.configChange != nil { test.configChange(config) @@ -261,7 +261,7 @@ options timeout:1 }, } { t.Logf("TestCase %q", desc) - c := newTestCRIContainerdService() + c := newTestCRIService() cfg := &runtime.PodSandboxConfig{ DnsConfig: test.dnsConfig, Linux: &runtime.LinuxPodSandboxConfig{ diff --git a/pkg/server/sandbox_status.go b/pkg/server/sandbox_status.go index 090f038e4..75bc98056 100644 --- a/pkg/server/sandbox_status.go +++ b/pkg/server/sandbox_status.go @@ -30,7 +30,7 @@ import ( ) // PodSandboxStatus returns the status of the PodSandbox. -func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (*runtime.PodSandboxStatusResponse, error) { +func (c *criService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (*runtime.PodSandboxStatusResponse, error) { sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId()) if err != nil { return nil, errors.Wrap(err, "an error occurred when try to find sandbox") @@ -54,7 +54,7 @@ func (c *criContainerdService) PodSandboxStatus(ctx context.Context, r *runtime. }, nil } -func (c *criContainerdService) getIP(sandbox sandboxstore.Sandbox) string { +func (c *criService) getIP(sandbox sandboxstore.Sandbox) string { config := sandbox.Config if config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE { diff --git a/pkg/server/sandbox_stop.go b/pkg/server/sandbox_stop.go index 495618218..ce9dca26b 100644 --- a/pkg/server/sandbox_stop.go +++ b/pkg/server/sandbox_stop.go @@ -33,7 +33,7 @@ import ( // StopPodSandbox stops the sandbox. If there are any running containers in the // sandbox, they should be forcibly terminated. -func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) { +func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) { sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId()) if err != nil { return nil, errors.Wrapf(err, "an error occurred when try to find sandbox %q", @@ -96,7 +96,7 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St } // stopSandboxContainer kills and deletes sandbox container. -func (c *criContainerdService) stopSandboxContainer(ctx context.Context, sandbox sandboxstore.Sandbox) error { +func (c *criService) stopSandboxContainer(ctx context.Context, sandbox sandboxstore.Sandbox) error { container := sandbox.Container task, err := container.Task(ctx, nil) if err != nil { @@ -116,7 +116,7 @@ func (c *criContainerdService) stopSandboxContainer(ctx context.Context, sandbox } // waitSandboxStop waits for sandbox to be stopped until timeout exceeds or context is cancelled. -func (c *criContainerdService) waitSandboxStop(ctx context.Context, sandbox sandboxstore.Sandbox, timeout time.Duration) error { +func (c *criService) waitSandboxStop(ctx context.Context, sandbox sandboxstore.Sandbox, timeout time.Duration) error { timeoutTimer := time.NewTimer(timeout) defer timeoutTimer.Stop() select { @@ -130,7 +130,7 @@ func (c *criContainerdService) waitSandboxStop(ctx context.Context, sandbox sand } // teardownPod removes the network from the pod -func (c *criContainerdService) teardownPod(id string, path string, config *runtime.PodSandboxConfig) error { +func (c *criService) teardownPod(id string, path string, config *runtime.PodSandboxConfig) error { if c.netPlugin == nil { return errors.New("cni config not intialized") } diff --git a/pkg/server/sandbox_stop_test.go b/pkg/server/sandbox_stop_test.go index a52c1d642..93a4f29a8 100644 --- a/pkg/server/sandbox_stop_test.go +++ b/pkg/server/sandbox_stop_test.go @@ -51,7 +51,7 @@ func TestWaitSandboxStop(t *testing.T) { expectErr: false, }, } { - c := newTestCRIContainerdService() + c := newTestCRIService() sandbox := sandboxstore.NewSandbox( sandboxstore.Metadata{ID: id}, sandboxstore.Status{State: test.state}, diff --git a/pkg/server/service.go b/pkg/server/service.go index a12dcb697..7fdeb61de 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -50,11 +50,11 @@ import ( type grpcServices interface { runtime.RuntimeServiceServer runtime.ImageServiceServer - api.CRIContainerdServiceServer + api.CRIPluginServiceServer } -// CRIContainerdService is the interface implement CRI remote service server. -type CRIContainerdService interface { +// CRIService is the interface implement CRI remote service server. +type CRIService interface { Run() error // io.Closer is used by containerd to gracefully stop cri service. io.Closer @@ -62,8 +62,8 @@ type CRIContainerdService interface { grpcServices } -// criContainerdService implements CRIContainerdService. -type criContainerdService struct { +// criService implements CRIService. +type criService struct { // config contains all configurations. config criconfig.Config // imageFSPath is the path to image filesystem. @@ -101,10 +101,10 @@ type criContainerdService struct { initialized atomic.Bool } -// NewCRIContainerdService returns a new instance of CRIContainerdService -func NewCRIContainerdService(config criconfig.Config, client *containerd.Client) (CRIContainerdService, error) { +// NewCRIService returns a new instance of CRIService +func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIService, error) { var err error - c := &criContainerdService{ + c := &criService{ config: config, client: client, apparmorEnabled: runcapparmor.IsEnabled(), @@ -159,16 +159,16 @@ func NewCRIContainerdService(config criconfig.Config, client *containerd.Client) // Register registers all required services onto a specific grpc server. // This is used by containerd cri plugin. -func (c *criContainerdService) Register(s *grpc.Server) error { +func (c *criService) Register(s *grpc.Server) error { instrumented := newInstrumentedService(c) runtime.RegisterRuntimeServiceServer(s, instrumented) runtime.RegisterImageServiceServer(s, instrumented) - api.RegisterCRIContainerdServiceServer(s, instrumented) + api.RegisterCRIPluginServiceServer(s, instrumented) return nil } -// Run starts the cri-containerd service. -func (c *criContainerdService) Run() error { +// Run starts the CRI service. +func (c *criService) Run() error { logrus.Info("Start subscribing containerd event") c.eventMonitor.subscribe(c.client) @@ -206,7 +206,7 @@ func (c *criContainerdService) Run() error { // Set the server as initialized. GRPC services could start serving traffic. c.initialized.Set() - // Stop the whole cri-containerd service if any of the critical service exits. + // Stop the whole CRI service if any of the critical service exits. select { case <-eventMonitorCloseCh: case <-streamServerCloseCh: @@ -235,9 +235,9 @@ func (c *criContainerdService) Run() error { return nil } -// Stop stops the cri-containerd service. -func (c *criContainerdService) Close() error { - logrus.Info("Stop cri-containerd service") +// Stop stops the CRI service. +func (c *criService) Close() error { + logrus.Info("Stop CRI service") // TODO(random-liu): Make event monitor stop synchronous. c.eventMonitor.stop() if err := c.streamServer.Stop(); err != nil { diff --git a/pkg/server/service_test.go b/pkg/server/service_test.go index 9d4d8f624..eb0d79eed 100644 --- a/pkg/server/service_test.go +++ b/pkg/server/service_test.go @@ -36,9 +36,9 @@ const ( testImageFSPath = "/test/image/fs/path" ) -// newTestCRIContainerdService creates a fake criContainerdService for test. -func newTestCRIContainerdService() *criContainerdService { - return &criContainerdService{ +// newTestCRIService creates a fake criService for test. +func newTestCRIService() *criService { + return &criService{ config: criconfig.Config{ RootDir: testRootDir, PluginConfig: criconfig.PluginConfig{ diff --git a/pkg/server/status.go b/pkg/server/status.go index b813e34a0..059036239 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -30,7 +30,7 @@ import ( const networkNotReadyReason = "NetworkPluginNotReady" // Status returns the status of the runtime. -func (c *criContainerdService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) { +func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) { // As a containerd plugin, if CRI plugin is serving request, // containerd must be ready. runtimeCondition := &runtime.RuntimeCondition{ diff --git a/pkg/server/streaming.go b/pkg/server/streaming.go index 5db17d388..78787e0cd 100644 --- a/pkg/server/streaming.go +++ b/pkg/server/streaming.go @@ -31,7 +31,7 @@ import ( ctrdutil "github.com/containerd/cri/pkg/containerd/util" ) -func newStreamServer(c *criContainerdService, addr, port string) (streaming.Server, error) { +func newStreamServer(c *criService, addr, port string) (streaming.Server, error) { if addr == "" { a, err := k8snet.ChooseBindAddress(nil) if err != nil { @@ -46,10 +46,10 @@ func newStreamServer(c *criContainerdService, addr, port string) (streaming.Serv } type streamRuntime struct { - c *criContainerdService + c *criService } -func newStreamRuntime(c *criContainerdService) streaming.Runtime { +func newStreamRuntime(c *criService) streaming.Runtime { return &streamRuntime{c: c} } diff --git a/pkg/server/update_runtime_config.go b/pkg/server/update_runtime_config.go index 62a69dd37..f53550c77 100644 --- a/pkg/server/update_runtime_config.go +++ b/pkg/server/update_runtime_config.go @@ -24,6 +24,6 @@ import ( // UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates. // TODO(random-liu): Figure out how to handle pod cidr in the cri plugin. -func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) { +func (c *criService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) { return &runtime.UpdateRuntimeConfigResponse{}, nil } diff --git a/pkg/server/version.go b/pkg/server/version.go index acaad7863..a23a28112 100644 --- a/pkg/server/version.go +++ b/pkg/server/version.go @@ -32,7 +32,7 @@ const ( ) // Version returns the runtime name, runtime version and runtime API version. -func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) { +func (c *criService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) { return &runtime.VersionResponse{ Version: kubeAPIVersion, RuntimeName: containerName,