From b27c303ac24fac02ef39ec9ec36fbdfc2767086e Mon Sep 17 00:00:00 2001 From: Filipe Xavier Date: Wed, 6 Nov 2024 08:59:43 -0300 Subject: [PATCH] update cri-api runtime interface and cri-client add new method --- .../src/k8s.io/cri-api/pkg/apis/services.go | 6 ++ .../pkg/apis/testing/fake_runtime_service.go | 13 ++++ .../cri-client/pkg/fake/fake_runtime.go | 5 ++ .../k8s.io/cri-client/pkg/remote_runtime.go | 17 +++++ .../criproxy/proxy_runtime_service.go | 68 +++++++++++-------- 5 files changed, 80 insertions(+), 29 deletions(-) diff --git a/staging/src/k8s.io/cri-api/pkg/apis/services.go b/staging/src/k8s.io/cri-api/pkg/apis/services.go index 03a068c4224..58cee8c14c8 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/services.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/services.go @@ -82,6 +82,12 @@ type PodSandboxManager interface { ListPodSandbox(ctx context.Context, filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) // PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address. PortForward(ctx context.Context, request *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) + // UpdatePodSandboxResources synchronously updates the PodSandboxConfig with + // the pod-level resource configuration. This method is called _after_ the + // Kubelet reconfigures the pod-level cgroups. + // This request is treated as best effort, and failure will not block the + // Kubelet with proceeding with a resize. + UpdatePodSandboxResources(ctx context.Context, request *runtimeapi.UpdatePodSandboxResourcesRequest) (*runtimeapi.UpdatePodSandboxResourcesResponse, error) } // ContainerStatsManager contains methods for retrieving the container diff --git a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go index 56effd29802..245fba577a0 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go @@ -794,3 +794,16 @@ func (r *FakeRuntimeService) RuntimeConfig(_ context.Context) (*runtimeapi.Runti return &runtimeapi.RuntimeConfigResponse{Linux: r.FakeLinuxConfiguration}, nil } + +// UpdatePodSandboxResources returns the container resource in the FakeRuntimeService. +func (r *FakeRuntimeService) UpdatePodSandboxResources(context.Context, *runtimeapi.UpdatePodSandboxResourcesRequest) (*runtimeapi.UpdatePodSandboxResourcesResponse, error) { + r.Lock() + defer r.Unlock() + + r.Called = append(r.Called, "UpdatePodSandboxResources") + if err := r.popError("UpdatePodSandboxResources"); err != nil { + return nil, err + } + + return &runtimeapi.UpdatePodSandboxResourcesResponse{}, nil +} diff --git a/staging/src/k8s.io/cri-client/pkg/fake/fake_runtime.go b/staging/src/k8s.io/cri-client/pkg/fake/fake_runtime.go index 3c1c391cae4..fd9e778067f 100644 --- a/staging/src/k8s.io/cri-client/pkg/fake/fake_runtime.go +++ b/staging/src/k8s.io/cri-client/pkg/fake/fake_runtime.go @@ -366,3 +366,8 @@ func (f *RemoteRuntime) RuntimeConfig(ctx context.Context, req *kubeapi.RuntimeC return resp, nil } + +// UpdatePodSandboxResources synchronously updates the PodSandboxConfig. +func (f *RemoteRuntime) UpdatePodSandboxResources(ctx context.Context, req *kubeapi.UpdatePodSandboxResourcesRequest) (*kubeapi.UpdatePodSandboxResourcesResponse, error) { + return f.RuntimeService.UpdatePodSandboxResources(ctx, req) +} diff --git a/staging/src/k8s.io/cri-client/pkg/remote_runtime.go b/staging/src/k8s.io/cri-client/pkg/remote_runtime.go index aa1518e0acc..f5f3970beff 100644 --- a/staging/src/k8s.io/cri-client/pkg/remote_runtime.go +++ b/staging/src/k8s.io/cri-client/pkg/remote_runtime.go @@ -610,6 +610,23 @@ func (r *remoteRuntimeService) portForwardV1(ctx context.Context, req *runtimeap return resp, nil } +// UpdatePodSandboxResources synchronously updates the PodSandboxConfig with +// the pod-level resource configuration. +func (r *remoteRuntimeService) UpdatePodSandboxResources(ctx context.Context, req *runtimeapi.UpdatePodSandboxResourcesRequest) (*runtimeapi.UpdatePodSandboxResourcesResponse, error) { + r.log(10, "[RemoteRuntimeService] UpdatePodSandboxResources", "PodSandboxId", req.PodSandboxId, "timeout", r.timeout) + ctx, cancel := context.WithTimeout(ctx, r.timeout) + defer cancel() + + resp, err := r.runtimeClient.UpdatePodSandboxResources(ctx, req) + if err != nil { + r.logErr(err, "UpdatePodSandboxResources from runtime service failed", "podSandboxID", req.PodSandboxId) + return nil, err + } + r.log(10, "[RemoteRuntimeService] UpdatePodSandboxResources Response", "podSandboxID", req.PodSandboxId) + + return resp, nil +} + // UpdateRuntimeConfig updates the config of a runtime service. The only // update payload currently supported is the pod CIDR assigned to a node, // and the runtime service just proxies it down to the network plugin. diff --git a/test/e2e_node/criproxy/proxy_runtime_service.go b/test/e2e_node/criproxy/proxy_runtime_service.go index cc17e970c6b..f2febf293fb 100644 --- a/test/e2e_node/criproxy/proxy_runtime_service.go +++ b/test/e2e_node/criproxy/proxy_runtime_service.go @@ -34,35 +34,36 @@ import ( ) const ( - Version = "Version" - RunPodSandbox = "RunPodSandbox" - StopPodSandbox = "StopPodSandbox" - RemovePodSandbox = "RemovePodSandbox" - PodSandboxStatus = "PodSandboxStatus" - ListPodSandbox = "ListPodSandbox" - CreateContainer = "CreateContainer" - StartContainer = "StartContainer" - StopContainer = "StopContainer" - RemoveContainer = "RemoveContainer" - ListContainers = "ListContainers" - ContainerStatus = "ContainerStatus" - UpdateContainerResources = "UpdateContainerResources" - ReopenContainerLog = "ReopenContainerLog" - ExecSync = "ExecSync" - Exec = "Exec" - Attach = "Attach" - PortForward = "PortForward" - ContainerStats = "ContainerStats" - ListContainerStats = "ListContainerStats" - PodSandboxStats = "PodSandboxStats" - ListPodSandboxStats = "ListPodSandboxStats" - UpdateRuntimeConfig = "UpdateRuntimeConfig" - Status = "Status" - CheckpointContainer = "CheckpointContainer" - GetContainerEvents = "GetContainerEvents" - ListMetricDescriptors = "ListMetricDescriptors" - ListPodSandboxMetrics = "ListPodSandboxMetrics" - RuntimeConfig = "RuntimeConfig" + Version = "Version" + RunPodSandbox = "RunPodSandbox" + StopPodSandbox = "StopPodSandbox" + RemovePodSandbox = "RemovePodSandbox" + PodSandboxStatus = "PodSandboxStatus" + ListPodSandbox = "ListPodSandbox" + CreateContainer = "CreateContainer" + StartContainer = "StartContainer" + StopContainer = "StopContainer" + RemoveContainer = "RemoveContainer" + ListContainers = "ListContainers" + ContainerStatus = "ContainerStatus" + UpdateContainerResources = "UpdateContainerResources" + ReopenContainerLog = "ReopenContainerLog" + ExecSync = "ExecSync" + Exec = "Exec" + Attach = "Attach" + PortForward = "PortForward" + ContainerStats = "ContainerStats" + ListContainerStats = "ListContainerStats" + PodSandboxStats = "PodSandboxStats" + ListPodSandboxStats = "ListPodSandboxStats" + UpdateRuntimeConfig = "UpdateRuntimeConfig" + Status = "Status" + CheckpointContainer = "CheckpointContainer" + GetContainerEvents = "GetContainerEvents" + ListMetricDescriptors = "ListMetricDescriptors" + ListPodSandboxMetrics = "ListPodSandboxMetrics" + RuntimeConfig = "RuntimeConfig" + UpdatePodSandboxResources = "UpdatePodSandboxResources" ) // AddInjector inject the error or delay to the next call to the RuntimeService. @@ -407,6 +408,15 @@ func (p *RemoteRuntime) UpdateRuntimeConfig(ctx context.Context, req *runtimeapi return &runtimeapi.UpdateRuntimeConfigResponse{}, nil } +// UpdatePodSandboxResources synchronously updates the PodSandboxConfig. +func (p *RemoteRuntime) UpdatePodSandboxResources(ctx context.Context, req *runtimeapi.UpdatePodSandboxResourcesRequest) (*runtimeapi.UpdatePodSandboxResourcesResponse, error) { + if err := p.runInjectors(UpdatePodSandboxResources); err != nil { + return nil, err + } + + return p.runtimeService.UpdatePodSandboxResources(ctx, req) +} + // Status returns the status of the runtime. func (p *RemoteRuntime) Status(ctx context.Context, req *runtimeapi.StatusRequest) (*runtimeapi.StatusResponse, error) { if err := p.runInjectors(Status); err != nil {