Merge pull request #9477 from lengrongfu/feat/add-cgroupParent-to-integration
add get cgroupdriver from RuntimeConfig to integration
This commit is contained in:
		| @@ -121,6 +121,14 @@ type RuntimeService interface { | |||||||
| 	UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error | 	UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error | ||||||
| 	// Status returns the status of the runtime. | 	// Status returns the status of the runtime. | ||||||
| 	Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error) | 	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 | // ImageManagerService interface should be implemented by a container image | ||||||
|   | |||||||
| @@ -51,11 +51,13 @@ import ( | |||||||
| 	"google.golang.org/grpc" | 	"google.golang.org/grpc" | ||||||
| 	"google.golang.org/grpc/credentials/insecure" | 	"google.golang.org/grpc/credentials/insecure" | ||||||
| 	runtime "k8s.io/cri-api/pkg/apis/runtime/v1" | 	runtime "k8s.io/cri-api/pkg/apis/runtime/v1" | ||||||
|  | 	"k8s.io/klog/v2" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	timeout      = 1 * time.Minute | 	timeout                    = 1 * time.Minute | ||||||
| 	k8sNamespace = constants.K8sContainerdNamespace | 	k8sNamespace               = constants.K8sContainerdNamespace | ||||||
|  | 	defaultCgroupSystemdParent = "/containerd-test.slice" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| @@ -208,6 +210,13 @@ func WithPodLabels(kvs map[string]string) PodSandboxOpts { | |||||||
|  |  | ||||||
| // PodSandboxConfig generates a pod sandbox config for test. | // PodSandboxConfig generates a pod sandbox config for test. | ||||||
| func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandboxConfig { | 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{ | 	config := &runtime.PodSandboxConfig{ | ||||||
| 		Metadata: &runtime.PodSandboxMetadata{ | 		Metadata: &runtime.PodSandboxMetadata{ | ||||||
| 			Name: name, | 			Name: name, | ||||||
| @@ -216,7 +225,9 @@ func PodSandboxConfig(name, ns string, opts ...PodSandboxOpts) *runtime.PodSandb | |||||||
| 			Uid:       util.GenerateID(), | 			Uid:       util.GenerateID(), | ||||||
| 			Namespace: Randomize(ns), | 			Namespace: Randomize(ns), | ||||||
| 		}, | 		}, | ||||||
| 		Linux:       &runtime.LinuxPodSandboxConfig{}, | 		Linux: &runtime.LinuxPodSandboxConfig{ | ||||||
|  | 			CgroupParent: cgroupParent, | ||||||
|  | 		}, | ||||||
| 		Annotations: make(map[string]string), | 		Annotations: make(map[string]string), | ||||||
| 		Labels:      make(map[string]string), | 		Labels:      make(map[string]string), | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -535,6 +535,15 @@ func (r *RuntimeService) Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeSta | |||||||
| 	return resp.Status, nil | 	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. | // ContainerStats returns the stats of the container. | ||||||
| func (r *RuntimeService) ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error) { | 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) | 	klog.V(10).Infof("[RuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Fu Wei
					Fu Wei