mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
LimitRange ignores objects previously marked for deletion
This commit is contained in:
parent
8583b6639d
commit
1748b42b21
@ -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)
|
items, err := l.GetLimitRanges(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -733,6 +733,15 @@ func TestLimitRangerAdmitPod(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Should have ignored calls to any subresource of pod %v", err)
|
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
|
// newMockClientForTest creates a mock client that returns a client configured for the specified list of limit ranges
|
||||||
|
Loading…
Reference in New Issue
Block a user