Skip to main content
Version: v1alpha5

Flux Kustomization

Overview

This topic covers how to mix in a Flux Kustomization to all components. We'll use the Artifacts field of ComponentConfig defined by the author schema.

The Code

Generating the structure

Use holos to generate a minimal platform directory structure. Start by creating a blank directory to hold the platform configuration.

mkdir holos-flux-kustomization && cd holos-flux-kustomization
holos init platform v1alpha5

Creating an example Component

Create a directory for the example podinfo component we'll use to render platform manifests.

mkdir -p components/podinfo

Create the CUE configuration for the example podinfo component.

cat <<EOF >components/podinfo/podinfo.cue
package holos

holos: Component.BuildPlan

Component: #Helm & {
Name: "podinfo"
Chart: {
version: "6.6.2"
repository: {
name: "podinfo"
url: "https://stefanprodan.github.io/podinfo"
}
}
Values: ui: {
message: string | *"Hello World" @tag(message, type=string)
}
}
EOF

Integrate the podinfo component into the platform.

cat <<EOF >platform/podinfo.cue
package holos

Platform: Components: podinfo: {
name: "podinfo"
path: "components/podinfo"
}
EOF

Adding Flux Kustomizations

Configure Holos to render a Kustomization by defining an Artifact for it in every BuildPlan holos produces. We're unifying our custom configuration with the existing #ComponentConfig defined in schema.cue.

cat <<EOF >flux-kustomization.cue
package holos

import (
"path"
flux "kustomize.toolkit.fluxcd.io/kustomization/v1"
)

#ComponentConfig: {
Name: _
OutputBaseDir: _

let ArtifactPath = path.Join([OutputBaseDir, "gitops", "\(Name).kustomization.gen.yaml"], path.Unix)
let ResourcesPath = path.Join(["deploy", OutputBaseDir, "components", Name], path.Unix)

Artifacts: "\(Name)-kustomization": {
artifact: ArtifactPath
generators: [{
kind: "Resources"
output: artifact
resources: Kustomization: (Name): flux.#Kustomization & {
metadata: name: Name
metadata: namespace: "default"
spec: {
interval: "5m"
timeout: "1m"
prune: true
path: ResourcesPath
sourceRef: {
kind: "GitRepository"
name: "webapp"
}
}
}
}]
}
}
EOF

Inspecting the BuildPlan

Our customized #ComponentConfig results in the following BuildPlan.

note

The second artifact around line 40 contains the configured Kustomization resource.

holos cue export --expression holos --out=yaml ./components/podinfo

Rendering manifests

holos render platform

Reviewing the Kustomization

The Artifact we added to #ComponentConfig will produce a Flux Kustomization resource for every component in the platform. The output in this example is located at:

deploy/gitops/podinfo.kustomization.gen.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo
namespace: default
spec:
interval: 5m
path: deploy/components/podinfo
prune: true
sourceRef:
kind: GitRepository
name: webapp
timeout: 1m