@@ -448,24 +448,27 @@ func shouldIgnore(a admission.Attributes) (bool, error) {
448
448
return false , admission .NewForbidden (a , fmt .Errorf ("object was marked as kind pod but was unable to be converted: %v" , a .GetOldObject ()))
449
449
}
450
450
451
- // never ignore any spec changes
452
- if ! kapihelper .Semantic .DeepEqual (pod .Spec , oldPod .Spec ) {
451
+ // Create deep copies to avoid mutating the original objects
452
+ podCopy := pod .DeepCopy ()
453
+ // Skip SchedulingGates when comparing specs
454
+ podCopy .Spec .SchedulingGates = oldPod .Spec .SchedulingGates
455
+ if ! kapihelper .Semantic .DeepEqual (podCopy .Spec , oldPod .Spec ) {
453
456
return false , nil
454
457
}
455
458
456
459
// see if we are only doing meta changes that should be ignored during admission
457
460
// for example, the OVN controller adds informative networking annotations that shouldn't cause the pod to go through admission again
458
- if shouldIgnoreMetaChanges (pod , oldPod ) {
461
+ if shouldIgnoreMetaChanges (podCopy , oldPod ) {
459
462
return true , nil
460
463
}
461
464
}
462
465
463
466
return false , nil
464
467
}
465
468
466
- func shouldIgnoreMetaChanges (newPod , oldPod * coreapi.Pod ) bool {
469
+ func shouldIgnoreMetaChanges (newPodCopy , oldPod * coreapi.Pod ) bool {
467
470
// check if we're adding or changing only annotations from the ignore list
468
- for key , newVal := range newPod .ObjectMeta .Annotations {
471
+ for key , newVal := range newPodCopy .ObjectMeta .Annotations {
469
472
if oldVal , ok := oldPod .ObjectMeta .Annotations [key ]; ok && newVal == oldVal {
470
473
continue
471
474
}
@@ -477,7 +480,7 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
477
480
478
481
// check if we're removing only annotations from the ignore list
479
482
for key := range oldPod .ObjectMeta .Annotations {
480
- if _ , ok := newPod .ObjectMeta .Annotations [key ]; ok {
483
+ if _ , ok := newPodCopy .ObjectMeta .Annotations [key ]; ok {
481
484
continue
482
485
}
483
486
@@ -486,7 +489,6 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
486
489
}
487
490
}
488
491
489
- newPodCopy := newPod .DeepCopyObject ()
490
492
newPodCopyMeta , err := meta .Accessor (newPodCopy )
491
493
if err != nil {
492
494
return false
0 commit comments