Compare commits

...

1 Commits

Author SHA1 Message Date
Jeff McCune
8c76061b0d (#27) Add recommended labels and sort output
Add the recommended labels mapping to holos stage, project, and
component names.  Project will eventually be renamed to "collection" or
something.

Example:

    app.kubernetes.io/part-of: prod
    app.kubernetes.io/name: secrets
    app.kubernetes.io/component: validate
    app.kubernetes.io/instance: prod-secrets-validate

Also sort the api objects produced from cue so the output of the `holos
render` command is stable for git commits.
2024-02-29 15:12:19 -08:00
5 changed files with 30 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
# Want kube api objects in the apiObjects output.
exec holos build .
stdout '^kind: SecretStore$'
stdout '# Source: holos component cue api objects SecretStore/default'
stdout '# Source: CUE apiObjects.SecretStore.default'
-- cue.mod --
package holos

View File

@@ -1,7 +1,7 @@
# Want kube api objects in the apiObjects output.
exec holos build .
stdout '^kind: SecretStore$'
stdout '# Source: holos component cue api objects SecretStore/default'
stdout '# Source: CUE apiObjects.SecretStore.default'
stderr 'skipping helm: no chart name specified'
-- cue.mod --

View File

@@ -33,9 +33,13 @@ _apiVersion: "holos.run/v1alpha1"
// #CommonLabels are mixed into every kubernetes api object.
#CommonLabels: {
"holos.run/stage.name": #InputKeys.stage
"holos.run/project.name": #InputKeys.project
"holos.run/component.name": #InputKeys.component
"holos.run/stage.name": #InputKeys.stage
"holos.run/project.name": #InputKeys.project
"holos.run/component.name": #InputKeys.component
"app.kubernetes.io/part-of": #InputKeys.stage
"app.kubernetes.io/name": #InputKeys.project
"app.kubernetes.io/component": #InputKeys.component
"app.kubernetes.io/instance": #InstanceName
...
}

View File

@@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/load"
@@ -131,11 +132,27 @@ func (r *Result) FinalOutput() string {
// addAPIObjects adds the overlay api objects to finalOutput.
func (r *Result) addOverlayObjects(log *slog.Logger) {
b := []byte(r.FinalOutput())
for kind, v := range r.APIObjectMap {
for name, yamlString := range v {
kinds := make([]string, 0, len(r.APIObjectMap))
// Sort the keys
for kind := range r.APIObjectMap {
kinds = append(kinds, kind)
}
slices.Sort(kinds)
for _, kind := range kinds {
v := r.APIObjectMap[kind]
// Sort the keys
names := make([]string, 0, len(v))
for name := range v {
names = append(names, name)
}
slices.Sort(names)
for _, name := range names {
yamlString := v[name]
log.Debug(fmt.Sprintf("%s/%s", kind, name), "kind", kind, "name", name)
util.EnsureNewline(b)
header := fmt.Sprintf("---\n# Source: holos component cue api objects %s/%s\n", kind, name)
header := fmt.Sprintf("---\n# Source: CUE apiObjects.%s.%s\n", kind, name)
b = append(b, []byte(header+yamlString)...)
util.EnsureNewline(b)
}

View File

@@ -1 +1 @@
0
1