pkg/messaging/consumer contains reusable consumers for the
pkg/messaging contract. Today that mostly means one thing:
deletion-driven local fan-out.
The package is not a broad library of message-processing patterns. It is a narrow
home for consumers that can be reused across services when lifecycle events need
to trigger predictable follow-up work.
What Lives Here
CascadingDelete, a consumer that:
ignores live events
reacts to deletion events
lists local resources, optionally filtered by a resource-ID label
issues foreground deletes so downstream cleanup can complete before the
referenced object is finally removed
Relationships
pkg/messaging defines the envelope, replay, and retry contract.
pkg/manager and the broader finalizer/reference model
are the reason this consumer exists: deletion of one resource often has to fan
out before another resource may finish disappearing.
Invariants
CascadingDelete treats deletion as the only actionable event. A nil deletion
timestamp is intentionally ignored.
If WithResourceLabel() is used, the consumer assumes that label identifies the
local resources owned by or referencing the deleted upstream resource.
Foreground deletion is used on purpose so owner-reference and finalizer-driven
cleanup blocks until dependents are actually cleared.
Caveats
This is a sharp tool. If the resource label is wrong or omitted carelessly, the
consumer can delete far more than intended.
The consumer is only thinly generic. It relies on the local resource type being
listable via client.ObjectList and on the system of record being Kubernetes.
The package currently has one real consumer. If more appear, they should earn
their place by being genuinely reusable rather than just being nearby.
type CascadingDelete struct {
// contains filtered or unexported fields
}
CascadingDelete implements a message queue consumer that watches
for resource deletion events and then fans them out to another local type.
You almost certainly want a resource label to be defined corrsponding to
the messages's resource ID, or you will just delete everything.
Consume receives project events. If the resource is being deleted, we propagate
that deletion request to all local resources that reference that resource.