diff --git a/docs/config.md b/docs/config.md index c19d53a16..ffce770cd 100644 --- a/docs/config.md +++ b/docs/config.md @@ -15,6 +15,10 @@ version = 2 # The 'plugins."io.containerd.grpc.v1.cri"' table contains all of the server options. [plugins."io.containerd.grpc.v1.cri"] + # disable_tcp_service disables serving CRI on the TCP server. + # Note that a TCP server is enabled for containerd if TCPAddress is set in section [grpc]. + disable_tcp_service = true + # stream_server_address is the ip address streaming server is listening on. stream_server_address = "127.0.0.1" diff --git a/pkg/config/config.go b/pkg/config/config.go index a6ff387cd..d6c8dbfad 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -138,6 +138,8 @@ type PluginConfig struct { CniConfig `toml:"cni" json:"cni"` // Registry contains config related to the registry Registry Registry `toml:"registry" json:"registry"` + // DisableTCPService disables serving CRI on the TCP server. + DisableTCPService bool `toml:"disable_tcp_service" json:"disableTCPService"` // StreamServerAddress is the ip address streaming server is listening on. StreamServerAddress string `toml:"stream_server_address" json:"streamServerAddress"` // StreamServerPort is the port streaming server is listening on. @@ -219,6 +221,7 @@ func DefaultConfig() PluginConfig { }, }, }, + DisableTCPService: true, StreamServerAddress: "127.0.0.1", StreamServerPort: "0", StreamIdleTimeout: streaming.DefaultConfig.StreamIdleTimeout.String(), // 4 hour diff --git a/pkg/server/service.go b/pkg/server/service.go index ab22ddf1c..cc14e2f71 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -171,9 +171,15 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi // Register registers all required services onto a specific grpc server. // This is used by containerd cri plugin. func (c *criService) Register(s *grpc.Server) error { - instrumented := newInstrumentedService(c) - runtime.RegisterRuntimeServiceServer(s, instrumented) - runtime.RegisterImageServiceServer(s, instrumented) + return c.register(s) +} + +// RegisterTCP register all required services onto a GRPC server on TCP. +// This is used by containerd CRI plugin. +func (c *criService) RegisterTCP(s *grpc.Server) error { + if !c.config.DisableTCPService { + return c.register(s) + } return nil } @@ -267,6 +273,13 @@ func (c *criService) Close() error { return nil } +func (c *criService) register(s *grpc.Server) error { + instrumented := newInstrumentedService(c) + runtime.RegisterRuntimeServiceServer(s, instrumented) + runtime.RegisterImageServiceServer(s, instrumented) + return nil +} + // imageFSPath returns containerd image filesystem path. // Note that if containerd changes directory layout, we also needs to change this. func imageFSPath(rootDir, snapshotter string) string {