mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
add 'operation' field to lifecycle.PodAdmitAttributes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user