Rename all variables to remove "cricontainerd".
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
9afdd1956b
commit
387da59ee5
@ -49,7 +49,7 @@ var loadCommand = cli.Command{
|
|||||||
timeout = context.GlobalDuration("timeout")
|
timeout = context.GlobalDuration("timeout")
|
||||||
cancel gocontext.CancelFunc
|
cancel gocontext.CancelFunc
|
||||||
)
|
)
|
||||||
cl, err := client.NewCRIContainerdClient(address, timeout)
|
cl, err := client.NewCRIPluginClient(address, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create grpc client")
|
return errors.Wrap(err, "failed to create grpc client")
|
||||||
}
|
}
|
||||||
|
2
cri.go
2
cri.go
@ -92,7 +92,7 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
return nil, errors.Wrap(err, "failed to create containerd client")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create CRI service")
|
return nil, errors.Wrap(err, "failed to create CRI service")
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,6 @@ protoc \
|
|||||||
|
|
||||||
# Update boilerplate for the generated file.
|
# Update boilerplate for the generated file.
|
||||||
echo "$(cat hack/boilerplate/boilerplate.go.txt ${API_ROOT}/api.pb.go)" > ${API_ROOT}/api.pb.go
|
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
|
gofmt -l -s -w ${API_ROOT}/api.pb.go
|
||||||
|
@ -58,7 +58,7 @@ func TestImageLoad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("load image in cri")
|
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.NoError(t, err)
|
||||||
require.Equal(t, []string{loadedImage}, res.GetImages())
|
require.Equal(t, []string{loadedImage}, res.GetImages())
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
runtimeService cri.RuntimeService
|
runtimeService cri.RuntimeService
|
||||||
imageService cri.ImageManagerService
|
imageService cri.ImageManagerService
|
||||||
containerdClient *containerd.Client
|
containerdClient *containerd.Client
|
||||||
criContainerdClient api.CRIContainerdServiceClient
|
criPluginClient api.CRIPluginServiceClient
|
||||||
)
|
)
|
||||||
|
|
||||||
var criContainerdEndpoint = flag.String("cri-endpoint", "/run/containerd/containerd.sock", "The endpoint of cri plugin.")
|
var criEndpoint = 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 criRoot = flag.String("cri-root", "/var/lib/containerd/io.containerd.grpc.v1.cri", "The root directory of cri plugin.")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -64,11 +64,11 @@ func init() {
|
|||||||
// ConnectDaemons connect cri plugin and containerd, and initialize the clients.
|
// ConnectDaemons connect cri plugin and containerd, and initialize the clients.
|
||||||
func ConnectDaemons() error {
|
func ConnectDaemons() error {
|
||||||
var err error
|
var err error
|
||||||
runtimeService, err = remote.NewRemoteRuntimeService(*criContainerdEndpoint, timeout)
|
runtimeService, err = remote.NewRemoteRuntimeService(*criEndpoint, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create runtime service")
|
return errors.Wrap(err, "failed to create runtime service")
|
||||||
}
|
}
|
||||||
imageService, err = remote.NewRemoteImageService(*criContainerdEndpoint, timeout)
|
imageService, err = remote.NewRemoteImageService(*criEndpoint, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create image service")
|
return errors.Wrap(err, "failed to create image service")
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ func ConnectDaemons() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to connect containerd")
|
return errors.Wrap(err, "failed to connect containerd")
|
||||||
}
|
}
|
||||||
criContainerdClient, err = client.NewCRIContainerdClient(*criContainerdEndpoint, timeout)
|
criPluginClient, err = client.NewCRIPluginClient(*criEndpoint, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to connect cri plugin")
|
return errors.Wrap(err, "failed to connect cri plugin")
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func TestVolumeCopyUp(t *testing.T) {
|
|||||||
assert.Equal(t, "test_content\n", string(stdout))
|
assert.Equal(t, "test_content\n", string(stdout))
|
||||||
|
|
||||||
t.Logf("Check host path of the volume")
|
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()
|
output, err := exec.Command("sh", "-c", hostCmd).CombinedOutput()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "test_content\n", string(output))
|
assert.Equal(t, "test_content\n", string(output))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 The Kubernetes Authors.
|
Copyright 2018 The containerd Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Code generated by protoc-gen-gogo.
|
// Code generated by protoc-gen-gogo.
|
||||||
// source: api.proto
|
// source: api.proto
|
||||||
// DO NOT EDIT!
|
// DO NOT EDIT!
|
||||||
@ -101,66 +100,66 @@ var _ grpc.ClientConn
|
|||||||
// is compatible with the grpc package it is being compiled against.
|
// is compatible with the grpc package it is being compiled against.
|
||||||
const _ = grpc.SupportPackageIsVersion4
|
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 loads a image into containerd.
|
||||||
LoadImage(ctx context.Context, in *LoadImageRequest, opts ...grpc.CallOption) (*LoadImageResponse, error)
|
LoadImage(ctx context.Context, in *LoadImageRequest, opts ...grpc.CallOption) (*LoadImageResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cRIContainerdServiceClient struct {
|
type cRIPluginServiceClient struct {
|
||||||
cc *grpc.ClientConn
|
cc *grpc.ClientConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCRIContainerdServiceClient(cc *grpc.ClientConn) CRIContainerdServiceClient {
|
func NewCRIPluginServiceClient(cc *grpc.ClientConn) CRIPluginServiceClient {
|
||||||
return &cRIContainerdServiceClient{cc}
|
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)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
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 loads a image into containerd.
|
||||||
LoadImage(context.Context, *LoadImageRequest) (*LoadImageResponse, error)
|
LoadImage(context.Context, *LoadImageRequest) (*LoadImageResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterCRIContainerdServiceServer(s *grpc.Server, srv CRIContainerdServiceServer) {
|
func RegisterCRIPluginServiceServer(s *grpc.Server, srv CRIPluginServiceServer) {
|
||||||
s.RegisterService(&_CRIContainerdService_serviceDesc, srv)
|
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)
|
in := new(LoadImageRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if interceptor == nil {
|
if interceptor == nil {
|
||||||
return srv.(CRIContainerdServiceServer).LoadImage(ctx, in)
|
return srv.(CRIPluginServiceServer).LoadImage(ctx, in)
|
||||||
}
|
}
|
||||||
info := &grpc.UnaryServerInfo{
|
info := &grpc.UnaryServerInfo{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
FullMethod: "/api.v1.CRIContainerdService/LoadImage",
|
FullMethod: "/api.v1.CRIPluginService/LoadImage",
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
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)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _CRIContainerdService_serviceDesc = grpc.ServiceDesc{
|
var _CRIPluginService_serviceDesc = grpc.ServiceDesc{
|
||||||
ServiceName: "api.v1.CRIContainerdService",
|
ServiceName: "api.v1.CRIPluginService",
|
||||||
HandlerType: (*CRIContainerdServiceServer)(nil),
|
HandlerType: (*CRIPluginServiceServer)(nil),
|
||||||
Methods: []grpc.MethodDesc{
|
Methods: []grpc.MethodDesc{
|
||||||
{
|
{
|
||||||
MethodName: "LoadImage",
|
MethodName: "LoadImage",
|
||||||
Handler: _CRIContainerdService_LoadImage_Handler,
|
Handler: _CRIPluginService_LoadImage_Handler,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{},
|
Streams: []grpc.StreamDesc{},
|
||||||
@ -580,7 +579,7 @@ var (
|
|||||||
func init() { proto.RegisterFile("api.proto", fileDescriptorApi) }
|
func init() { proto.RegisterFile("api.proto", fileDescriptorApi) }
|
||||||
|
|
||||||
var fileDescriptorApi = []byte{
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
0xb8, 0xd8, 0xc0, 0x02, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0x9c, 0x41, 0x50, 0x9e, 0x51, 0x18,
|
||||||
0x97, 0x88, 0x73, 0x90, 0xa7, 0x73, 0x7e, 0x5e, 0x49, 0x62, 0x66, 0x5e, 0x6a, 0x51, 0x4a, 0x70,
|
0x97, 0x80, 0x73, 0x90, 0x67, 0x40, 0x4e, 0x69, 0x7a, 0x66, 0x5e, 0x70, 0x6a, 0x51, 0x59, 0x66,
|
||||||
0x6a, 0x51, 0x59, 0x66, 0x72, 0xaa, 0x90, 0x13, 0x17, 0x27, 0xdc, 0x10, 0x21, 0x09, 0x3d, 0x88,
|
0x72, 0xaa, 0x90, 0x13, 0x17, 0x27, 0xdc, 0x00, 0x21, 0x09, 0x3d, 0x88, 0xab, 0xf5, 0xd0, 0xdd,
|
||||||
0xcb, 0xf5, 0xd0, 0xdd, 0x21, 0x25, 0x89, 0x45, 0x06, 0x62, 0xa3, 0x12, 0x83, 0x93, 0xcc, 0x89,
|
0x20, 0x25, 0x89, 0x45, 0x06, 0x62, 0x9b, 0x12, 0x83, 0x93, 0xcc, 0x89, 0x87, 0x72, 0x8c, 0x37,
|
||||||
0x87, 0x72, 0x8c, 0x37, 0x1e, 0xca, 0x31, 0x34, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1,
|
0x1e, 0xca, 0x31, 0x34, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6,
|
||||||
0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xfb,
|
0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0x48, 0x62, 0x03, 0xfb, 0xcc, 0x18, 0x10, 0x00,
|
||||||
0xce, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x6a, 0xfe, 0x35, 0x81, 0x21, 0x01, 0x00, 0x00,
|
0x00, 0xff, 0xff, 0xfc, 0x6f, 0xec, 0xf4, 0x1d, 0x01, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ option (gogoproto.sizer_all) = true;
|
|||||||
option (gogoproto.unmarshaler_all) = true;
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
option (gogoproto.goproto_unrecognized_all) = false;
|
option (gogoproto.goproto_unrecognized_all) = false;
|
||||||
|
|
||||||
// CRIContainerdService defines non-CRI APIs for cri-containerd.
|
// CRIPluginService defines non-CRI APIs for cri plugin.
|
||||||
service CRIContainerdService{
|
service CRIPluginService{
|
||||||
// LoadImage loads a image into containerd.
|
// LoadImage loads a image into containerd.
|
||||||
rpc LoadImage(LoadImageRequest) returns (LoadImageResponse) {}
|
rpc LoadImage(LoadImageRequest) returns (LoadImageResponse) {}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ import (
|
|||||||
api "github.com/containerd/cri/pkg/api/v1"
|
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.
|
// 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)
|
addr, dialer, err := util.GetAddressAndDialer(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get dialer")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to dial")
|
return nil, errors.Wrap(err, "failed to dial")
|
||||||
}
|
}
|
||||||
return api.NewCRIContainerdServiceClient(conn), nil
|
return api.NewCRIPluginServiceClient(conn), nil
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ type Config struct {
|
|||||||
ContainerdRootDir string `json:"containerdRootDir,omitempty"`
|
ContainerdRootDir string `json:"containerdRootDir,omitempty"`
|
||||||
// ContainerdEndpoint is the containerd endpoint path.
|
// ContainerdEndpoint is the containerd endpoint path.
|
||||||
ContainerdEndpoint string `json:"containerdEndpoint,omitempty"`
|
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.)
|
// (metadata checkpoint etc.)
|
||||||
RootDir string `json:"rootDir,omitempty"`
|
RootDir string `json:"rootDir,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
|
// 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())
|
cntr, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to find container in store")
|
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)
|
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 {
|
tty bool, resize <-chan remotecommand.TerminalSize) error {
|
||||||
// Get container from our container store.
|
// Get container from our container store.
|
||||||
cntr, err := c.containerStore.Get(id)
|
cntr, err := c.containerStore.Get(id)
|
||||||
|
@ -73,7 +73,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateContainer creates a new container in the given PodSandbox.
|
// 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()
|
config := r.GetConfig()
|
||||||
sandboxConfig := r.GetSandboxConfig()
|
sandboxConfig := r.GetSandboxConfig()
|
||||||
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
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
|
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) {
|
sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, extraMounts []*runtime.Mount) (*runtimespec.Spec, error) {
|
||||||
// Creates a spec Generator with the default spec.
|
// Creates a spec Generator with the default spec.
|
||||||
spec, err := defaultRuntimeSpec(id)
|
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
|
// 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
|
// root directory to do cleanup. Note that image volume will be skipped, if there is criMounts
|
||||||
// specified with the same destination.
|
// 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 {
|
if len(config.Volumes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ func (c *criContainerdService) generateVolumeMounts(containerRootDir string, cri
|
|||||||
|
|
||||||
// generateContainerMounts sets up necessary container mounts including /dev/shm, /etc/hosts
|
// generateContainerMounts sets up necessary container mounts including /dev/shm, /etc/hosts
|
||||||
// and /etc/resolv.conf.
|
// 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
|
var mounts []*runtime.Mount
|
||||||
securityContext := config.GetLinux().GetSecurityContext()
|
securityContext := config.GetLinux().GetSecurityContext()
|
||||||
if !isInCRIMounts(etcHosts, config.GetMounts()) {
|
if !isInCRIMounts(etcHosts, config.GetMounts()) {
|
||||||
@ -496,7 +496,7 @@ func clearReadOnly(m *runtimespec.Mount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// addDevices set device mapping without privilege.
|
// 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()
|
spec := g.Spec()
|
||||||
for _, device := range devs {
|
for _, device := range devs {
|
||||||
path, err := c.os.ResolveSymbolicLink(device.HostPath)
|
path, err := c.os.ResolveSymbolicLink(device.HostPath)
|
||||||
@ -559,7 +559,7 @@ func setOCIDevicesPrivileged(g *generate.Generator) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// addOCIBindMounts adds bind mounts.
|
// 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.
|
// Mount cgroup into the container as readonly, which inherits docker's behavior.
|
||||||
g.AddCgroupsMount("ro") // nolint: errcheck
|
g.AddCgroupsMount("ro") // nolint: errcheck
|
||||||
for _, mount := range mounts {
|
for _, mount := range mounts {
|
||||||
|
@ -188,7 +188,7 @@ func TestGeneralContainerSpec(t *testing.T) {
|
|||||||
testID := "test-id"
|
testID := "test-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -200,7 +200,7 @@ func TestContainerCapabilities(t *testing.T) {
|
|||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
capability *runtime.Capability
|
capability *runtime.Capability
|
||||||
includes []string
|
includes []string
|
||||||
@ -269,7 +269,7 @@ func TestContainerSpecTty(t *testing.T) {
|
|||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
for _, tty := range []bool{true, false} {
|
for _, tty := range []bool{true, false} {
|
||||||
config.Tty = tty
|
config.Tty = tty
|
||||||
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
||||||
@ -289,7 +289,7 @@ func TestContainerSpecReadonlyRootfs(t *testing.T) {
|
|||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
for _, readonly := range []bool{true, false} {
|
for _, readonly := range []bool{true, false} {
|
||||||
config.Linux.SecurityContext.ReadonlyRootfs = readonly
|
config.Linux.SecurityContext.ReadonlyRootfs = readonly
|
||||||
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
spec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil)
|
||||||
@ -304,7 +304,7 @@ func TestContainerSpecWithExtraMounts(t *testing.T) {
|
|||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
mountInConfig := &runtime.Mount{
|
mountInConfig := &runtime.Mount{
|
||||||
ContainerPath: "test-container-path",
|
ContainerPath: "test-container-path",
|
||||||
HostPath: "test-host-path",
|
HostPath: "test-host-path",
|
||||||
@ -338,7 +338,7 @@ func TestContainerAndSandboxPrivileged(t *testing.T) {
|
|||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
config, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
containerPrivileged bool
|
containerPrivileged bool
|
||||||
sandboxPrivileged bool
|
sandboxPrivileged bool
|
||||||
@ -477,7 +477,7 @@ func TestGenerateVolumeMounts(t *testing.T) {
|
|||||||
config := &imagespec.ImageConfig{
|
config := &imagespec.ImageConfig{
|
||||||
Volumes: test.imageVolumes,
|
Volumes: test.imageVolumes,
|
||||||
}
|
}
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
got := c.generateVolumeMounts(testContainerRootDir, test.criMounts, config)
|
got := c.generateVolumeMounts(testContainerRootDir, test.criMounts, config)
|
||||||
assert.Len(t, got, len(test.expectedMountDest))
|
assert.Len(t, got, len(test.expectedMountDest))
|
||||||
for _, dest := range test.expectedMountDest {
|
for _, dest := range test.expectedMountDest {
|
||||||
@ -596,7 +596,7 @@ func TestGenerateContainerMounts(t *testing.T) {
|
|||||||
SecurityContext: test.securityContext,
|
SecurityContext: test.securityContext,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
mounts := c.generateContainerMounts(testSandboxRootDir, config)
|
mounts := c.generateContainerMounts(testSandboxRootDir, config)
|
||||||
assert.Equal(t, test.expectedMounts, mounts, desc)
|
assert.Equal(t, test.expectedMounts, mounts, desc)
|
||||||
}
|
}
|
||||||
@ -628,7 +628,7 @@ func TestPrivilegedBindMount(t *testing.T) {
|
|||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
g := generate.New()
|
g := generate.New()
|
||||||
g.SetRootReadonly(test.readonlyRootFS)
|
g.SetRootReadonly(test.readonlyRootFS)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
c.addOCIBindMounts(&g, nil, "")
|
c.addOCIBindMounts(&g, nil, "")
|
||||||
if test.privileged {
|
if test.privileged {
|
||||||
setOCIBindMountsPrivileged(&g)
|
setOCIBindMountsPrivileged(&g)
|
||||||
@ -736,7 +736,7 @@ func TestMountPropagation(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
g := generate.New()
|
g := generate.New()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn
|
c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn
|
||||||
err := c.addOCIBindMounts(&g, []*runtime.Mount{test.criMount}, "")
|
err := c.addOCIBindMounts(&g, []*runtime.Mount{test.criMount}, "")
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
@ -753,7 +753,7 @@ func TestPidNamespace(t *testing.T) {
|
|||||||
testPid := uint32(1234)
|
testPid := uint32(1234)
|
||||||
testSandboxID := "sandbox-id"
|
testSandboxID := "sandbox-id"
|
||||||
config, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
config, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
pidNS runtime.NamespaceMode
|
pidNS runtime.NamespaceMode
|
||||||
expected runtimespec.LinuxNamespace
|
expected runtimespec.LinuxNamespace
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
|
// 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())
|
cntr, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find container %q in store", r.GetContainerId())
|
return nil, errors.Wrapf(err, "failed to find container %q in store", r.GetContainerId())
|
||||||
|
@ -39,7 +39,7 @@ import (
|
|||||||
|
|
||||||
// ExecSync executes a command in the container, and returns the stdout output.
|
// 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.
|
// 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
|
var stdout, stderr bytes.Buffer
|
||||||
exitCode, err := c.execInContainer(ctx, r.GetContainerId(), execOptions{
|
exitCode, err := c.execInContainer(ctx, r.GetContainerId(), execOptions{
|
||||||
cmd: r.GetCmd(),
|
cmd: r.GetCmd(),
|
||||||
@ -71,7 +71,7 @@ type execOptions struct {
|
|||||||
|
|
||||||
// execInContainer executes a command inside the container synchronously, and
|
// execInContainer executes a command inside the container synchronously, and
|
||||||
// redirects stdio stream properly.
|
// 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.
|
// Cancel the context before returning to ensure goroutines are stopped.
|
||||||
// This is important, because if `Start` returns error, `Wait` will hang
|
// This is important, because if `Start` returns error, `Wait` will hang
|
||||||
// forever unless we cancel the context.
|
// forever unless we cancel the context.
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ListContainers lists all containers matching the filter.
|
// 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.
|
// List all containers from store.
|
||||||
containersInStore := c.containerStore.List()
|
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 {
|
if cntr, err := c.containerStore.Get(filter.GetId()); err == nil {
|
||||||
filter.Id = cntr.ID
|
filter.Id = cntr.ID
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func (c *criContainerdService) normalizeContainerFilter(filter *runtime.Containe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filterCRIContainers filters CRIContainers.
|
// 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 {
|
if filter == nil {
|
||||||
return containers
|
return containers
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func TestToCRIContainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterContainers(t *testing.T) {
|
func TestFilterContainers(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
|
|
||||||
testContainers := []*runtime.Container{
|
testContainers := []*runtime.Container{
|
||||||
{
|
{
|
||||||
@ -168,7 +168,7 @@ func (c containerForTest) toContainer() (containerstore.Container, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListContainers(t *testing.T) {
|
func TestListContainers(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
sandboxesInStore := []sandboxstore.Sandbox{
|
sandboxesInStore := []sandboxstore.Sandbox{
|
||||||
sandboxstore.NewSandbox(
|
sandboxstore.NewSandbox(
|
||||||
sandboxstore.Metadata{
|
sandboxstore.Metadata{
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
// ReopenContainerLog asks the cri plugin to reopen the stdout/stderr log file for the container.
|
// 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.
|
// 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())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
|
|
||||||
// RemoveContainer removes the container.
|
// RemoveContainer removes the container.
|
||||||
// TODO(random-liu): Forcibly stop container if it's running.
|
// 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())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != store.ErrNotExist {
|
if err != store.ErrNotExist {
|
||||||
|
@ -35,7 +35,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// StartContainer starts the container.
|
// 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())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
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
|
// 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.
|
// 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,
|
cntr containerstore.Container,
|
||||||
status *containerstore.Status) (retErr error) {
|
status *containerstore.Status) (retErr error) {
|
||||||
id := cntr.ID
|
id := cntr.ID
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
// ContainerStats returns stats of the container. If the container does not
|
// ContainerStats returns stats of the container. If the container does not
|
||||||
// exist, the call returns an error.
|
// 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())
|
cntr, err := c.containerStore.Get(in.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to find container")
|
return nil, errors.Wrap(err, "failed to find container")
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ListContainerStats returns stats of all running containers.
|
// ListContainerStats returns stats of all running containers.
|
||||||
func (c *criContainerdService) ListContainerStats(
|
func (c *criService) ListContainerStats(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
in *runtime.ListContainerStatsRequest,
|
in *runtime.ListContainerStatsRequest,
|
||||||
) (*runtime.ListContainerStatsResponse, error) {
|
) (*runtime.ListContainerStatsResponse, error) {
|
||||||
@ -48,7 +48,7 @@ func (c *criContainerdService) ListContainerStats(
|
|||||||
return criStats, nil
|
return criStats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) toCRIContainerStats(
|
func (c *criService) toCRIContainerStats(
|
||||||
stats []*types.Metric,
|
stats []*types.Metric,
|
||||||
containers []containerstore.Container,
|
containers []containerstore.Container,
|
||||||
) (*runtime.ListContainerStatsResponse, error) {
|
) (*runtime.ListContainerStatsResponse, error) {
|
||||||
@ -67,7 +67,7 @@ func (c *criContainerdService) toCRIContainerStats(
|
|||||||
return containerStats, nil
|
return containerStats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) getContainerMetrics(
|
func (c *criService) getContainerMetrics(
|
||||||
meta containerstore.Metadata,
|
meta containerstore.Metadata,
|
||||||
stats *types.Metric,
|
stats *types.Metric,
|
||||||
) (*runtime.ContainerStats, error) {
|
) (*runtime.ContainerStats, error) {
|
||||||
@ -118,7 +118,7 @@ func (c *criContainerdService) getContainerMetrics(
|
|||||||
return &cs, nil
|
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 {
|
if cntr, err := c.containerStore.Get(filter.GetId()); err == nil {
|
||||||
filter.Id = cntr.ID
|
filter.Id = cntr.ID
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ func (c *criContainerdService) normalizeContainerStatsFilter(filter *runtime.Con
|
|||||||
|
|
||||||
// buildTaskMetricsRequest constructs a tasks.MetricsRequest based on
|
// buildTaskMetricsRequest constructs a tasks.MetricsRequest based on
|
||||||
// the information in the stats request and the containerStore
|
// the information in the stats request and the containerStore
|
||||||
func (c *criContainerdService) buildTaskMetricsRequest(
|
func (c *criService) buildTaskMetricsRequest(
|
||||||
r *runtime.ListContainerStatsRequest,
|
r *runtime.ListContainerStatsRequest,
|
||||||
) (tasks.MetricsRequest, []containerstore.Container, error) {
|
) (tasks.MetricsRequest, []containerstore.Container, error) {
|
||||||
var req tasks.MetricsRequest
|
var req tasks.MetricsRequest
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ContainerStatus inspects the container and returns the status.
|
// 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())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
return nil, errors.Wrapf(err, "an error occurred when try to find container %q", r.GetContainerId())
|
||||||
|
@ -193,7 +193,7 @@ func TestContainerStatus(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
metadata, status, image, expected := getContainerStatusTestData()
|
metadata, status, image, expected := getContainerStatusTestData()
|
||||||
// Update status with test case.
|
// Update status with test case.
|
||||||
status.FinishedAt = test.finishedAt
|
status.FinishedAt = test.finishedAt
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
const killContainerTimeout = 2 * time.Minute
|
const killContainerTimeout = 2 * time.Minute
|
||||||
|
|
||||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
// 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.
|
// Get container config from container store.
|
||||||
container, err := c.containerStore.Get(r.GetContainerId())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
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.
|
// 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
|
id := container.ID
|
||||||
|
|
||||||
// Return without error if container is not running. This makes sure that
|
// 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.
|
// 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)
|
timeoutTimer := time.NewTimer(timeout)
|
||||||
defer timeoutTimer.Stop()
|
defer timeoutTimer.Stop()
|
||||||
select {
|
select {
|
||||||
|
@ -61,7 +61,7 @@ func TestWaitContainerStop(t *testing.T) {
|
|||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
container, err := containerstore.NewContainer(
|
container, err := containerstore.NewContainer(
|
||||||
containerstore.Metadata{ID: id},
|
containerstore.Metadata{ID: id},
|
||||||
containerstore.WithFakeStatus(*test.status),
|
containerstore.WithFakeStatus(*test.status),
|
||||||
|
@ -35,7 +35,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// UpdateContainerResources updates ContainerConfig of the container.
|
// 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())
|
container, err := c.containerStore.Get(r.GetContainerId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to find container")
|
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
|
return &runtime.UpdateContainerResourcesResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) updateContainerResources(ctx context.Context,
|
func (c *criService) updateContainerResources(ctx context.Context,
|
||||||
cntr containerstore.Container,
|
cntr containerstore.Container,
|
||||||
resources *runtime.LinuxContainerResources,
|
resources *runtime.LinuxContainerResources,
|
||||||
status containerstore.Status) (retErr error) {
|
status containerstore.Status) (retErr error) {
|
||||||
|
@ -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
|
// localResolve resolves image reference locally and returns corresponding image metadata. It returns
|
||||||
// nil without error if the reference doesn't exist.
|
// 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 {
|
getImageID := func(refOrId string) string {
|
||||||
if _, err := imagedigest.Parse(refOrID); err == nil {
|
if _, err := imagedigest.Parse(refOrID); err == nil {
|
||||||
return refOrID
|
return refOrID
|
||||||
@ -278,7 +278,7 @@ func getUserFromImage(user string) (*int64, string) {
|
|||||||
|
|
||||||
// ensureImageExists returns corresponding metadata of the image reference, if image is not
|
// ensureImageExists returns corresponding metadata of the image reference, if image is not
|
||||||
// pulled yet, the function will pull the image.
|
// 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)
|
image, err := c.localResolve(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to resolve image %q", ref)
|
return nil, errors.Wrapf(err, "failed to resolve image %q", ref)
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
// ListImages lists existing images.
|
// ListImages lists existing images.
|
||||||
// TODO(random-liu): Add image list filters after CRI defines this more clear, and kubelet
|
// TODO(random-liu): Add image list filters after CRI defines this more clear, and kubelet
|
||||||
// actually needs it.
|
// 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()
|
imagesInStore := c.imageStore.List()
|
||||||
|
|
||||||
var images []*runtime.Image
|
var images []*runtime.Image
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestListImages(t *testing.T) {
|
func TestListImages(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
imagesInStore := []imagestore.Image{
|
imagesInStore := []imagestore.Image{
|
||||||
{
|
{
|
||||||
ID: "sha256:1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
ID: "sha256:1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// LoadImage loads a image into containerd.
|
// 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()
|
path := r.GetFilePath()
|
||||||
if !filepath.IsAbs(path) {
|
if !filepath.IsAbs(path) {
|
||||||
return nil, errors.Errorf("path %q is not an absolute path", path)
|
return nil, errors.Errorf("path %q is not an absolute path", path)
|
||||||
|
@ -77,7 +77,7 @@ import (
|
|||||||
// contents are missing but snapshots are ready, is the image still "READY"?
|
// contents are missing but snapshots are ready, is the image still "READY"?
|
||||||
|
|
||||||
// PullImage pulls an image with authentication config.
|
// 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()
|
imageRef := r.GetImage().GetImage()
|
||||||
namedRef, err := util.NormalizeImageRef(imageRef)
|
namedRef, err := util.NormalizeImageRef(imageRef)
|
||||||
if err != nil {
|
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.
|
// 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
|
// the image reference is deleted by someone else after create returns already exists, but before update
|
||||||
// happens.
|
// 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{
|
img := containerdimages.Image{
|
||||||
Name: name,
|
Name: name,
|
||||||
Target: desc,
|
Target: desc,
|
||||||
@ -212,7 +212,7 @@ func (c *criContainerdService) createImageReference(ctx context.Context, name st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) getResolverOptions() map[string][]string {
|
func (c *criService) getResolverOptions() map[string][]string {
|
||||||
options := make(map[string][]string)
|
options := make(map[string][]string)
|
||||||
for ns, mirror := range c.config.Mirrors {
|
for ns, mirror := range c.config.Mirrors {
|
||||||
options[ns] = append(options[ns], mirror.Endpoints...)
|
options[ns] = append(options[ns], mirror.Endpoints...)
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
// TODO(random-liu): We should change CRI to distinguish image id and image spec.
|
// 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
|
// Remove the whole image no matter the it's image id or reference. This is the
|
||||||
// semantic defined in CRI now.
|
// 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())
|
image, err := c.localResolve(ctx, r.GetImage().GetImage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "can not resolve %q locally", r.GetImage().GetImage())
|
return nil, errors.Wrapf(err, "can not resolve %q locally", r.GetImage().GetImage())
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
// ImageStatus returns the status of the image, returns nil if the image isn't present.
|
// 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
|
// TODO(random-liu): We should change CRI to distinguish image id and image spec. (See
|
||||||
// kubernetes/kubernetes#46255)
|
// 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())
|
image, err := c.localResolve(ctx, r.GetImage().GetImage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "can not resolve %q locally", r.GetImage().GetImage())
|
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.
|
// 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 {
|
if !verbose {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func TestImageStatus(t *testing.T) {
|
|||||||
Username: "user",
|
Username: "user",
|
||||||
}
|
}
|
||||||
|
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
t.Logf("should return nil image spec without error for non-exist image")
|
t.Logf("should return nil image spec without error for non-exist image")
|
||||||
resp, err := c.ImageStatus(context.Background(), &runtime.ImageStatusRequest{
|
resp, err := c.ImageStatus(context.Background(), &runtime.ImageStatusRequest{
|
||||||
Image: &runtime.ImageSpec{Image: testID},
|
Image: &runtime.ImageSpec{Image: testID},
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ImageFsInfo returns information of the filesystem that is used to store images.
|
// 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()
|
snapshots := c.snapshotStore.List()
|
||||||
timestamp := time.Now().UnixNano()
|
timestamp := time.Now().UnixNano()
|
||||||
var usedBytes, inodesUsed uint64
|
var usedBytes, inodesUsed uint64
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestImageFsInfo(t *testing.T) {
|
func TestImageFsInfo(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
snapshots := []snapshotstore.Snapshot{
|
snapshots := []snapshotstore.Snapshot{
|
||||||
{
|
{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
|
@ -30,10 +30,10 @@ import (
|
|||||||
|
|
||||||
// instrumentedService wraps service with containerd namespace and logs.
|
// instrumentedService wraps service with containerd namespace and logs.
|
||||||
type instrumentedService struct {
|
type instrumentedService struct {
|
||||||
c *criContainerdService
|
c *criService
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInstrumentedService(c *criContainerdService) grpcServices {
|
func newInstrumentedService(c *criService) grpcServices {
|
||||||
return &instrumentedService{c: c}
|
return &instrumentedService{c: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ import (
|
|||||||
// tolerant tasks being created or started, we prefer that not to happen.
|
// tolerant tasks being created or started, we prefer that not to happen.
|
||||||
|
|
||||||
// recover recovers system state from containerd and status checkpoint.
|
// 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.
|
// Recover all sandboxes.
|
||||||
sandboxes, err := c.client.Containers(ctx, filterLabel(containerKindLabel, containerKindSandbox))
|
sandboxes, err := c.client.Containers(ctx, filterLabel(containerKindLabel, containerKindSandbox))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ListPodSandbox returns a list of Sandbox.
|
// 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.
|
// List all sandboxes from store.
|
||||||
sandboxesInStore := c.sandboxStore.List()
|
sandboxesInStore := c.sandboxStore.List()
|
||||||
var sandboxes []*runtime.PodSandbox
|
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 {
|
if sb, err := c.sandboxStore.Get(filter.GetId()); err == nil {
|
||||||
filter.Id = sb.ID
|
filter.Id = sb.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterCRISandboxes filters CRISandboxes.
|
// 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 {
|
if filter == nil {
|
||||||
return sandboxes
|
return sandboxes
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ func TestToCRISandbox(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterSandboxes(t *testing.T) {
|
func TestFilterSandboxes(t *testing.T) {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
sandboxes := []sandboxstore.Sandbox{
|
sandboxes := []sandboxstore.Sandbox{
|
||||||
sandboxstore.NewSandbox(
|
sandboxstore.NewSandbox(
|
||||||
sandboxstore.Metadata{
|
sandboxstore.Metadata{
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
// 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.
|
// TODO(random-liu): Run a socat container inside the sandbox to do portforward.
|
||||||
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
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
|
// 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
|
// 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.
|
// 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)
|
s, err := c.sandboxStore.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
return errors.Wrapf(err, "failed to find sandbox %q in store", id)
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
|
|
||||||
// RemovePodSandbox removes the sandbox. If there are running containers in the
|
// RemovePodSandbox removes the sandbox. If there are running containers in the
|
||||||
// sandbox, they should be forcibly removed.
|
// 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())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != store.ErrNotExist {
|
if err != store.ErrNotExist {
|
||||||
|
@ -51,7 +51,7 @@ func init() {
|
|||||||
|
|
||||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||||
// the sandbox is in ready state.
|
// 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()
|
config := r.GetConfig()
|
||||||
|
|
||||||
// Generate unique id and name for the sandbox and reserve the name.
|
// 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
|
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) {
|
imageConfig *imagespec.ImageConfig, nsPath string) (*runtimespec.Spec, error) {
|
||||||
// Creates a spec Generator with the default spec.
|
// Creates a spec Generator with the default spec.
|
||||||
// TODO(random-liu): [P1] Compare the default settings with docker and containerd default.
|
// 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
|
// setupSandboxFiles sets up necessary sandbox files including /dev/shm, /etc/hosts
|
||||||
// and /etc/resolv.conf.
|
// 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.
|
// TODO(random-liu): Consider whether we should maintain /etc/hosts and /etc/resolv.conf in kubelet.
|
||||||
sandboxEtcHosts := getSandboxHosts(rootDir)
|
sandboxEtcHosts := getSandboxHosts(rootDir)
|
||||||
if err := c.os.CopyFile(etcHosts, sandboxEtcHosts, 0644); err != nil {
|
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:
|
// remove these files. Unmount should *NOT* return error when:
|
||||||
// 1) The mount point is already unmounted.
|
// 1) The mount point is already unmounted.
|
||||||
// 2) The mount point doesn't exist.
|
// 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 config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetIpc() != runtime.NamespaceMode_NODE {
|
||||||
if err := c.os.Unmount(getSandboxDevShm(rootDir), unix.MNT_DETACH); err != nil && !os.IsNotExist(err) {
|
if err := c.os.Unmount(getSandboxDevShm(rootDir), unix.MNT_DETACH); err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
@ -478,7 +478,7 @@ func (c *criContainerdService) unmountSandboxFiles(rootDir string, config *runti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setupPod setups up the network for a pod
|
// 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 {
|
if c.netPlugin == nil {
|
||||||
return "", errors.New("cni config not intialized")
|
return "", errors.New("cni config not intialized")
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
config, imageConfig, specCheck := getRunPodSandboxTestData()
|
config, imageConfig, specCheck := getRunPodSandboxTestData()
|
||||||
if test.configChange != nil {
|
if test.configChange != nil {
|
||||||
test.configChange(config)
|
test.configChange(config)
|
||||||
@ -261,7 +261,7 @@ options timeout:1
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
cfg := &runtime.PodSandboxConfig{
|
cfg := &runtime.PodSandboxConfig{
|
||||||
DnsConfig: test.dnsConfig,
|
DnsConfig: test.dnsConfig,
|
||||||
Linux: &runtime.LinuxPodSandboxConfig{
|
Linux: &runtime.LinuxPodSandboxConfig{
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// PodSandboxStatus returns the status of the PodSandbox.
|
// 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())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "an error occurred when try to find sandbox")
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *criContainerdService) getIP(sandbox sandboxstore.Sandbox) string {
|
func (c *criService) getIP(sandbox sandboxstore.Sandbox) string {
|
||||||
config := sandbox.Config
|
config := sandbox.Config
|
||||||
|
|
||||||
if config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE {
|
if config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE {
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
|
|
||||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||||
// sandbox, they should be forcibly terminated.
|
// 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())
|
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "an error occurred when try to find sandbox %q",
|
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.
|
// 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
|
container := sandbox.Container
|
||||||
task, err := container.Task(ctx, nil)
|
task, err := container.Task(ctx, nil)
|
||||||
if err != 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.
|
// 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)
|
timeoutTimer := time.NewTimer(timeout)
|
||||||
defer timeoutTimer.Stop()
|
defer timeoutTimer.Stop()
|
||||||
select {
|
select {
|
||||||
@ -130,7 +130,7 @@ func (c *criContainerdService) waitSandboxStop(ctx context.Context, sandbox sand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// teardownPod removes the network from the pod
|
// 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 {
|
if c.netPlugin == nil {
|
||||||
return errors.New("cni config not intialized")
|
return errors.New("cni config not intialized")
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func TestWaitSandboxStop(t *testing.T) {
|
|||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
c := newTestCRIContainerdService()
|
c := newTestCRIService()
|
||||||
sandbox := sandboxstore.NewSandbox(
|
sandbox := sandboxstore.NewSandbox(
|
||||||
sandboxstore.Metadata{ID: id},
|
sandboxstore.Metadata{ID: id},
|
||||||
sandboxstore.Status{State: test.state},
|
sandboxstore.Status{State: test.state},
|
||||||
|
@ -50,11 +50,11 @@ import (
|
|||||||
type grpcServices interface {
|
type grpcServices interface {
|
||||||
runtime.RuntimeServiceServer
|
runtime.RuntimeServiceServer
|
||||||
runtime.ImageServiceServer
|
runtime.ImageServiceServer
|
||||||
api.CRIContainerdServiceServer
|
api.CRIPluginServiceServer
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRIContainerdService is the interface implement CRI remote service server.
|
// CRIService is the interface implement CRI remote service server.
|
||||||
type CRIContainerdService interface {
|
type CRIService interface {
|
||||||
Run() error
|
Run() error
|
||||||
// io.Closer is used by containerd to gracefully stop cri service.
|
// io.Closer is used by containerd to gracefully stop cri service.
|
||||||
io.Closer
|
io.Closer
|
||||||
@ -62,8 +62,8 @@ type CRIContainerdService interface {
|
|||||||
grpcServices
|
grpcServices
|
||||||
}
|
}
|
||||||
|
|
||||||
// criContainerdService implements CRIContainerdService.
|
// criService implements CRIService.
|
||||||
type criContainerdService struct {
|
type criService struct {
|
||||||
// config contains all configurations.
|
// config contains all configurations.
|
||||||
config criconfig.Config
|
config criconfig.Config
|
||||||
// imageFSPath is the path to image filesystem.
|
// imageFSPath is the path to image filesystem.
|
||||||
@ -101,10 +101,10 @@ type criContainerdService struct {
|
|||||||
initialized atomic.Bool
|
initialized atomic.Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCRIContainerdService returns a new instance of CRIContainerdService
|
// NewCRIService returns a new instance of CRIService
|
||||||
func NewCRIContainerdService(config criconfig.Config, client *containerd.Client) (CRIContainerdService, error) {
|
func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIService, error) {
|
||||||
var err error
|
var err error
|
||||||
c := &criContainerdService{
|
c := &criService{
|
||||||
config: config,
|
config: config,
|
||||||
client: client,
|
client: client,
|
||||||
apparmorEnabled: runcapparmor.IsEnabled(),
|
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.
|
// Register registers all required services onto a specific grpc server.
|
||||||
// This is used by containerd cri plugin.
|
// 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)
|
instrumented := newInstrumentedService(c)
|
||||||
runtime.RegisterRuntimeServiceServer(s, instrumented)
|
runtime.RegisterRuntimeServiceServer(s, instrumented)
|
||||||
runtime.RegisterImageServiceServer(s, instrumented)
|
runtime.RegisterImageServiceServer(s, instrumented)
|
||||||
api.RegisterCRIContainerdServiceServer(s, instrumented)
|
api.RegisterCRIPluginServiceServer(s, instrumented)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the cri-containerd service.
|
// Run starts the CRI service.
|
||||||
func (c *criContainerdService) Run() error {
|
func (c *criService) Run() error {
|
||||||
logrus.Info("Start subscribing containerd event")
|
logrus.Info("Start subscribing containerd event")
|
||||||
c.eventMonitor.subscribe(c.client)
|
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.
|
// Set the server as initialized. GRPC services could start serving traffic.
|
||||||
c.initialized.Set()
|
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 {
|
select {
|
||||||
case <-eventMonitorCloseCh:
|
case <-eventMonitorCloseCh:
|
||||||
case <-streamServerCloseCh:
|
case <-streamServerCloseCh:
|
||||||
@ -235,9 +235,9 @@ func (c *criContainerdService) Run() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops the cri-containerd service.
|
// Stop stops the CRI service.
|
||||||
func (c *criContainerdService) Close() error {
|
func (c *criService) Close() error {
|
||||||
logrus.Info("Stop cri-containerd service")
|
logrus.Info("Stop CRI service")
|
||||||
// TODO(random-liu): Make event monitor stop synchronous.
|
// TODO(random-liu): Make event monitor stop synchronous.
|
||||||
c.eventMonitor.stop()
|
c.eventMonitor.stop()
|
||||||
if err := c.streamServer.Stop(); err != nil {
|
if err := c.streamServer.Stop(); err != nil {
|
||||||
|
@ -36,9 +36,9 @@ const (
|
|||||||
testImageFSPath = "/test/image/fs/path"
|
testImageFSPath = "/test/image/fs/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newTestCRIContainerdService creates a fake criContainerdService for test.
|
// newTestCRIService creates a fake criService for test.
|
||||||
func newTestCRIContainerdService() *criContainerdService {
|
func newTestCRIService() *criService {
|
||||||
return &criContainerdService{
|
return &criService{
|
||||||
config: criconfig.Config{
|
config: criconfig.Config{
|
||||||
RootDir: testRootDir,
|
RootDir: testRootDir,
|
||||||
PluginConfig: criconfig.PluginConfig{
|
PluginConfig: criconfig.PluginConfig{
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
const networkNotReadyReason = "NetworkPluginNotReady"
|
const networkNotReadyReason = "NetworkPluginNotReady"
|
||||||
|
|
||||||
// Status returns the status of the runtime.
|
// 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,
|
// As a containerd plugin, if CRI plugin is serving request,
|
||||||
// containerd must be ready.
|
// containerd must be ready.
|
||||||
runtimeCondition := &runtime.RuntimeCondition{
|
runtimeCondition := &runtime.RuntimeCondition{
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
|
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 == "" {
|
if addr == "" {
|
||||||
a, err := k8snet.ChooseBindAddress(nil)
|
a, err := k8snet.ChooseBindAddress(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -46,10 +46,10 @@ func newStreamServer(c *criContainerdService, addr, port string) (streaming.Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
type streamRuntime struct {
|
type streamRuntime struct {
|
||||||
c *criContainerdService
|
c *criService
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStreamRuntime(c *criContainerdService) streaming.Runtime {
|
func newStreamRuntime(c *criService) streaming.Runtime {
|
||||||
return &streamRuntime{c: c}
|
return &streamRuntime{c: c}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,6 @@ import (
|
|||||||
|
|
||||||
// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
|
// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
|
||||||
// TODO(random-liu): Figure out how to handle pod cidr in the cri plugin.
|
// 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
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Version returns the runtime name, runtime version and runtime API version.
|
// 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{
|
return &runtime.VersionResponse{
|
||||||
Version: kubeAPIVersion,
|
Version: kubeAPIVersion,
|
||||||
RuntimeName: containerName,
|
RuntimeName: containerName,
|
||||||
|
Loading…
Reference in New Issue
Block a user