application

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 16

README

pkg/provisioners/application

Intention

pkg/provisioners/application is the provisioner adapter for CD-managed Helm applications. It turns a managed resource plus an application lookup function into the canonical CD driver operations needed to create, update, and delete an application instance.

This package is not a generic Helm abstraction and it is not merely a thin wrapper around the CD driver. It encodes the repository's model for:

  • resolving which version of a HelmApplication applies to the current managed resource
  • deriving a stable application identity from that resource
  • translating resource scope, remote-cluster scope, and optional generator customizations into a cd.HelmApplication
  • delegating the actual application lifecycle to the CD driver

Like pkg/provisioners/remotecluster, this package is tightly coupled to the context-based provisioning-scope model described in pkg/client. It expects context to carry both the managed resource and the active cluster scope that determine where the application should be installed.

Invariants And Guard Rails

  • Within the current in-tree CD/application model, this is the main provisioner adapter for CD-managed Helm applications.
  • New(applicationGetter) requires a lookup function that resolves the effective HelmApplication object and version for the current context. The provisioner does not own application discovery itself.
  • Provision() and Deprovision() both call initialize() at execution time, not at construction time, so application resolution happens in a path that can return normal reconcile errors.
  • Application identity is derived from both sides of the relationship: the application name selected during initialization and the managed resource labels carried in context. Those resource labels are sorted deterministically so the CD-layer identity remains stable.
  • Destination cluster identity comes from the active client.ClusterContext in context. Descendants are therefore expected to run under the correct provisioning scope before this provisioner is invoked.
  • InNamespace() overrides the application namespace explicitly. Otherwise the namespace comes from the application version, falling back to default.
  • WithGenerator() is the historical customization seam for adding implicit release names, parameters, values, namespace metadata, ignored-difference customizations, and lifecycle hooks around an otherwise standard application template.
  • AllowDegraded() deliberately weakens the success condition so degraded application health is accepted for cases where that is an intentional repository policy.
  • PreDeprovisionHook runs before application deletion and PostProvisionHook runs only after successful provisioning.
  • Deprovision propagates remotecluster.BackgroundDeletionFromContext(ctx) into the CD driver's delete path so descendant cleanup can respect doomed-remote semantics.

Caveats

  • This package mixes several concerns in one place: application lookup, version selection, identity derivation, template customization, lifecycle hooks, remote-scope interpretation, and CD-driver delegation.
  • The package is heavily context-driven. It assumes the managed resource is already present in context and that the active cluster scope has already been set correctly. If either hidden prerequisite is missing or wrong, behavior will be wrong in ways the constructor cannot prevent.
  • WithGenerator() is intentionally open-ended and therefore compromise-prone. It is a plugin-style any plus a pile of optional interface assertions, not a clean extension model. The typed generator interfaces are useful, but the generic Customizer hook is effectively an escape hatch and should be treated with suspicion.
  • AllowDegraded() is not a neutral option. It encodes a policy exception that should only be used when degraded application health is genuinely acceptable for that application.
  • PreDeprovisionHook and PostProvisionHook are operational escape hatches around the main CD lifecycle. Useful, but also evidence that some managed applications still need extra bespoke handling.
  • getResourceID() still depends on util.Keys() for deterministic label ordering. That is one of the remaining obstacles to deleting the now-obsolete helper in pkg/util.
  • This package is coupled to the CD/application model. If the old in-tree CD layer continues to shrink or is replaced, this package would likely need to be split or redesigned rather than carried forward unchanged.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

Types

type Customizer

type Customizer interface {
	Customize(version unikornv1.SemanticVersion) ([]cd.HelmApplicationField, error)
}

Customizer is a generic generator interface that implemnets raw customizations to the application template. Try to avoid using this.

type GetterFunc

ApplicationGetter abstracts away how an application is looked up for a specific entity.

type NamespaceLabeler added in v1.4.0

type NamespaceLabeler interface {
	NamespaceMetadata(ctx context.Context, version unikornv1.SemanticVersion) (map[string]string, map[string]string, error)
}

NamespaceLabeler is an interface you can implement in a generator, to give a namespace created by the CD labels and annotations.

type Paramterizer

type Paramterizer interface {
	Parameters(ctx context.Context, version unikornv1.SemanticVersion) (map[string]string, error)
}

Paramterizer is an interface that allows generators to supply a list of parameters to Helm. These are in addition to those defined by the application template. At present, there is nothing special about overriding, it just appends, so ensure the explicit and implicit sets don't overlap.

type PostProvisionHook

type PostProvisionHook interface {
	PostProvision(ctx context.Context) error
}

PostProvisionHook is an interface that lets an application provisioner run a callback when provisioning has completed successfully.

type PreDeprovisionHook added in v0.1.87

type PreDeprovisionHook interface {
	PreDeprovision(ctx context.Context) error
}

PreDeprovisionHook is an interface that lets an application deprovisioner run a callback before deprovisioning an application e.g. to handle manual resource deletion.

type Provisioner

type Provisioner struct {
	// Metadata defines the application name, this directly affects
	// the application what will be searched for in the application bundle
	// defined in the resource.  It will also be the default Application ID
	// name, unless overridden by Name.
	provisioners.Metadata
	// contains filtered or unexported fields
}

Provisioner deploys an application that is keyed to a specific resource. For example, ArgoCD dictates that applications be installed in the same namespace, so we use the resource to define a unique set of labels that identifies that resource out of all others, and add in the application name to uniquely identify the application within that resource.

func New

func New(applicationGetter GetterFunc) *Provisioner

New returns a new initialized provisioner object.

func (*Provisioner) AllowDegraded

func (p *Provisioner) AllowDegraded() *Provisioner

AllowDegraded accepts a degraded status as a success for an application.

func (*Provisioner) Deprovision

func (p *Provisioner) Deprovision(ctx context.Context) error

Deprovision implements the Provision interface.

func (*Provisioner) InNamespace

func (p *Provisioner) InNamespace(namespace string) *Provisioner

InNamespace deploys the application into an explicit namespace.

func (*Provisioner) Provision

func (p *Provisioner) Provision(ctx context.Context) error

Provision implements the Provision interface.

func (*Provisioner) WithGenerator

func (p *Provisioner) WithGenerator(generator any) *Provisioner

WithGenerator registers an object that can generate implicit configuration where you cannot do it all from the default set of arguments.

type ReleaseNamer

type ReleaseNamer interface {
	ReleaseName(ctx context.Context) string
}

ReleaseNamer is an interface that allows generators to supply an implicit release name to Helm.

type ValuesGenerator

type ValuesGenerator interface {
	Values(ctx context.Context, version unikornv1.SemanticVersion) (any, error)
}

ValuesGenerator is an interface that allows generators to supply a raw values.yaml file to Helm. This accepts an object that can be marshaled to YAML.

Jump to

Keyboard shortcuts

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