Skip to content

Commit c7c6bb9

Browse files
authored
Merge pull request containerd#9477 from lengrongfu/feat/add-cgroupParent-to-integration
add get cgroupdriver from RuntimeConfig to integration
2 parents 287b4ce + dffeea4 commit c7c6bb9

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

integration/cri-api/pkg/apis/services.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ type RuntimeService interface {
121121
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error
122122
// Status returns the status of the runtime.
123123
Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error)
124+
// RuntimeConfig returns configuration information of the runtime.
125+
// A couple of notes:
126+
// - The RuntimeConfigRequest object is not to be confused with the contents of UpdateRuntimeConfigRequest.
127+
// The former is for having runtime tell Kubelet what to do, the latter vice versa.
128+
// - It is the expectation of the Kubelet that these fields are static for the lifecycle of the Kubelet.
129+
// The Kubelet will not re-request the RuntimeConfiguration after startup, and CRI implementations should
130+
// avoid updating them without a full node reboot.
131+
RuntimeConfig(in *runtimeapi.RuntimeConfigRequest, opts ...grpc.CallOption) (*runtimeapi.RuntimeConfigResponse, error)
124132
}
125133

126134
// ImageManagerService interface should be implemented by a container image

integration/main_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ import (
5151
"google.golang.org/grpc"
5252
"google.golang.org/grpc/credentials/insecure"
5353
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
54+
"k8s.io/klog/v2"
5455
)
5556

5657
const (
57-
timeout = 1 * time.Minute
58-
k8sNamespace = constants.K8sContainerdNamespace
58+
timeout = 1 * time.Minute
59+
k8sNamespace = constants.K8sContainerdNamespace
60+
defaultCgroupSystemdParent = "/containerd-test.slice"
5961
)
6062

6163
var (
@@ -208,6 +210,13 @@ func WithPodLabels(kvs map[string]string) PodSandboxOpts {
208210

209211
// PodSandboxConfig generates a pod sandbox config for test.
210212
func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandboxConfig {
213+
var cgroupParent string
214+
runtimeConfig, err := runtimeService.RuntimeConfig(&runtime.RuntimeConfigRequest{})
215+
if err != nil {
216+
klog.Errorf("runtime service call RuntimeConfig error %s", err.Error())
217+
} else if runtimeConfig.GetLinux().GetCgroupDriver() == runtime.CgroupDriver_SYSTEMD {
218+
cgroupParent = defaultCgroupSystemdParent
219+
}
211220
config := &runtime.PodSandboxConfig{
212221
Metadata: &runtime.PodSandboxMetadata{
213222
Name: name,
@@ -216,7 +225,9 @@ func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandb
216225
Uid: util.GenerateID(),
217226
Namespace: Randomize(ns),
218227
},
219-
Linux: &runtime.LinuxPodSandboxConfig{},
228+
Linux: &runtime.LinuxPodSandboxConfig{
229+
CgroupParent: cgroupParent,
230+
},
220231
Annotations: make(map[string]string),
221232
Labels: make(map[string]string),
222233
}

integration/remote/remote_runtime.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,15 @@ func (r *RuntimeService) Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeSta
535535
return resp.Status, nil
536536
}
537537

538+
// RuntimeConfig returns the CgroupDriver of the runtime.
539+
func (r *RuntimeService) RuntimeConfig(in *runtimeapi.RuntimeConfigRequest, opts ...grpc.CallOption) (*runtimeapi.RuntimeConfigResponse, error) {
540+
klog.V(10).Infof("[RuntimeService] RuntimeConfig (timeout=%v)", r.timeout)
541+
ctx, cancel := getContextWithTimeout(r.timeout)
542+
defer cancel()
543+
runtimeConfig, err := r.runtimeClient.RuntimeConfig(ctx, in)
544+
return runtimeConfig, err
545+
}
546+
538547
// ContainerStats returns the stats of the container.
539548
func (r *RuntimeService) ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error) {
540549
klog.V(10).Infof("[RuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)

0 commit comments

Comments
 (0)