diff --git a/integration/cri-api/pkg/apis/services.go b/integration/cri-api/pkg/apis/services.go index 74591cb42..318e3129a 100644 --- a/integration/cri-api/pkg/apis/services.go +++ b/integration/cri-api/pkg/apis/services.go @@ -121,6 +121,14 @@ type RuntimeService interface { UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error // Status returns the status of the runtime. Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error) + // RuntimeConfig returns configuration information of the runtime. + // A couple of notes: + // - The RuntimeConfigRequest object is not to be confused with the contents of UpdateRuntimeConfigRequest. + // The former is for having runtime tell Kubelet what to do, the latter vice versa. + // - It is the expectation of the Kubelet that these fields are static for the lifecycle of the Kubelet. + // The Kubelet will not re-request the RuntimeConfiguration after startup, and CRI implementations should + // avoid updating them without a full node reboot. + RuntimeConfig(in *runtimeapi.RuntimeConfigRequest, opts ...grpc.CallOption) (*runtimeapi.RuntimeConfigResponse, error) } // ImageManagerService interface should be implemented by a container image diff --git a/integration/main_test.go b/integration/main_test.go index 170a1079c..34877c54e 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -51,11 +51,13 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" runtime "k8s.io/cri-api/pkg/apis/runtime/v1" + "k8s.io/klog/v2" ) const ( - timeout = 1 * time.Minute - k8sNamespace = constants.K8sContainerdNamespace + timeout = 1 * time.Minute + k8sNamespace = constants.K8sContainerdNamespace + defaultCgroupSystemdParent = "/containerd-test.slice" ) var ( @@ -208,6 +210,13 @@ func WithPodLabels(kvs map[string]string) PodSandboxOpts { // PodSandboxConfig generates a pod sandbox config for test. func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandboxConfig { + var cgroupParent string + runtimeConfig, err := runtimeService.RuntimeConfig(&runtime.RuntimeConfigRequest{}) + if err != nil { + klog.Errorf("runtime service call RuntimeConfig error %s", err.Error()) + } else if runtimeConfig.GetLinux().GetCgroupDriver() == runtime.CgroupDriver_SYSTEMD { + cgroupParent = defaultCgroupSystemdParent + } config := &runtime.PodSandboxConfig{ Metadata: &runtime.PodSandboxMetadata{ Name: name, @@ -216,7 +225,9 @@ func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandb Uid: util.GenerateID(), Namespace: Randomize(ns), }, - Linux: &runtime.LinuxPodSandboxConfig{}, + Linux: &runtime.LinuxPodSandboxConfig{ + CgroupParent: cgroupParent, + }, Annotations: make(map[string]string), Labels: make(map[string]string), } diff --git a/integration/remote/remote_runtime.go b/integration/remote/remote_runtime.go index 57d492bba..d602381d9 100644 --- a/integration/remote/remote_runtime.go +++ b/integration/remote/remote_runtime.go @@ -535,6 +535,15 @@ func (r *RuntimeService) Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeSta return resp.Status, nil } +// RuntimeConfig returns the CgroupDriver of the runtime. +func (r *RuntimeService) RuntimeConfig(in *runtimeapi.RuntimeConfigRequest, opts ...grpc.CallOption) (*runtimeapi.RuntimeConfigResponse, error) { + klog.V(10).Infof("[RuntimeService] RuntimeConfig (timeout=%v)", r.timeout) + ctx, cancel := getContextWithTimeout(r.timeout) + defer cancel() + runtimeConfig, err := r.runtimeClient.RuntimeConfig(ctx, in) + return runtimeConfig, err +} + // ContainerStats returns the stats of the container. func (r *RuntimeService) ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error) { klog.V(10).Infof("[RuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)