From 694c998fb147d1972098e1c9bfbc1239f5b3b962 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 5 Aug 2025 21:42:51 +0000 Subject: [PATCH] add 'operation' field to lifecycle.PodAdmitAttributes --- pkg/kubelet/allocation/allocation_manager.go | 8 ++++---- pkg/kubelet/lifecycle/interfaces.go | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/allocation/allocation_manager.go b/pkg/kubelet/allocation/allocation_manager.go index 074601feca3..d3b9e51bad5 100644 --- a/pkg/kubelet/allocation/allocation_manager.go +++ b/pkg/kubelet/allocation/allocation_manager.go @@ -554,7 +554,7 @@ func (m *manager) AddPod(activePods []*v1.Pod, pod *v1.Pod) (bool, string, strin // Check if we can admit the pod; if so, update the allocation. allocatedPods := m.getAllocatedPods(activePods) - ok, reason, message := m.canAdmitPod(logger, allocatedPods, pod) + ok, reason, message := m.canAdmitPod(logger, allocatedPods, pod, lifecycle.AddOperation) if ok && utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) { // Checkpoint the resource values at which the Pod has been admitted or resized. @@ -686,12 +686,12 @@ func disallowResizeForSwappableContainers(runtime kubecontainer.Runtime, desired // the pod cannot be admitted. // allocatedPods should represent the pods that have already been admitted, along with their // admitted (allocated) resources. -func (m *manager) canAdmitPod(logger klog.Logger, allocatedPods []*v1.Pod, pod *v1.Pod) (bool, string, string) { +func (m *manager) canAdmitPod(logger klog.Logger, allocatedPods []*v1.Pod, pod *v1.Pod, operation lifecycle.Operation) (bool, string, string) { // Filter out the pod being evaluated. allocatedPods = slices.DeleteFunc(allocatedPods, func(p *v1.Pod) bool { return p.UID == pod.UID }) // If any handler rejects, the pod is rejected. - attrs := &lifecycle.PodAdmitAttributes{Pod: pod, OtherPods: allocatedPods} + attrs := &lifecycle.PodAdmitAttributes{Pod: pod, OtherPods: allocatedPods, Operation: operation} for _, podAdmitHandler := range m.admitHandlers { if result := podAdmitHandler.Admit(attrs); !result.Admit { logger.Info("Pod admission denied", "podUID", attrs.Pod.UID, "pod", klog.KObj(attrs.Pod), "reason", result.Reason, "message", result.Message) @@ -745,7 +745,7 @@ func (m *manager) canResizePod(logger klog.Logger, allocatedPods []*v1.Pod, pod return false, v1.PodReasonInfeasible, msg } - if ok, failReason, failMessage := m.canAdmitPod(logger, allocatedPods, pod); !ok { + if ok, failReason, failMessage := m.canAdmitPod(logger, allocatedPods, pod, lifecycle.ResizeOperation); !ok { // Log reason and return. logger.V(3).Info("Resize cannot be accommodated", "pod", klog.KObj(pod), "reason", failReason, "message", failMessage) return false, v1.PodReasonDeferred, failMessage diff --git a/pkg/kubelet/lifecycle/interfaces.go b/pkg/kubelet/lifecycle/interfaces.go index 3be7adade54..864c69dc8fc 100644 --- a/pkg/kubelet/lifecycle/interfaces.go +++ b/pkg/kubelet/lifecycle/interfaces.go @@ -16,7 +16,7 @@ limitations under the License. package lifecycle -import "k8s.io/api/core/v1" +import v1 "k8s.io/api/core/v1" // PodAdmitAttributes is the context for a pod admission decision. // The member fields of this struct should never be mutated. @@ -25,8 +25,20 @@ type PodAdmitAttributes struct { Pod *v1.Pod // all pods bound to the kubelet excluding the pod being evaluated OtherPods []*v1.Pod + // the operation being performed; either "add" or "resize" + Operation Operation } +// Operation represents the type of operation being performed on a pod. +type Operation string + +const ( + // AddOperation indicates that the pod is being added to the kubelet. + AddOperation Operation = "add" + // ResizeOperation indicates that the pod is being resized. + ResizeOperation Operation = "resize" +) + // PodAdmitResult provides the result of a pod admission decision. type PodAdmitResult struct { // if true, the pod should be admitted.