target

package
v1.223.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package target implements provision targets: reusable delivery destinations (kinds) that publish a rendered ProvisionArtifact to a place such as a Git repository, an OCI registry, or a Kubernetes cluster.

A target is intentionally decoupled from the component type that produced the artifact: a Kubernetes component renders a "kubernetes.manifests" artifact and a future Docker component would render an "oci.image" artifact, yet both can be delivered by the same registered targets. The registry therefore lives in this neutral package, consumes a producer-agnostic ProvisionArtifact, and must not import any component package.

Index

Constants

View Source
const (
	// FormatYAML indicates UTF-8 YAML file content.
	FormatYAML = "yaml"
	// FormatJSON indicates UTF-8 JSON file content.
	FormatJSON = "json"
	// FormatText indicates arbitrary UTF-8 text content.
	FormatText = "text"
	// FormatDirectory indicates an opaque set of files forming a directory tree.
	FormatDirectory = "directory"
)

Artifact formats describe how ProvisionArtifact.Files content is encoded.

View Source
const (
	// KindKubernetes delivers rendered manifests to a Kubernetes cluster.
	KindKubernetes = "kubernetes"
	// KindGit publishes rendered files to a Git deployment repository.
	KindGit = "git"

	// DefaultClusterTargetName is the implicit target used when no target is
	// selected and none is configured: it preserves the historical behavior of
	// applying directly to the cluster, so components without provision.targets
	// keep working with zero configuration.
	DefaultClusterTargetName = "cluster"
)
View Source
const (
	// ArtifactKindKubernetesManifests is a stream of rendered Kubernetes objects.
	ArtifactKindKubernetesManifests = "kubernetes.manifests"
)

Artifact kinds produced by component types and consumed by target provisioners.

Variables

This section is empty.

Functions

func Deliver

func Deliver(ctx context.Context, kind string, in *DeliverInput) error

Deliver resolves the registered provisioner for the kind and delivers the artifact. It returns ErrProvisionTargetKindUnknown when no provisioner is registered for the kind.

func Register

func Register(kind string, p Provisioner)

Register adds a target provisioner instance under its kind. It is typically called during package initialization via init():

func init() { target.Register("git", &gitProvisioner{}) }

Registering the same kind twice replaces the prior instance (last write wins), which keeps testing and future overrides simple.

func RegisteredKinds

func RegisteredKinds() []string

RegisteredKinds returns the sorted kinds currently registered.

Types

type ArtifactMetadata

type ArtifactMetadata struct {
	// Component is the Atmos component instance name.
	Component string
	// Stack is the Atmos stack the artifact was rendered for.
	Stack string
	// Target is the name of the selected provision target.
	Target string
	// SourcePaths are the component source paths the artifact was rendered from.
	SourcePaths []string
	// RenderHash is a deterministic digest of Files, used for change detection.
	RenderHash string
}

ArtifactMetadata carries provenance for a rendered artifact. Targets use it for commit messages, trailers, and idempotency checks.

type DeliverInput

type DeliverInput struct {
	// AtmosConfig is the fully merged Atmos configuration.
	AtmosConfig *schema.AtmosConfiguration
	// TargetName is the configured name of the selected target.
	TargetName string
	// TargetConfig is the merged provision.targets.<name> block.
	TargetConfig map[string]any
	// Artifact is the rendered, producer-agnostic artifact to deliver.
	Artifact ProvisionArtifact
	// AuthContext is the resolved auth context for the component, if any.
	AuthContext *schema.AuthContext
	// EnvProvider composes the identity environment for targets that authenticate
	// via Atmos Auth (e.g. the git target's GitHub STS credentials). May be nil,
	// in which case ambient credentials apply.
	EnvProvider IdentityEnvironmentProvider
}

DeliverInput carries everything a target provisioner needs to publish an artifact. TargetConfig is the merged `provision.targets.<name>` block for the selected target.

type FetchInput

type FetchInput struct {
	// AtmosConfig is the fully merged Atmos configuration.
	AtmosConfig *schema.AtmosConfiguration
	// TargetName is the configured name of the selected target.
	TargetName string
	// TargetConfig is the merged provision.targets.<name> block.
	TargetConfig map[string]any
	// AuthContext is the resolved auth context for the component, if any.
	AuthContext *schema.AuthContext
	// EnvProvider composes the identity environment for targets that authenticate
	// via Atmos Auth. May be nil, in which case ambient credentials apply.
	EnvProvider IdentityEnvironmentProvider
}

