Skip to content

Commit ebdbf84

Browse files
committed
Ignore updates related to Scheduling Gates
to allow the installation of external operators that manage pod scheduling. Scheduling Gates don't affect pod privileges, so there's no need to block them through SCC admission. Signed-off-by: bmordeha <[email protected]>
1 parent 8d341e9 commit ebdbf84

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

pkg/securitycontextconstraints/sccadmission/admission.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,24 +448,27 @@ func shouldIgnore(a admission.Attributes) (bool, error) {
448448
return false, admission.NewForbidden(a, fmt.Errorf("object was marked as kind pod but was unable to be converted: %v", a.GetOldObject()))
449449
}
450450

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) {
453456
return false, nil
454457
}
455458

456459
// see if we are only doing meta changes that should be ignored during admission
457460
// 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) {
459462
return true, nil
460463
}
461464
}
462465

463466
return false, nil
464467
}
465468

466-
func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
469+
func shouldIgnoreMetaChanges(newPodCopy, oldPod *coreapi.Pod) bool {
467470
// 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 {
469472
if oldVal, ok := oldPod.ObjectMeta.Annotations[key]; ok && newVal == oldVal {
470473
continue
471474
}
@@ -477,7 +480,7 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
477480

478481
// check if we're removing only annotations from the ignore list
479482
for key := range oldPod.ObjectMeta.Annotations {
480-
if _, ok := newPod.ObjectMeta.Annotations[key]; ok {
483+
if _, ok := newPodCopy.ObjectMeta.Annotations[key]; ok {
481484
continue
482485
}
483486

@@ -486,7 +489,6 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
486489
}
487490
}
488491

489-
newPodCopy := newPod.DeepCopyObject()
490492
newPodCopyMeta, err := meta.Accessor(newPodCopy)
491493
if err != nil {
492494
return false

pkg/securitycontextconstraints/sccadmission/admission_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ func TestShouldIgnore(t *testing.T) {
268268
shouldIgnore: true,
269269
admissionAttributes: withStatusUpdate(goodPod()),
270270
},
271+
{
272+
description: "schedulingGates updates should be ignored",
273+
shouldIgnore: true,
274+
admissionAttributes: withUpdate(schedulingGatePod(), "",
275+
func(p *coreapi.Pod) *coreapi.Pod {
276+
p.Spec.SchedulingGates = []coreapi.PodSchedulingGate{}
277+
return p
278+
}),
279+
},
271280
{
272281
description: "don't ignore normal updates",
273282
shouldIgnore: false,
@@ -2008,6 +2017,14 @@ func goodPod() *coreapi.Pod {
20082017
}
20092018
}
20102019

2020+
// schedulingGatePod is empty pod with scheduling gate. schedulingGates modifications
2021+
// should be safely ignored.
2022+
func schedulingGatePod() *coreapi.Pod {
2023+
p := goodPod()
2024+
p.Spec.SchedulingGates = []coreapi.PodSchedulingGate{{Name: "testGate"}}
2025+
return p
2026+
}
2027+
20112028
// windowsPod returns windows pod without any SCCs which are specific to Linux. The admission of Windows pod
20122029
// should be safely ignored.
20132030
func windowsPod() *coreapi.Pod {

0 commit comments

Comments
 (0)