@@ -99,8 +99,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
99
99
log := loggerWithRID (r .Log ).WithValues ("ns" , ns )
100
100
101
101
// Early exit if it's an excluded namespace
102
- if ! config .IsNamespaceIncluded (ns ) {
103
- return ctrl.Result {}, r .handleExcludedNamespace (ctx , log , ns )
102
+ if ! config .IsManagedNamespace (ns ) {
103
+ return ctrl.Result {}, r .handleUnmanaged (ctx , log , ns )
104
104
}
105
105
106
106
stats .StartHierConfigReconcile ()
@@ -109,7 +109,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
109
109
return ctrl.Result {}, r .reconcile (ctx , log , ns )
110
110
}
111
111
112
- func (r * Reconciler ) handleExcludedNamespace (ctx context.Context , log logr.Logger , nm string ) error {
112
+ func (r * Reconciler ) handleUnmanaged (ctx context.Context , log logr.Logger , nm string ) error {
113
113
// Get the namespace. Early exist if the namespace doesn't exist or is purged.
114
114
// If so, there must be no namespace label or HC instance to delete.
115
115
nsInst , err := r .getNamespace (ctx , nm )
@@ -127,13 +127,23 @@ func (r *Reconciler) handleExcludedNamespace(ctx context.Context, log logr.Logge
127
127
return err
128
128
}
129
129
130
- // Always delete hierarchyconfiguration (and any other HNC CRs) in the
131
- // excluded namespaces. Note: since singletons in the excluded namespaces are
132
- // never synced by HNC, there are no finalizers on the singletons that we can
133
- // delete them without removing the finalizers first.
134
- if err := r . deleteSingletonIfExists ( ctx , log , nm ); err != nil {
130
+ // Don't delete the hierarchy config, since the admin might be enabling and disabling the regex and
131
+ // we don't want this to be destructive. Instead, just remove the finalizers if there are any so that
132
+ // users can delete it if they like.
133
+ inst , _ , err := r . getSingleton ( ctx , nm )
134
+ if err != nil {
135
135
return err
136
136
}
137
+ if len (inst .ObjectMeta .Finalizers ) > 0 || len (inst .Status .Children ) > 0 {
138
+ log .Info ("Removing finalizers and children on unmanaged singleton" )
139
+ inst .ObjectMeta .Finalizers = nil
140
+ inst .Status .Children = nil
141
+ stats .WriteHierConfig ()
142
+ if err := r .Update (ctx , inst ); err != nil {
143
+ log .Error (err , "while removing finalizers on unmanaged namespace" )
144
+ return err
145
+ }
146
+ }
137
147
138
148
return nil
139
149
}
@@ -428,9 +438,9 @@ func (r *Reconciler) syncParent(log logr.Logger, inst *api.HierarchyConfiguratio
428
438
429
439
// Sync this namespace with its current parent.
430
440
curParent := r .Forest .Get (inst .Spec .Parent )
431
- if ! config .IsNamespaceIncluded (inst .Spec .Parent ) {
432
- log .Info ("Setting ConditionActivitiesHalted: excluded namespace set as parent" , "parent" , inst .Spec .Parent )
433
- ns .SetCondition (api .ConditionActivitiesHalted , api .ReasonIllegalParent , fmt .Sprintf ("Parent %q is an excluded namespace" , inst .Spec .Parent ))
441
+ if ! config .IsManagedNamespace (inst .Spec .Parent ) {
442
+ log .Info ("Setting ConditionActivitiesHalted: unmanaged namespace set as parent" , "parent" , inst .Spec .Parent )
443
+ ns .SetCondition (api .ConditionActivitiesHalted , api .ReasonIllegalParent , fmt .Sprintf ("Parent %q is an unmanaged namespace" , inst .Spec .Parent ))
434
444
} else if curParent != nil && ! curParent .Exists () {
435
445
log .Info ("Setting ConditionActivitiesHalted: parent doesn't exist (or hasn't been synced yet)" , "parent" , inst .Spec .Parent )
436
446
ns .SetCondition (api .ConditionActivitiesHalted , api .ReasonParentMissing , fmt .Sprintf ("Parent %q does not exist" , inst .Spec .Parent ))
@@ -644,37 +654,6 @@ func (r *Reconciler) writeHierarchy(ctx context.Context, log logr.Logger, orig,
644
654
return true , nil
645
655
}
646
656
647
- // deleteSingletonIfExists deletes the singleton in the namespace if it exists.
648
- // Note: Make sure there's no finalizers on the singleton before calling this
649
- // function.
650
- func (r * Reconciler ) deleteSingletonIfExists (ctx context.Context , log logr.Logger , nm string ) error {
651
- inst , deletingCRD , err := r .getSingleton (ctx , nm )
652
- if err != nil {
653
- return err
654
- }
655
-
656
- // Early exit if the singleton doesn't exist.
657
- if inst .CreationTimestamp .IsZero () {
658
- return nil
659
- }
660
-
661
- // If the CRD is being deleted, we don't need to delete it separately. It will
662
- // be deleted with the CRD.
663
- if deletingCRD {
664
- log .Info ("HC in excluded namespace is already being deleted" )
665
- return nil
666
- }
667
- log .Info ("Deleting illegal HC in excluded namespace" )
668
-
669
- stats .WriteHierConfig ()
670
- if err := r .Delete (ctx , inst ); err != nil {
671
- log .Error (err , "while deleting on apiserver" )
672
- return err
673
- }
674
-
675
- return nil
676
- }
677
-
678
657
func (r * Reconciler ) writeNamespace (ctx context.Context , log logr.Logger , orig , inst * corev1.Namespace ) (bool , error ) {
679
658
if reflect .DeepEqual (orig , inst ) {
680
659
return false , nil
0 commit comments