FetchInput carries everything a target needs to read its current state. It mirrors DeliverInput without an artifact (nothing is being published).

type Fetcher

type Fetcher interface {
	// Fetch returns the artifact currently published at the destination. A
	// destination that holds nothing yet returns an artifact with no Files (not an
	// error), so the caller treats it as an empty baseline.
	Fetch(ctx context.Context, in *FetchInput) (ProvisionArtifact, error)
}

Fetcher is an optional capability a Provisioner may implement to read the CURRENT state already published at the destination, so a producer can diff a freshly rendered artifact against what is live there (e.g. the manifests currently committed in a Git deployment repository). It is intentionally separate from Provisioner so write-only targets need not implement it.

type IdentityEnvironmentProvider

type IdentityEnvironmentProvider interface {
	EnsureIdentityEnvironment(ctx context.Context, identityName string) (map[string]string, error)
}

IdentityEnvironmentProvider supplies the composed identity environment for an Atmos Auth identity (including linked auto-provision integrations such as github/sts, which materializes GIT_CONFIG_* variables). The auth.AuthManager satisfies this interface. It is declared here (rather than imported from pkg/git) so the neutral registry stays free of service dependencies.

type ProvisionArtifact

type ProvisionArtifact struct {
	// Kind identifies what was rendered (e.g. ArtifactKindKubernetesManifests).
	Kind string
	// Format describes how Files content is encoded (e.g. FormatYAML).
	Format string
	// Files maps deterministic repo-relative paths to their content.
	Files map[string][]byte
	// Metadata carries provenance for commit messages, trailers, and change detection.
	Metadata ArtifactMetadata
}

ProvisionArtifact is the producer-agnostic unit a target provisioner delivers. A component type renders one of these; a target publishes it without knowing how it was produced.

func Fetch

func Fetch(ctx context.Context, kind string, in *FetchInput) (ProvisionArtifact, error)

Fetch resolves the registered provisioner for the kind and reads its current state. It returns ErrProvisionTargetKindUnknown when no provisioner is registered for the kind, and ErrProvisionTargetNoFetch when the provisioner does not implement the Fetcher capability.

type Provisioner

type Provisioner interface {
	// Deliver publishes the artifact to the destination described by the input.
	Deliver(ctx context.Context, in *DeliverInput) error
}

Provisioner delivers a rendered ProvisionArtifact to a destination. Implementations are registered by kind (e.g. "git", "kubernetes") and must publish already-rendered files only — a Provisioner never renders manifests or runs `generate`.

func Get

func Get(kind string) (Provisioner, bool)

Get returns the registered provisioner instance for the kind. The boolean is false when no provisioner is registered for that kind.

type SelectedTarget

type SelectedTarget struct {
	// Name is the configured (or implicit) target name.
	Name string
	// Kind is the registered target kind (e.g. "git", "kubernetes").
	Kind string
	// Config is the merged provision.targets.<name> block (nil for the implicit cluster).
	Config map[string]any
}

SelectedTarget is the resolved provision target for a delivery: its name, kind, and merged config block.

func SelectTarget

func SelectTarget(provisionSection map[string]any, flagTarget string) (*SelectedTarget, error)

SelectTarget resolves which provision target to deliver to. Precedence: flagTarget, then provision.default, then the implicit "cluster" target.

When no targets are configured (or the implicit "cluster" target is selected without an explicit definition), it returns the implicit Kubernetes cluster target so existing components apply to the cluster unchanged. An explicitly requested name that is not configured returns ErrProvisionTargetNotFound, and a configured target missing a kind returns ErrProvisionTargetKindMissing.

Directories

Path Synopsis
Package git implements the "git" provision target: it publishes a rendered ProvisionArtifact to a managed Git deployment repository by writing the files under a configured path, committing the scoped path, and pushing.
Package git implements the "git" provision target: it publishes a rendered ProvisionArtifact to a managed Git deployment repository by writing the files under a configured path, committing the scoped path, and pushing.

Jump to

Keyboard shortcuts

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