@@ -26,6 +26,7 @@ import (
26
26
"github.com/containerd/log"
27
27
"github.com/pelletier/go-toml/v2"
28
28
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
29
+ "k8s.io/kubelet/pkg/cri/streaming"
29
30
30
31
runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
31
32
runcoptions "github.com/containerd/containerd/v2/core/runtime/v2/runc/options"
@@ -312,33 +313,18 @@ type ImageConfig struct {
312
313
StatsCollectPeriod int `toml:"stats_collect_period" json:"statsCollectPeriod"`
313
314
}
314
315
315
- // PluginConfig contains toml config related to CRI plugin,
316
+ // RuntimeConfig contains toml config related to CRI plugin,
316
317
// it is a subset of Config.
317
- type PluginConfig struct {
318
+ type RuntimeConfig struct {
318
319
// ContainerdConfig contains config related to containerd
319
320
ContainerdConfig `toml:"containerd" json:"containerd"`
320
321
// CniConfig contains config related to cni
321
322
CniConfig `toml:"cni" json:"cni"`
322
- // DisableTCPService disables serving CRI on the TCP server.
323
- DisableTCPService bool `toml:"disable_tcp_service" json:"disableTCPService"`
324
- // StreamServerAddress is the ip address streaming server is listening on.
325
- StreamServerAddress string `toml:"stream_server_address" json:"streamServerAddress"`
326
- // StreamServerPort is the port streaming server is listening on.
327
- StreamServerPort string `toml:"stream_server_port" json:"streamServerPort"`
328
- // StreamIdleTimeout is the maximum time a streaming connection
329
- // can be idle before the connection is automatically closed.
330
- // The string is in the golang duration format, see:
331
- // https://golang.org/pkg/time/#ParseDuration
332
- StreamIdleTimeout string `toml:"stream_idle_timeout" json:"streamIdleTimeout"`
333
323
// EnableSelinux indicates to enable the selinux support.
334
324
EnableSelinux bool `toml:"enable_selinux" json:"enableSelinux"`
335
325
// SelinuxCategoryRange allows the upper bound on the category range to be set.
336
326
// If not specified or set to 0, defaults to 1024 from the selinux package.
337
327
SelinuxCategoryRange int `toml:"selinux_category_range" json:"selinuxCategoryRange"`
338
- // EnableTLSStreaming indicates to enable the TLS streaming support.
339
- EnableTLSStreaming bool `toml:"enable_tls_streaming" json:"enableTLSStreaming"`
340
- // X509KeyPairStreaming is a x509 key pair used for TLS streaming
341
- X509KeyPairStreaming `toml:"x509_key_pair_streaming" json:"x509KeyPairStreaming"`
342
328
// MaxContainerLogLineSize is the maximum log line size in bytes for a container.
343
329
// Log line longer than the limit will be split into multiple lines. Non-positive
344
330
// value means no limit.
@@ -418,10 +404,10 @@ type X509KeyPairStreaming struct {
418
404
TLSKeyFile string `toml:"tls_key_file" json:"tlsKeyFile"`
419
405
}
420
406
421
- // Config contains all configurations for cri server .
407
+ // Config contains all configurations for CRI runtime plugin .
422
408
type Config struct {
423
- // PluginConfig is the config for CRI plugin .
424
- PluginConfig
409
+ // RuntimeConfig is the config for CRI runtime .
410
+ RuntimeConfig
425
411
// ContainerdRootDir is the root directory path for containerd.
426
412
ContainerdRootDir string `json:"containerdRootDir"`
427
413
// ContainerdEndpoint is the containerd endpoint path.
@@ -433,6 +419,25 @@ type Config struct {
433
419
StateDir string `json:"stateDir"`
434
420
}
435
421
422
+ // ServerConfig contains all the configuration for the CRI API server.
423
+ type ServerConfig struct {
424
+ // DisableTCPService disables serving CRI on the TCP server.
425
+ DisableTCPService bool `toml:"disable_tcp_service" json:"disableTCPService"`
426
+ // StreamServerAddress is the ip address streaming server is listening on.
427
+ StreamServerAddress string `toml:"stream_server_address" json:"streamServerAddress"`
428
+ // StreamServerPort is the port streaming server is listening on.
429
+ StreamServerPort string `toml:"stream_server_port" json:"streamServerPort"`
430
+ // StreamIdleTimeout is the maximum time a streaming connection
431
+ // can be idle before the connection is automatically closed.
432
+ // The string is in the golang duration format, see:
433
+ // https://golang.org/pkg/time/#ParseDuration
434
+ StreamIdleTimeout string `toml:"stream_idle_timeout" json:"streamIdleTimeout"`
435
+ // EnableTLSStreaming indicates to enable the TLS streaming support.
436
+ EnableTLSStreaming bool `toml:"enable_tls_streaming" json:"enableTLSStreaming"`
437
+ // X509KeyPairStreaming is a x509 key pair used for TLS streaming
438
+ X509KeyPairStreaming `toml:"x509_key_pair_streaming" json:"x509KeyPairStreaming"`
439
+ }
440
+
436
441
const (
437
442
// RuntimeUntrusted is the implicit runtime defined for ContainerdConfig.UntrustedWorkloadRuntime
438
443
RuntimeUntrusted = "untrusted"
@@ -494,8 +499,8 @@ func ValidateImageConfig(ctx context.Context, c *ImageConfig) ([]deprecation.War
494
499
return warnings , nil
495
500
}
496
501
497
- // ValidatePluginConfig validates the given plugin configuration.
498
- func ValidatePluginConfig (ctx context.Context , c * PluginConfig ) ([]deprecation.Warning , error ) {
502
+ // ValidateRuntimeConfig validates the given runtime configuration.
503
+ func ValidateRuntimeConfig (ctx context.Context , c * RuntimeConfig ) ([]deprecation.Warning , error ) {
499
504
var warnings []deprecation.Warning
500
505
if c .ContainerdConfig .Runtimes == nil {
501
506
c .ContainerdConfig .Runtimes = make (map [string ]Runtime )
@@ -520,13 +525,6 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) ([]deprecation.W
520
525
}
521
526
}
522
527
523
- // Validation for stream_idle_timeout
524
- if c .StreamIdleTimeout != "" {
525
- if _ , err := time .ParseDuration (c .StreamIdleTimeout ); err != nil {
526
- return warnings , fmt .Errorf ("invalid stream idle timeout: %w" , err )
527
- }
528
- }
529
-
530
528
// Validation for drain_exec_sync_io_timeout
531
529
if c .DrainExecSyncIOTimeout != "" {
532
530
if _ , err := time .ParseDuration (c .DrainExecSyncIOTimeout ); err != nil {
@@ -539,6 +537,18 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) ([]deprecation.W
539
537
return warnings , nil
540
538
}
541
539
540
+ // ValidateServerConfig validates the given server configuration.
541
+ func ValidateServerConfig (ctx context.Context , c * ServerConfig ) ([]deprecation.Warning , error ) {
542
+ var warnings []deprecation.Warning
543
+ // Validation for stream_idle_timeout
544
+ if c .StreamIdleTimeout != "" {
545
+ if _ , err := time .ParseDuration (c .StreamIdleTimeout ); err != nil {
546
+ return warnings , fmt .Errorf ("invalid stream idle timeout: %w" , err )
547
+ }
548
+ }
549
+ return warnings , nil
550
+ }
551
+
542
552
func (config * Config ) GetSandboxRuntime (podSandboxConfig * runtime.PodSandboxConfig , runtimeHandler string ) (Runtime , error ) {
543
553
if untrustedWorkload (podSandboxConfig ) {
544
554
// If the untrusted annotation is provided, runtimeHandler MUST be empty.
@@ -627,3 +637,17 @@ func getRuntimeOptionsType(t string) interface{} {
627
637
return & runtimeoptions.Options {}
628
638
}
629
639
}
640
+
641
+ func DefaultServerConfig () ServerConfig {
642
+ return ServerConfig {
643
+ DisableTCPService : true ,
644
+ StreamServerAddress : "127.0.0.1" ,
645
+ StreamServerPort : "0" ,
646
+ StreamIdleTimeout : streaming .DefaultConfig .StreamIdleTimeout .String (), // 4 hour
647
+ EnableTLSStreaming : false ,
648
+ X509KeyPairStreaming : X509KeyPairStreaming {
649
+ TLSKeyFile : "" ,
650
+ TLSCertFile : "" ,
651
+ },
652
+ }
653
+ }
0 commit comments