resources

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: 10 Imported by: 0

Documentation

Overview

Package resources contains example resource implementations for the component architecture.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCoreDeployment

func NewCoreDeployment(name, namespace string) *appsv1.Deployment

NewCoreDeployment returns the current latest version of the desired Deployment baseline. It encapsulates the core desired state (replicas, containers, etc.) that remains consistent across all versions of the component. Feature mutations are then applied on top of this baseline to implement version-specific or conditional logic.

Types

type DeploymentBuilder

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

DeploymentBuilder is a helper for configuring and assembling a DeploymentResource. It allows for the injection of custom behavior and Feature Mutations, enabling a clean and declarative way to define complex resources.

func NewDeploymentBuilder

func NewDeploymentBuilder(deployment *appsv1.Deployment) *DeploymentBuilder

NewDeploymentBuilder initializes a new builder with a default Deployment object.

func (*DeploymentBuilder) Build

Build finalizes and returns the configured DeploymentResource. It returns an error if the desired is nil, or if it lacks a name or namespace.

func (*DeploymentBuilder) WithCustomConvergeStatus

WithCustomConvergeStatus overrides the default readiness logic for the resource. This is part of implementing the Alive interface for the Component Framework.

func (*DeploymentBuilder) WithCustomGraceStatus

func (b *DeploymentBuilder) WithCustomGraceStatus(
	handler func(*appsv1.Deployment) (component.GraceStatusWithReason, error),
) *DeploymentBuilder

WithCustomGraceStatus overrides the default health reporting for degraded resources.

func (*DeploymentBuilder) WithCustomSuspendDeletionDecision

func (b *DeploymentBuilder) WithCustomSuspendDeletionDecision(
	handler func(*appsv1.Deployment) bool,
) *DeploymentBuilder

WithCustomSuspendDeletionDecision overrides whether a resource is deleted on suspension.

func (*DeploymentBuilder) WithCustomSuspendMutation

func (b *DeploymentBuilder) WithCustomSuspendMutation(
	handler func(*appsv1.Deployment) error,
) *DeploymentBuilder

WithCustomSuspendMutation overrides how the resource is suspended (e.g., scaling to 0).

func (*DeploymentBuilder) WithCustomSuspendStatus

func (b *DeploymentBuilder) WithCustomSuspendStatus(
	handler func(*appsv1.Deployment) (component.SuspensionStatusWithReason, error),
) *DeploymentBuilder

WithCustomSuspendStatus overrides the default suspension status reporting.

func (*DeploymentBuilder) WithDataExtractor

func (b *DeploymentBuilder) WithDataExtractor(
	extractor func(appsv1.Deployment) error,
) *DeploymentBuilder

WithDataExtractor registers a function to pull information from the resource during reconciliation. This implements the DataExtractable interface. The extractor is intentionally a pass by value method to prevent mutations for read-only data extraction.

func (*DeploymentBuilder) WithMutation

WithMutation registers a version-gated Feature Mutation to the resource. These are applied sequentially in the resource's Mutate() call.

type DeploymentResource

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

DeploymentResource is a wrapper around a Kubernetes Deployment object. It implements the component.Resource, component.Alive, component.Suspendable, and component.DataExtractable interfaces from the Component Framework. This abstraction exists to decouple the reconciliation logic from the specific Kubernetes type, allowing the framework to handle lifecycle and status aggregation.

func (*DeploymentResource) ConvergingStatus

ConvergingStatus reports the progress of the resource toward its desired state. It implements the Alive interface, allowing the Component to aggregate status.

func (*DeploymentResource) DeleteOnSuspend

func (r *DeploymentResource) DeleteOnSuspend() bool

DeleteOnSuspend determines if the resource should be deleted when the component is suspended.

func (*DeploymentResource) ExtractData

func (r *DeploymentResource) ExtractData() error

ExtractData pulls information from the reconciled resource for use by other components. It implements the DataExtractable interface.

func (*DeploymentResource) GraceStatus

GraceStatus reports the health of the resource when it's not fully ready (e.g., degraded). It's part of the Alive interface used for sophisticated status reporting.

