This example demonstrates the usage of the statefulset primitive within the operator component framework. It shows how
to manage a Kubernetes StatefulSet as a component of a larger application, utilizing features like:
Base Construction: Initializing a StatefulSet with basic metadata, spec, and volume claim templates.
Feature Mutations: Applying version-gated or conditional changes (sidecars, env vars, annotations) using the
Mutator.
Custom Status Handlers: Overriding the default logic for determining readiness (via ConvergingStatus and the
WithCustomConvergeStatus builder hook) and health assessment during rollouts (GraceStatus).
Custom Suspension: Extending the default suspension logic (scaling to 0) with additional mutations.
Data Extraction: Harvesting information from the reconciled resource.
Directory Structure
app/: Defines the mock ExampleApp CRD and the controller that uses the component framework.
features/: Contains modular feature definitions:
mutations.go: sidecar injection, env vars, and version-based image updates.
handlers.go: custom status and suspension handlers.
resources/: Contains the central NewStatefulSetResource factory that assembles all features using the
statefulset.Builder.
main.go: A standalone entry point that demonstrates a single reconciliation loop using a fake client.