Documentation
¶
Overview ¶
Package layout provides utilities for generating cluster directory layouts and for writing Kubernetes and Flux manifests to disk.
Flux Kustomizations and ArgoCD Applications reference directories in a Git repository using different fields. Flux uses `spec.path`, which must start with `./` and is always interpreted relative to the repository root. ArgoCD uses `spec.source.path` without the `./` prefix but with the same relative semantics.
When nodes or bundles live in nested subfolders, the path must point directly to the folder containing the manifests unless the directory tree only contains files for a single node or bundle. Flux will recursively auto-generate a `kustomization.yaml` when one is missing and include every manifest under the specified path. ArgoCD does not auto-generate a `kustomization.yaml` and therefore ignores nested directories unless they are referenced from a `kustomization.yaml` at the target path.
For example, consider the layout:
repo/
clusters/
prod/
nodes/
cp/
kustomization.yaml
bundles/
monitoring/
kustomization.yaml
The Flux Kustomization for the control-plane node uses:
spec.path: ./clusters/prod/nodes/cp
The equivalent ArgoCD Application uses:
spec.source.path: clusters/prod/nodes/cp
With this layout, each node or bundle is targeted individually. Pointing a Flux Kustomization at `./clusters/prod` would combine the `cp` and `monitoring` manifests into a single deployment because it would auto-generate a `kustomization.yaml` for the entire tree. ArgoCD will only process the manifests under `clusters/prod` itself unless a `kustomization.yaml` aggregates the subdirectories, so each subfolder must be referenced separately.
Package api defines configuration structures used to generate Kubernetes manifests and Flux resources.
Index ¶
- func DefaultKustomizationFileName(name string) string
- func DefaultManifestFileName(namespace, kind, name string, mode FileExportMode) string
- func WalkClusterByPackage(c *stack.Cluster, rules LayoutRules) (map[string]*ManifestLayout, error)
- func WriteManifest(basePath string, cfg Config, ml *ManifestLayout) error
- func WritePackagesToDisk(packages map[string]*ManifestLayout, basePath string) error
- type ApplicationFileMode
- type Config
- type FileExportMode
- type FluxPlacement
- type GroupingMode
- type KustomizationFileNameFunc
- type KustomizationMode
- type LayoutRules
- type ManifestFileNameFunc
- type ManifestLayout
- type Profile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultKustomizationFileName ¶
DefaultKustomizationFileName returns the standard Flux Kustomization file name.
func DefaultManifestFileName ¶
func DefaultManifestFileName(namespace, kind, name string, mode FileExportMode) string
DefaultManifestFileName implements the standard file naming convention used by Kure. It writes either one file per resource or groups by kind depending on the FileExportMode.
func WalkClusterByPackage ¶
func WalkClusterByPackage(c *stack.Cluster, rules LayoutRules) (map[string]*ManifestLayout, error)
WalkClusterByPackage traverses a stack.Cluster and builds separate ManifestLayout trees for each unique PackageRef (OCI artifact). Returns a map where keys are PackageRef GVKs and values are the corresponding ManifestLayout trees. Nodes without PackageRef inherit from their parent, with nil representing the default package.
func WriteManifest ¶
func WriteManifest(basePath string, cfg Config, ml *ManifestLayout) error
WriteManifest writes a ManifestLayout to disk using the provided configuration.
func WritePackagesToDisk ¶
func WritePackagesToDisk(packages map[string]*ManifestLayout, basePath string) error
WritePackagesToDisk writes multiple package layouts to separate directory structures
Types ¶
type ApplicationFileMode ¶
type ApplicationFileMode string
ApplicationFileMode specifies how resources within an application are written.
The default is AppFilePerResource which mirrors the behaviour of FilePerResource and writes each generated resource to its own file. AppFileSingle groups all resources belonging to an application into a single manifest file.
const ( // AppFilePerResource writes each application resource to its own file. AppFilePerResource ApplicationFileMode = "resource" // AppFileSingle writes all resources for an application into one file. AppFileSingle ApplicationFileMode = "single" // AppFileUnset indicates that no application file mode was specified. AppFileUnset ApplicationFileMode = "" )
type Config ¶
type Config struct {
// ManifestsDir is the directory under which Kubernetes manifests are written.
ManifestsDir string
// FluxDir is the directory under which Flux manifests are written.
FluxDir string
// FilePer determines how resources are grouped into files when writing manifests.
FilePer FileExportMode
// ApplicationFileMode controls whether application resources are written
// to a single file or split per resource. Defaults to AppFilePerResource.
ApplicationFileMode ApplicationFileMode
// KustomizationMode controls how kustomization.yaml files are generated.
// Defaults to KustomizationExplicit.
KustomizationMode KustomizationMode
// ManifestFileName formats the file name for a resource manifest.
ManifestFileName ManifestFileNameFunc
// KustomizationFileName formats the file name for a Flux Kustomization.
KustomizationFileName KustomizationFileNameFunc
}
Config LayoutConfig defines rules for generating a cluster layout.
func DefaultConfigForProfile ¶
DefaultConfigForProfile returns a Config initialised with defaults for the given profile. Unknown profiles fall back to FluxProfile.
func DefaultLayoutConfig ¶
func DefaultLayoutConfig() Config
DefaultLayoutConfig returns a configuration that matches the directory layout expected by FluxCD when writing manifests and Kustomizations.
type FileExportMode ¶
type FileExportMode string
FileExportMode determines how resources are written to disk.
const ( // FilePerResource writes each resource to its own file. FilePerResource FileExportMode = "resource" // FilePerKind groups resources by kind into a single file. FilePerKind FileExportMode = "kind" // FilePerUnset indicates that no export mode is specified. FilePerUnset FileExportMode = "" )
type FluxPlacement ¶
type FluxPlacement string
FluxPlacement determines how Flux Kustomizations are placed in the layout.
const ( // FluxSeparate places all Flux Kustomizations in a separate directory. FluxSeparate FluxPlacement = "separate" // FluxIntegrated distributes Flux Kustomizations across their target nodes. FluxIntegrated FluxPlacement = "integrated" // FluxUnset indicates no flux placement preference. FluxUnset FluxPlacement = "" )
type GroupingMode ¶
type GroupingMode string
GroupingMode controls how nodes, bundles and applications are laid out on disk.
The default for all grouping modes is GroupByName which creates a directory per entity. GroupFlat places all entities in the same directory.
const ( // GroupByName creates a directory for each item in the hierarchy. GroupByName GroupingMode = "name" // GroupFlat flattens the hierarchy placing all items in the same directory. GroupFlat GroupingMode = "flat" // GroupUnset indicates that no grouping preference was specified. GroupUnset GroupingMode = "" )
type KustomizationFileNameFunc ¶
KustomizationFileNameFunc returns the file name for a Flux Kustomization manifest.
type KustomizationMode ¶
type KustomizationMode string
KustomizationMode determines how kustomization.yaml files reference manifests.
const ( // KustomizationExplicit lists each manifest file in kustomization.yaml. KustomizationExplicit KustomizationMode = "explicit" // KustomizationRecursive references only subdirectories in kustomization.yaml. KustomizationRecursive KustomizationMode = "recursive" // KustomizationUnset indicates no kustomization mode preference. KustomizationUnset KustomizationMode = "" )
type LayoutRules ¶
type LayoutRules struct {
// NodeGrouping controls how nodes are written to disk. Defaults to
// GroupByName.
NodeGrouping GroupingMode
// BundleGrouping controls how bundles are written to disk. Defaults to
// GroupByName.
BundleGrouping GroupingMode
// ApplicationGrouping controls how applications are written to disk.
// Defaults to GroupByName.
ApplicationGrouping GroupingMode
// ApplicationFileMode controls whether application resources are
// combined into a single file or split per resource. Defaults to
// AppFilePerResource.
ApplicationFileMode ApplicationFileMode
// FilePer sets the default file export mode for resources. Defaults to
// FilePerResource.
FilePer FileExportMode
// ClusterName specifies a cluster name to prepend to all paths.
// When set, creates clusters/{ClusterName}/... structure.
ClusterName string
// FluxPlacement determines how Flux Kustomizations are placed.
// Defaults to FluxSeparate.
FluxPlacement FluxPlacement
}
LayoutRules control how layouts are generated.
Zero values are interpreted as the defaults described in the field documentation.
func DefaultLayoutRules ¶
func DefaultLayoutRules() LayoutRules
DefaultLayoutRules returns a LayoutRules instance populated with the documented default values.
func (LayoutRules) Validate ¶
func (lr LayoutRules) Validate() error
Validate ensures the LayoutRules contain known option values.
type ManifestFileNameFunc ¶
type ManifestFileNameFunc func(namespace, kind, name string, mode FileExportMode) string
ManifestFileNameFunc returns a file name for the given namespace, kind and resource name.
type ManifestLayout ¶
type ManifestLayout struct {
Name string
Namespace string
PackageRef *schema.GroupVersionKind
FilePer FileExportMode
ApplicationFileMode ApplicationFileMode
Mode KustomizationMode
FluxPlacement FluxPlacement // Track flux placement mode for kustomization generation
Resources []client.Object
Children []*ManifestLayout
}
func WalkCluster ¶
func WalkCluster(c *stack.Cluster, rules LayoutRules) (*ManifestLayout, error)
WalkCluster traverses a stack.Cluster and builds a ManifestLayout tree that mirrors the node and bundle hierarchy. Behaviour is controlled via LayoutRules. When BundleGrouping and ApplicationGrouping are set to GroupFlat, all application resources are written directly to their parent node's directory.
func (*ManifestLayout) FullRepoPath ¶
func (ml *ManifestLayout) FullRepoPath() string
func (*ManifestLayout) FullRepoPathWithPackage ¶
func (ml *ManifestLayout) FullRepoPathWithPackage() string
FullRepoPathWithPackage returns the repository path including package-specific prefix
func (*ManifestLayout) WriteToDisk ¶
func (ml *ManifestLayout) WriteToDisk(basePath string) error
func (*ManifestLayout) WriteToTar ¶
func (ml *ManifestLayout) WriteToTar(w io.Writer) error
WriteToTar writes the ManifestLayout to a tar archive, mirroring the directory structure that WriteToDisk would produce. File paths use forward slashes and output is deterministic (sorted file names).