Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config-related resource cannot be cleaned up after disable addons #8188

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (r *ComponentDefinitionReconciler) deletionHandler(rctx intctrlutil.Request
recordEvent, &appsv1alpha1.ComponentList{}); res != nil || err != nil {
return res, err
}
_ = appsconfig.DeleteConfigMapFinalizer(r.Client, rctx, cmpd)
return nil, nil
}
}
Expand Down
30 changes: 24 additions & 6 deletions controllers/apps/configuration/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,49 @@ 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)
if err != nil {
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 []appsv1alpha1.ComponentConfigSpec, cr client.Object) error {
Expand Down
Loading