Skip to main content
Version: v1alpha6

ArgoCD Application

Overview​

This topic covers how to mix in an ArgoCD Application 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-argocd-application && cd holos-argocd-application
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 ArgoCD Application​

Configure Holos to render an Application 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 >argocd-application.cue
package holos

import (
"path"
app "argoproj.io/application/v1alpha1"
)

#ComponentConfig: {
Name: _
OutputBaseDir: _

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

Artifacts: "\(Name)-application": {
artifact: ArtifactPath
generators: [{
kind: "Resources"
output: artifact
resources: Application: (Name): app.#Application & {
metadata: name: Name
metadata: namespace: "argocd"
spec: {
destination: server: "https://kubernetes.default.svc"
project: "default"
source: {
path: ResourcesPath
repoURL: "https://example.com/example.git"
targetRevision: "main"
}
}
}
}]
}
}
EOF

Inspecting the BuildPlan​

Our customized #ComponentConfig results in the following BuildPlan.

note

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

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

Rendering manifests​

holos render platform

Reviewing the Application​

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

deploy/gitops/podinfo.application.gen.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: podinfo
namespace: argocd
spec:
destination:
server: https://kubernetes.default.svc
project: default
source:
path: deploy/components/podinfo
repoURL: https://example.com/example.git
targetRevision: main