mirror of https://github.com/k3s-io/k3s
Merge pull request #56971 from derekwaynecarr/limit-range-ignore-terminating-pods
Automatic merge from submit-queue (batch tested with PRs 56971, 57570, 57830, 57742). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. LimitRange ignores objects previously marked for deletion **What this PR does / why we need it**: A `LimitRange` added to a namespace after it has pods can prevent terminating pods from being deleted if they do not conform to the min/max criteria. xref https://bugzilla.redhat.com/show_bug.cgi?id=1509309 Fixes https://github.com/kubernetes/kubernetes/issues/57201 ```release-note NONE ```pull/6/head
commit
cb6b88ffc6
|
@ -113,6 +113,18 @@ func (l *LimitRanger) runLimitFunc(a admission.Attributes, limitFn func(limitRan
|
|||
}
|
||||
}
|
||||
|
||||
// ignore all objects marked for deletion
|
||||
oldObj := a.GetOldObject()
|
||||
if oldObj != nil {
|
||||
oldAccessor, err := meta.Accessor(oldObj)
|
||||
if err != nil {
|
||||
return admission.NewForbidden(a, err)
|
||||
}
|
||||
if oldAccessor.GetDeletionTimestamp() != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
items, err := l.GetLimitRanges(a)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -733,6 +733,15 @@ func TestLimitRangerAdmitPod(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Should have ignored calls to any subresource of pod %v", err)
|
||||
}
|
||||
|
||||
// a pod that is undergoing termination should never be blocked
|
||||
terminatingPod := validPod("terminatingPod", 1, api.ResourceRequirements{})
|
||||
now := metav1.Now()
|
||||
terminatingPod.DeletionTimestamp = &now
|
||||
err = handler.Validate(admission.NewAttributesRecord(&terminatingPod, &terminatingPod, api.Kind("Pod").WithVersion("version"), limitRange.Namespace, "terminatingPod", api.Resource("pods").WithVersion("version"), "", admission.Update, nil))
|
||||
if err != nil {
|
||||
t.Errorf("LimitRange should ignore a pod marked for termination")
|
||||
}
|
||||
}
|
||||
|
||||
// newMockClientForTest creates a mock client that returns a client configured for the specified list of limit ranges
|
||||
|
|
Loading…
Reference in New Issue