diff --git a/controllers/apps/componentdefinition_controller.go b/controllers/apps/componentdefinition_controller.go index 4b6f8f903b9..aa76acf7a06 100644 --- a/controllers/apps/componentdefinition_controller.go +++ b/controllers/apps/componentdefinition_controller.go @@ -133,6 +133,9 @@ func (r *ComponentDefinitionReconciler) deletionHandler(rctx intctrlutil.Request recordEvent, &appsv1.ComponentList{}); res != nil || err != nil { return res, err } + if err := appsconfig.DeleteConfigMapFinalizer(r.Client, rctx, cmpd); err != nil { + return &ctrl.Result{}, err + } return nil, nil } } diff --git a/controllers/apps/configuration/config_util.go b/controllers/apps/configuration/config_util.go index a5aac06e7c1..8ccc268f8a7 100644 --- a/controllers/apps/configuration/config_util.go +++ b/controllers/apps/configuration/config_util.go @@ -125,7 +125,7 @@ func DeleteConfigMapFinalizer(cli client.Client, ctx intctrlutil.RequestCtx, obj func validateConfigMapOwners(cli client.Client, ctx intctrlutil.RequestCtx, labels client.MatchingLabels, check func(obj client.Object) bool, objLists ...client.ObjectList) (bool, error) { for _, objList := range objLists { - if err := cli.List(ctx.Ctx, objList, labels, client.Limit(2)); err != nil { + if err := cli.List(ctx.Ctx, objList, labels, inDataContextUnspecified()); err != nil { return false, err } v, err := conversion.EnforcePtr(objList) @@ -133,23 +133,41 @@ func validateConfigMapOwners(cli client.Client, ctx intctrlutil.RequestCtx, labe return false, err } items := v.FieldByName("Items") - if !items.IsValid() || items.Kind() != reflect.Slice || items.Len() > 1 { + if !items.IsValid() || items.Kind() != reflect.Slice { return false, nil } if items.Len() == 0 { continue } + if !checkEnabledDelete(items, check) { + return false, nil + } + } + return true, nil +} - val := items.Index(0) +func checkEnabledDelete(items reflect.Value, check func(obj client.Object) bool) bool { + for i := 0; i < items.Len(); i++ { + val := items.Index(i) // fetch object pointer if val.CanAddr() { val = val.Addr() } - if !val.CanInterface() || !check(val.Interface().(client.Object)) { - return false, nil + if !val.CanInterface() { + return false + } + obj, ok := val.Interface().(client.Object) + if !ok { + return false + } + if obj.GetDeletionTimestamp() != nil { + continue + } + if !check(obj) { + return false } } - return true, nil + return true } func batchDeleteConfigMapFinalizer(cli client.Client, ctx intctrlutil.RequestCtx, configSpecs []appsv1.ComponentConfigSpec, cr client.Object) error {