consumer

package
v1.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

README

pkg/messaging/consumer

Intention

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/messaging/kubernetes is the current backend that delivers those envelopes.
  • 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CascadingDelete

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.

func NewCascadingDelete

func NewCascadingDelete(client client.Client, resources client.ObjectList, options ...Option) *CascadingDelete

NewCascadingDelete creates a new cascading deletion consumer.

func (*CascadingDelete) Consume

func (c *CascadingDelete) Consume(ctx context.Context, envelope *messaging.Envelope) error

Consume receives project events. If the resource is being deleted, we propagate that deletion request to all local resources that reference that resource.

type Option

type Option func(c *CascadingDelete)

Options defines a set of runtime composable options.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the namespace in which to each for resources.

func WithResourceLabel

func WithResourceLabel(label string) Option

WithResourceLabel creates a label selector that will match the value passed in the messages's resource ID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL