api

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package api owns the infra that actually materializes a DeploymentIntent onto a backend — it does not decide which backend or strategy to use (that dispatch lives in pkg/apis/deployment/strategy and pkg/apis/deployment/reconcile).

K8SProvider applies/tears down Kubernetes Deployment and Service objects via server-side apply. KustomizeStrategyProvider takes the GitOps path instead: it renders manifests (via render/builders), commits them to a repo, and ensures the Flux GitRepository/Kustomization CRs that make the cluster reconcile them. Provider and ProviderRegistry describe the interface every runtime-specific implementation conforms to, so a caller can resolve one by intent.Runtime without knowing the concrete type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type K8SProvider

type K8SProvider struct {
	Client   client.Client
	Scheme   *runtime.Scheme
	Log      logr.Logger
	Recorder events.EventRecorder
}

K8SProvider applies and tears down the Kubernetes Deployment and Service objects for a single ServiceUnit via server-side apply.

func NewK8SProvider

func NewK8SProvider(
	c client.Client,
	scheme *runtime.Scheme,
	log logr.Logger,
	rec events.EventRecorder,
) *K8SProvider

NewK8SProvider constructs a K8SProvider.

func (*K8SProvider) ApplyServiceUnit

ApplyServiceUnit applies the Deployment and Service objects for a single ServiceUnit and reports the resulting observed state.

func (*K8SProvider) Teardown

func (p *K8SProvider) Teardown(
	ctx context.Context,
	deploymentIntent *intent.DeploymentIntent,
) error

Teardown deletes the Kubernetes Deployment and Service this provider created for each ServiceUnit in the intent. Required, not optional — applyDeployment/applyService use server-side apply with no ownerReference, so Kubernetes GC will not reclaim these when the parent Deployment CR is removed. Teardown is the only mechanism that cleans them up.

Idempotent — a missing Deployment or Service is not an error. Attempts both objects for every ServiceUnit regardless of individual failures and aggregates errors, so one stuck object doesn't block cleanup of the rest.

type KustomizationProvider

type KustomizationProvider struct {
	Client                       client.Client
	Scheme                       *runtime.Scheme
	Log                          logr.Logger
	NewKustomizeStrategyProvider *KustomizeStrategyProvider
}

KustomizationProvider holds the shared clients used to construct a KustomizeStrategyProvider.

type KustomizeStrategyProvider

type KustomizeStrategyProvider struct {
	Client client.Client
	Scheme *runtime.Scheme
	Log    logr.Logger
}

KustomizeStrategyProvider implements the GitOps deployment path: it renders manifests, commits them to a repo, and ensures the Flux GitRepository/Kustomization CRs that make the cluster reconcile them.

func NewKustomizationProvider

func NewKustomizationProvider(c client.Client, scheme *runtime.Scheme, log logr.Logger, Recorder record.EventRecorder) *KustomizeStrategyProvider

NewKustomizationProvider constructs a KustomizeStrategyProvider from the given clients.

func NewKustomizeStrategyProvider

func NewKustomizeStrategyProvider(
	c client.Client,
	scheme *runtime.Scheme,
	log logr.Logger,
) *KustomizeStrategyProvider

NewKustomizeStrategyProvider constructs a KustomizeStrategyProvider.

func (*KustomizeStrategyProvider) BuildKustomize

func (m *KustomizeStrategyProvider) BuildKustomize(
	intent *intent.DeploymentIntent,
) ([]runtime.Object, error)

BuildKustomize renders the Deployment and Service objects for every ServiceUnit in intent, without writing them anywhere.

func (*KustomizeStrategyProvider) CommitAndPush

func (m *KustomizeStrategyProvider) CommitAndPush(
	repoPath string,
	intent *intent.DeploymentIntent,
	env string,
	sshEnv []string,
) error

CommitAndPush renders each ServiceUnit's Deployment/Service manifests into the env overlay under repoPath, removing previously generated workload files first, then commits and pushes the result. repoPath must already be a local clone (see ensureLocalClone); sshEnv authenticates the push.

func (*KustomizeStrategyProvider) ReconcileKustomization

func (m *KustomizeStrategyProvider) ReconcileKustomization(
	ctx context.Context,
	cr *environmentv1alpha1.Deployment,
	intent *intent.DeploymentIntent,
	repoURL string,
	ref string,
	path string,
) error

ReconcileKustomization is the GitOps path's public entrypoint: it renders and commits manifests to repoURL, then ensures the Flux GitRepository and Kustomization CRs that make the cluster apply them from ref/path.

func (*KustomizeStrategyProvider) Teardown

Teardown removes GitOps-managed resources for this Deployment CR: deletes the workload manifests from the external Git repo (committed + pushed), then deletes the Kustomization and GitRepository Flux CRs via TeardownFluxResources. repoURL/ref identify the manifests repo exactly as ReconcileKustomization's caller does (ref is a commit SHA) — needed to ensure a local clone exists before removeAndPush can touch it.

Only meaningful for a manifests repo whose lifecycle this type owns end to end (shared/persistent repo, files added and removed per Deployment). If something else owns that repo's lifecycle (creates and deletes the whole repo per Deployment), call TeardownFluxResources alone instead — see its doc comment.

Order matters: the Flux CRs must be deleted (or their manifests must already be absent) before or alongside the repo cleanup — otherwise Flux may reconcile a stale kustomization.yaml pointing at files mid-removal. Deleting first, removing files second, is the safer order here since a missing Kustomization simply stops reconciling rather than reconciling a broken state.

func (*KustomizeStrategyProvider) TeardownFluxResources

func (m *KustomizeStrategyProvider) TeardownFluxResources(
	ctx context.Context,
	cr *environmentv1alpha1.Deployment,
) error

TeardownFluxResources deletes the Kustomization and GitRepository Flux CRs this Deployment's GitOps reconciliation created. It does not touch the manifests repo itself (no clone, no commit/push) — callers whose manifests-repo lifecycle is managed elsewhere (e.g. a mediator that provisions and deletes a whole per-Deployment repo via a Git host's API) call this alone rather than the fuller Teardown, since removing files from a repo that's about to be deleted wholesale is redundant at best and a failing clone/push at worst.

The Kustomization is deleted before the GitRepository — stop reconciliation before the source it points at goes away, rather than after.

GitRepository and Kustomization are ownerRef'd (SetControllerReference), so GC would eventually reclaim them — deleted explicitly here anyway for determinism.

type Provider

type Provider interface {
	// Runtime returns the runtime this provider supports.
	Runtime() intent.Runtime

	// Supports reports whether the provider supports the given strategy.
	Supports(strategy intent.Strategy) bool

	// Execute reconciles the DeploymentIntent.
	Execute(
		ctx context.Context,
		intent *intent.DeploymentIntent,
	) (*domain.DeploymentResult, error)
}

Provider executes a DeploymentIntent against a specific runtime backend.

type ProviderRegistry

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

ProviderRegistry resolves Providers by runtime.

func NewProviderRegistry

func NewProviderRegistry(providers ...Provider) *ProviderRegistry

NewProviderRegistry constructs a ProviderRegistry pre-populated with the given providers, indexed by their own Runtime().

func (*ProviderRegistry) Register

func (r *ProviderRegistry) Register(provider Provider)

Register allows late registration (optional).

func (*ProviderRegistry) Resolve

func (r *ProviderRegistry) Resolve(
	runtime intent.Runtime,
) (Provider, error)

Resolve returns a provider for the given runtime.

Jump to

Keyboard shortcuts

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