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

Temporary full deletion protection #312

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
16 changes: 5 additions & 11 deletions pkg/controller/webhooks/deletionprotection.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ func checkManagedObject(ctx context.Context, obj client.Object, c client.Client,
ownerKind, ok := obj.GetLabels()[runtime.OwnerKindAnnotation]
if !ok || ownerKind == "" {
l.Info(runtime.OwnerKindAnnotation + " label not set, skipping evaluation")
return compositeInfo{Exists: false}, nil
return compositeInfo{Exists: true}, nil
}

ownerVersion, ok := obj.GetLabels()[runtime.OwnerVersionAnnotation]
if !ok || ownerVersion == "" {
l.Info(runtime.OwnerVersionAnnotation + " label not found, skipping evaluation")
return compositeInfo{Exists: false}, nil
return compositeInfo{Exists: true}, nil
}

onwerGroup, ok := obj.GetLabels()[runtime.OwnerGroupAnnotation]
if !ok || onwerGroup == "" {
l.Info(runtime.OwnerGroupAnnotation + " label not found, skipping evaluation")
return compositeInfo{Exists: false}, nil
return compositeInfo{Exists: true}, nil
}

ownerName, ok := obj.GetLabels()["crossplane.io/composite"]
if !ok || ownerName == "" {
l.Info("crossplane.io/composite label not found, skipping evaluation")
return compositeInfo{Exists: false}, nil
return compositeInfo{Exists: true}, nil
}

gvk := schema.GroupVersionKind{
Expand Down Expand Up @@ -104,13 +104,7 @@ func checkManagedObject(ctx context.Context, obj client.Object, c client.Client,
return compositeInfo{Exists: true, Name: ownerName}, fmt.Errorf("cannot get composite: %w", err)
}

// Check if the composite is already being deleted, then we disengage the
// protection.
if comp.GetDeletionTimestamp() != nil {
return compositeInfo{Exists: false, Name: ownerName}, nil
}

return compositeInfo{Exists: isDeletionProtected(obj), Name: ownerName}, nil
return compositeInfo{Exists: true, Name: ownerName}, nil
}

// checkUnmanagedObject tries to get the composite information about objects that are not directly managed by Crossplane.
Expand Down
Loading