
Component Operator Runtime
Build Kubernetes Component Operators
Reconcile Generic Components
// Component is the central interface that component operators have to implement.
type Component interface {
client.Object
// Return a read-only accessor to the component's spec.
GetSpec() types.Unstructurable
// Return a read-write (usually a pointer) accessor to the component's status,
GetStatus() *Status
}
// Reconciler provides the implementation of controller-runtime's Reconciler interface,
// for a given Component type T.
type Reconciler[T Component] struct {
// ...
}
// Reconcile the given component by applying its dependent resources to the target cluster.
func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// ...
}
Generate Manifests
// Resource generator interface.
type Generator interface {
// Generate manifests of the dependent resources.
Generate(ctx context.Context, namespace string, name string,
parameters types.Unstructurable) ([]client.Object, error)
}
// Create a new HelmGenerator.
func NewHelmGenerator(fsys fs.FS, chartPath string) (*HelmGenerator, error) {
// ...
}
// Create a new KustomizeGenerator.
func NewKustomizeGenerator(fsys fs.FS, kustomizationPath string,
options KustomizeGeneratorOptions) (*KustomizeGenerator, error) {
// ...
}
Apply and Delete Dependents
// The low-level Reconciler manages specified objects in the given target cluster.
type Reconciler struct {
// ...
}
// Apply given object manifests to the target cluster and maintain inventory.
func (r *Reconciler) Apply(ctx context.Context, inventory *[]*InventoryItem, objects []client.Object,
namespace string, ownerId string, componentDigest string) (bool, error) {
// ...
}
// Delete objects stored in the inventory from the target cluster and maintain inventory.
func (r *Reconciler) Delete(ctx context.Context, inventory *[]*InventoryItem,
ownerId string) (bool, error) {
// ...
}
// Check if the object set defined by inventory is ready for deletion.
func (r *Reconciler) IsDeletionAllowed(ctx context.Context, inventory *[]*InventoryItem,
ownerId string) (bool, string, error) {
// ...
}