@@ -3,6 +3,7 @@ package psalabelsyncer
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strings"
6
7
7
8
corev1 "k8s.io/api/core/v1"
8
9
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -125,7 +126,7 @@ func NewPodSecurityAdmissionLabelSynchronizationController(
125
126
if ns .Annotations == nil || len (ns .Annotations [securityv1 .UIDRangeAnnotation ]) == 0 {
126
127
return false
127
128
}
128
- return true
129
+ return checkNSControlled ( ns )
129
130
},
130
131
namespaceInformer .Informer (),
131
132
).
@@ -148,6 +149,11 @@ func (c *PodSecurityAdmissionLabelSynchronizationController) sync(ctx context.Co
148
149
return fmt .Errorf (errFmt , qKey , err )
149
150
}
150
151
152
+ if ns .Status .Phase == corev1 .NamespaceTerminating {
153
+ klog .Infof ("skipping synchronizing namespace %q because it is terminating" , ns .Name )
154
+ return nil
155
+ }
156
+
151
157
if err := c .syncNamespace (ctx , controllerContext , ns ); err != nil {
152
158
return fmt .Errorf (errFmt , qKey , err )
153
159
}
@@ -304,17 +310,28 @@ func (c *PodSecurityAdmissionLabelSynchronizationController) saToSCCCAcheEnqueue
304
310
}
305
311
}
306
312
307
- func (c * PodSecurityAdmissionLabelSynchronizationController ) checkNSControlled (ns string ) (bool , error ) {
308
- nsObj , err := c .namespaceLister .Get (ns )
313
+ func (c * PodSecurityAdmissionLabelSynchronizationController ) checkNSControlled (nsName string ) (bool , error ) {
314
+ ns , err := c .namespaceLister .Get (nsName )
309
315
if err != nil {
310
316
return false , err
311
317
}
312
318
313
- if nsObj .Labels [labelSyncControlLabel ] != "false" {
314
- return true , nil
319
+ return checkNSControlled (ns ), nil
320
+
321
+ }
322
+
323
+ func checkNSControlled (ns * corev1.Namespace ) bool {
324
+ nsName := ns .Name
325
+ isSystemNS := strings .HasPrefix (nsName , "openshift-" ) || nsName == "openshift" || nsName == "kube-system"
326
+ if isSystemNS {
327
+ return false
328
+ }
329
+
330
+ if ns .Labels [labelSyncControlLabel ] != "false" {
331
+ return true
315
332
}
316
333
317
- return false , nil
334
+ return false
318
335
}
319
336
320
337
// controlledNamespacesLabelSelector returns label selector to be used with the
0 commit comments