From 2224f6d63f5a203d84df3ac733549f48fa46d60f Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Fri, 22 Mar 2024 10:13:23 +0800 Subject: [PATCH] runtime: support to configure CreateContainer timeout in annotation Support to configure CreateContainerRequestTimeout in the annotations. e.g.: annotations: "io.katacontainers.config.runtime.create_container_timeout": "300" Note: The effective timeout is determined by the lesser of two values: runtime-request-timeout from kubelet config (https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/#:~:text=runtime%2Drequest%2Dtimeout) and create_container_timeout. In essence, the timeout used for guest pull=runtime-request-timeout --- src/runtime/pkg/katautils/config.go | 2 ++ src/runtime/pkg/oci/utils.go | 12 ++++++++++++ src/runtime/pkg/oci/utils_test.go | 2 ++ src/runtime/virtcontainers/kata_agent.go | 5 +++++ .../virtcontainers/pkg/annotations/annotations.go | 3 +++ src/runtime/virtcontainers/sandbox.go | 4 ++++ 6 files changed, 28 insertions(+) diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index f7782ed1f0..997b83ed2d 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -186,6 +186,7 @@ type runtime struct { StaticSandboxResourceMgmt bool `toml:"static_sandbox_resource_mgmt"` EnablePprof bool `toml:"enable_pprof"` DisableGuestEmptyDir bool `toml:"disable_guest_empty_dir"` + CreateContainerTimeout uint64 `toml:"create_container_timeout"` } type agent struct { @@ -1569,6 +1570,7 @@ func LoadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat config.JaegerEndpoint = tomlConf.Runtime.JaegerEndpoint config.JaegerUser = tomlConf.Runtime.JaegerUser config.JaegerPassword = tomlConf.Runtime.JaegerPassword + config.CreateContainerTimeout = tomlConf.Runtime.CreateContainerTimeout for _, f := range tomlConf.Runtime.Experimental { feature := exp.Get(f) if feature == nil { diff --git a/src/runtime/pkg/oci/utils.go b/src/runtime/pkg/oci/utils.go index 08759c2066..b07951fdfe 100644 --- a/src/runtime/pkg/oci/utils.go +++ b/src/runtime/pkg/oci/utils.go @@ -156,6 +156,10 @@ type RuntimeConfig struct { // Determines if Kata creates emptyDir on the guest DisableGuestEmptyDir bool + + // CreateContainer timeout which, if provided, indicates the createcontainer request timeout + // needed for the workload ( Mostly used for pulling images in the guest ) + CreateContainerTimeout uint64 } // AddKernelParam allows the addition of new kernel parameters to an existing @@ -864,6 +868,12 @@ func addRuntimeConfigOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig, r return err } + if err := newAnnotationConfiguration(ocispec, vcAnnotations.CreateContainerTimeout).setUint(func(createContainerTimeout uint64) { + sbConfig.CreateContainerTimeout = createContainerTimeout + }); err != nil { + return err + } + if err := newAnnotationConfiguration(ocispec, vcAnnotations.EnableVCPUsPinning).setBool(func(enableVCPUsPinning bool) { sbConfig.EnableVCPUsPinning = enableVCPUsPinning }); err != nil { @@ -1007,6 +1017,8 @@ func SandboxConfig(ocispec specs.Spec, runtime RuntimeConfig, bundlePath, cid st GuestSeLinuxLabel: runtime.GuestSeLinuxLabel, Experimental: runtime.Experimental, + + CreateContainerTimeout: runtime.CreateContainerTimeout, } if err := addAnnotations(ocispec, &sandboxConfig, runtime); err != nil { diff --git a/src/runtime/pkg/oci/utils_test.go b/src/runtime/pkg/oci/utils_test.go index 778db87b55..1f53b831ad 100644 --- a/src/runtime/pkg/oci/utils_test.go +++ b/src/runtime/pkg/oci/utils_test.go @@ -810,12 +810,14 @@ func TestAddRuntimeAnnotations(t *testing.T) { ocispec.Annotations[vcAnnotations.SandboxCgroupOnly] = "true" ocispec.Annotations[vcAnnotations.DisableNewNetNs] = "true" ocispec.Annotations[vcAnnotations.InterNetworkModel] = "macvtap" + ocispec.Annotations[vcAnnotations.CreateContainerTimeout] = "100" addAnnotations(ocispec, &config, runtimeConfig) assert.Equal(config.DisableGuestSeccomp, true) assert.Equal(config.SandboxCgroupOnly, true) assert.Equal(config.NetworkConfig.DisableNewNetwork, true) assert.Equal(config.NetworkConfig.InterworkingModel, vc.NetXConnectMacVtapModel) + assert.Equal(config.CreateContainerTimeout, uint64(100)) } func TestRegexpContains(t *testing.T) { diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 83bde40df1..34e4b39700 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -377,6 +377,11 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config KataAgent k.kmodules = config.KernelModules k.dialTimout = config.DialTimeout + createContainerRequestTimeout = time.Duration(sandbox.config.CreateContainerTimeout) * time.Second + k.Logger().WithFields(logrus.Fields{ + "createContainerRequestTimeout": fmt.Sprintf("%+v", createContainerRequestTimeout), + }).Info("The createContainerRequestTimeout has been set ") + return disableVMShutdown, nil } diff --git a/src/runtime/virtcontainers/pkg/annotations/annotations.go b/src/runtime/virtcontainers/pkg/annotations/annotations.go index 03498fef75..2b9cfbdd56 100644 --- a/src/runtime/virtcontainers/pkg/annotations/annotations.go +++ b/src/runtime/virtcontainers/pkg/annotations/annotations.go @@ -271,6 +271,9 @@ const ( // VfioMode is a sandbox annotation to specify how attached VFIO devices should be treated // Overrides the runtime.vfio_mode parameter in the global configuration.toml VfioMode = kataAnnotRuntimePrefix + "vfio_mode" + + // CreateContainerTimeout is a sandbox annotaion that sets the create container timeout. + CreateContainerTimeout = kataAnnotRuntimePrefix + "create_container_timeout" ) // Agent related annotations diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index bff8b6b9b0..4a9d9e698d 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -182,6 +182,10 @@ type SandboxConfig struct { // EnableVCPUsPinning controls whether each vCPU thread should be scheduled to a fixed CPU EnableVCPUsPinning bool + + // Create container timeout which, if provided, indicates the create container timeout + // needed for the workload(s) + CreateContainerTimeout uint64 } // valid checks that the sandbox configuration is valid.