func (*DeploymentResource) Identity

func (r *DeploymentResource) Identity() string

Identity returns a unique identifier for the resource, used by the framework for logging and tracking.

func (*DeploymentResource) IsSuspended

func (r *DeploymentResource) IsSuspended() bool

IsSuspended checks if the resource is currently in a suspended state (e.g., scaled to 0). It implements the Suspendable interface.

func (*DeploymentResource) Mutate

func (r *DeploymentResource) Mutate(current client.Object) error

Mutate applies the desired state to the resource, including Feature Mutations. It demonstrates how the Mutator pattern is used to safely apply version-gated changes.

func (*DeploymentResource) Object

func (r *DeploymentResource) Object() (client.Object, error)

Object returns a copy of the underlying Kubernetes object after reconcile or the unchanged desired object before a reconcile happens. It implements the Resource interface.

func (*DeploymentResource) Suspend

func (r *DeploymentResource) Suspend() error

Suspend records the intent to suspend the resource, to be applied during the next reconcile.

func (*DeploymentResource) SuspensionStatus

SuspensionStatus reports the progress of the resource toward a suspended state.

type DeploymentResourceMutator

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

DeploymentResourceMutator records feature mutation intent for a Deployment and applies the resulting changes in one final pass.

This keeps feature mutations simple and expressive while allowing the mutator to own mutation mechanics and resolve slice updates efficiently.

func NewDeploymentResourceMutator

func NewDeploymentResourceMutator(current *appsv1.Deployment) *DeploymentResourceMutator

NewDeploymentResourceMutator creates a new planner-style mutator for the given resource.

The mutator records intended changes and applies them later via Apply().

func (*DeploymentResourceMutator) Apply

func (m *DeploymentResourceMutator) Apply() error

Apply computes and writes the final Deployment state from the recorded mutation intent. The core desired state is already applied in Mutate() before this is called.

func (*DeploymentResourceMutator) EnsureContainerArg

func (m *DeploymentResourceMutator) EnsureContainerArg(arg string)

EnsureContainerArg records that a CLI argument should exist in all containers.

If the arg is already present when Apply() runs, it is kept as-is. If it is missing, it is appended. If the arg was previously marked for removal, this overrides that removal.

func (*DeploymentResourceMutator) EnsureContainerArgOrdered

func (m *DeploymentResourceMutator) EnsureContainerArgOrdered(arg string)

EnsureContainerArgOrdered records an argument and places it after Apply() only if absent. If order matters more strictly than simple append semantics, prefer a dedicated helper. This helper is optional and can be removed if not needed.

func (*DeploymentResourceMutator) EnsureContainerEnvVar

func (m *DeploymentResourceMutator) EnsureContainerEnvVar(name, value string)

EnsureContainerEnvVar records that an environment variable should exist in all containers.

If the env var already exists when Apply() runs, its value will be updated. If it does not exist, it will be appended. If the same env var was previously marked for removal, this overrides that removal.

func (*DeploymentResourceMutator) HasPlannedArg

func (m *DeploymentResourceMutator) HasPlannedArg(arg string) bool

HasPlannedArg reports whether an arg currently has a planned operation for any container. This is optional and mainly useful for debugging or tests.

func (*DeploymentResourceMutator) HasPlannedEnvVar

func (m *DeploymentResourceMutator) HasPlannedEnvVar(name string) bool

HasPlannedEnvVar reports whether an env var currently has a planned operation for any container. This is optional and mainly useful for debugging or tests.

func (*DeploymentResourceMutator) RemoveContainerArg

func (m *DeploymentResourceMutator) RemoveContainerArg(arg string)

RemoveContainerArg records that a CLI argument should be removed from all containers.

If the same arg was previously ensured, removal takes precedence unless another ensure call later overrides it.

func (*DeploymentResourceMutator) RemoveContainerEnvVar

func (m *DeploymentResourceMutator) RemoveContainerEnvVar(name string)

RemoveContainerEnvVar records that an environment variable should be removed from all containers.

If the same env var was previously ensured, removal takes precedence unless another ensure call later overrides it.

Jump to

Keyboard shortcuts

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