statusapplier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package statusapplier applies template-driven status patches to Kubernetes resources.

The StatusApplier subscribes to pipeline events (TemplateRenderedEvent, ReconciliationCompletedEvent, ReconciliationFailedEvent) and applies the appropriate status patch variant for each lifecycle phase using Server-Side Apply (SSA).

Status patches are fully defined by templates — the controller never hardcodes knowledge of specific resource types or condition names. Templates register patches via the statusPatch() template function during rendering, including outcome-keyed variants for each pipeline phase (rendered, deployed, renderFailed, deployFailed).

Index

Constants

View Source
const (
	// ComponentName is the unique identifier for this component.
	ComponentName = "status-applier"

	// EventBufferSize is the size of the event subscription buffer.
	// Moderate volume: receives template rendered, reconciliation completed/failed,
	// and leadership events.
	EventBufferSize = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component applies template-driven status patches to Kubernetes resources via Server-Side Apply (SSA).

This is an all-replica component that subscribes in the constructor. It caches patches from TemplateRenderedEvent and applies the appropriate variant based on pipeline lifecycle events. Only the leader applies patches to avoid conflicts.

Event flow:

TemplateRenderedEvent → cache patches, apply "rendered" variant (if leader)
ReconciliationCompletedEvent → apply "deployed" variant (if leader)
ReconciliationFailedEvent → apply "renderFailed" or "deployFailed" variant (if leader)
BecameLeaderEvent → clear checksum cache, apply cached "rendered" variant
LostLeadershipEvent → clear pending state

func New

func New(cfg *Config) *Component

New creates a new StatusApplier component.

The component subscribes to events in the constructor (all-replica pattern). It only applies patches when it is the leader.

func (*Component) HealthCheck

func (c *Component) HealthCheck() error

HealthCheck returns nil if the component is healthy.

func (*Component) Name

func (c *Component) Name() string

Name returns the unique identifier for this component.

func (*Component) Start

func (c *Component) Start(ctx context.Context) error

Start begins the StatusApplier event loop.

This method blocks until the context is cancelled.

type Config

type Config struct {
	// EventBus is the event bus for subscribing to events and publishing results.
	EventBus *busevents.EventBus

	// DynamicClient is the Kubernetes dynamic client for SSA patch operations.
	DynamicClient dynamic.Interface

	// GVRResolver resolves apiVersion + kind to GroupVersionResource.
	GVRResolver GVRResolver

	// Logger is the structured logger.
	Logger *slog.Logger
}

Config contains configuration for creating a StatusApplier Component.

type GVRResolver

type GVRResolver interface {
	Resolve(apiVersion, kind string) (schema.GroupVersionResource, error)
}

GVRResolver resolves apiVersion + kind to a GroupVersionResource. This abstracts the REST mapper for testability.

type RestMapperResolver

type RestMapperResolver struct {
}

RestMapperResolver implements GVRResolver using a Kubernetes REST mapper.

func NewRestMapperResolver

func NewRestMapperResolver() *RestMapperResolver

NewRestMapperResolver creates a GVRResolver that maps apiVersion+kind to GVR using static conventions (pluralized lowercase kind).

For production use, consider implementing a resolver backed by a real REST mapper if custom resources use non-standard pluralization.

func (*RestMapperResolver) Resolve

func (r *RestMapperResolver) Resolve(apiVersion, kind string) (schema.GroupVersionResource, error)

Resolve maps apiVersion + kind to a GroupVersionResource.

This uses the standard Kubernetes convention of pluralizing the lowercase kind as the resource name. For example:

  • networking.k8s.io/v1 + Ingress → networking.k8s.io/v1/ingresses
  • gateway.networking.k8s.io/v1 + Gateway → gateway.networking.k8s.io/v1/gateways
  • gateway.networking.k8s.io/v1 + HTTPRoute → gateway.networking.k8s.io/v1/httproutes

Jump to

Keyboard shortcuts

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