From b68ac5f4a2f931b857076b1f727e3eccbc631499 Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Tue, 18 Mar 2025 17:28:03 +0100 Subject: [PATCH 1/3] fix: add group information to addon output --- internal/project/cluster.go | 1 + internal/template/engine.go | 1 + internal/template/funcs.go | 2 ++ 3 files changed, 4 insertions(+) diff --git a/internal/project/cluster.go b/internal/project/cluster.go index dbf3d42..759ef21 100644 --- a/internal/project/cluster.go +++ b/internal/project/cluster.go @@ -70,6 +70,7 @@ func (c *Cluster) Render(config *ProjectConfig, env, stage string) error { for k, v := range addonProperties { addons[k] = template.AddonData{ Enabled: v.Enabled, + Group: config.ParsedAddons[k].Group, Annotations: config.ParsedAddons[k].Annotations, Properties: v.Properties, } diff --git a/internal/template/engine.go b/internal/template/engine.go index 3da3ddc..2d8344a 100644 --- a/internal/template/engine.go +++ b/internal/template/engine.go @@ -31,6 +31,7 @@ type TemplateData struct { type AddonData struct { Enabled bool + Group string Annotations map[string]string Properties map[string]any } diff --git a/internal/template/funcs.go b/internal/template/funcs.go index b29bda9..881aef4 100644 --- a/internal/template/funcs.go +++ b/internal/template/funcs.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "fmt" "io" + "path" "strings" "text/template" @@ -18,6 +19,7 @@ func funcMap(tmpl *template.Template) template.FuncMap { templateFuncMap["gzip"] = gzipCompress templateFuncMap["gunzip"] = gzipDecompress templateFuncMap["include"] = includeFun(tmpl, map[string]int{}) + templateFuncMap["joinPath"] = path.Join return templateFuncMap } From 58bf9501fe24ece84f6b661ed3e16aabac637f5b Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Tue, 18 Mar 2025 17:36:47 +0100 Subject: [PATCH 2/3] feat: add ClusterPath and BasePath variable to templating --- README.md | 10 ++++++---- internal/project/cluster.go | 3 +++ internal/template/engine.go | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 813c775..811018a 100644 --- a/README.md +++ b/README.md @@ -242,8 +242,10 @@ No matter if you define an addon or a template, you always have access to the fo | Variable | Scope | Description | | --- | --- | --- | -| `{{ .Environment }}` | addon, tempate | The environment variable returns the name of the environment we are currenlty in | -| `{{ .Stage }}` | addon, tempate | The stage variable returns the name of the stage we are currently in | -| `{{ .Cluster }}` | addon, tempate | The cluster variable returns the name of the cluster we are currently in | -| `{{ .Properties. }}` | addon, tempate | The properties variable returns the value of the property with the key ``. The property keys in addons differ from the property keys in the template, as the addon does not currently have access to the environment, stage or cluster properties. In order for the addon to have properties available, you must define a property key in the `manifest.yaml` file. All properties defined there are then available for your addon template files. | +| `{{ .BasePath }}` | template | The configured base path to the `environment` folder | +| `{{ .ClusterPath }}` | template | The complete path to the cluster | +| `{{ .Environment }}` | addon, template | The environment variable returns the name of the environment we are currenlty in | +| `{{ .Stage }}` | addon, template | The stage variable returns the name of the stage we are currently in | +| `{{ .Cluster }}` | addon, template | The cluster variable returns the name of the cluster we are currently in | +| `{{ .Properties. }}` | addon, template | The properties variable returns the value of the property with the key ``. The property keys in addons differ from the property keys in the template, as the addon does not currently have access to the environment, stage or cluster properties. In order for the addon to have properties available, you must define a property key in the `manifest.yaml` file. All properties defined there are then available for your addon template files. | | `{{ .ClusterProperties. }}` | addon | The cluster properties is a map that contains all properties that are defined for the cluster. | diff --git a/internal/project/cluster.go b/internal/project/cluster.go index 759ef21..a285080 100644 --- a/internal/project/cluster.go +++ b/internal/project/cluster.go @@ -2,6 +2,7 @@ package project import ( "fmt" + "path" "github.com/leonsteinhaeuser/openshift-gitops-cli/internal/template" "github.com/leonsteinhaeuser/openshift-gitops-cli/internal/utils" @@ -79,6 +80,8 @@ func (c *Cluster) Render(config *ProjectConfig, env, stage string) error { // render templates for _, t := range templates { err = t.Render(config.BasePath, template.TemplateData{ + BasePath: config.BasePath, + ClusterPath: path.Join(config.BasePath, env, stage, c.Name), Environment: env, Stage: stage, ClusterName: c.Name, diff --git a/internal/template/engine.go b/internal/template/engine.go index 2d8344a..42908da 100644 --- a/internal/template/engine.go +++ b/internal/template/engine.go @@ -22,6 +22,8 @@ type TemplateCarrier struct { } type TemplateData struct { + BasePath string + ClusterPath string Environment string Stage string ClusterName string From 4663e6d87a6a491d6ad19f5a60c3bb7c75d23f3e Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Tue, 18 Mar 2025 17:37:45 +0100 Subject: [PATCH 3/3] chore: update example --- _example/overlays/dev/dev/hugi/app-of-apps/values.yaml | 10 +++++----- .../cluster-configs/policies/cluster-policies/abc.yaml | 2 -- .../policies/cluster-policies/abc2.yaml | 2 -- .../cluster-policies/config/sub/kustomization.yaml | 5 ----- _example/source/templates/appofapps/values.yaml | 4 ++-- 5 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 _example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc.yaml delete mode 100644 _example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc2.yaml delete mode 100644 _example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/config/sub/kustomization.yaml diff --git a/_example/overlays/dev/dev/hugi/app-of-apps/values.yaml b/_example/overlays/dev/dev/hugi/app-of-apps/values.yaml index 170b913..64a4a95 100644 --- a/_example/overlays/dev/dev/hugi/app-of-apps/values.yaml +++ b/_example/overlays/dev/dev/hugi/app-of-apps/values.yaml @@ -1,6 +1,6 @@ --- appSuffix: "hugi-dev" -appSourceBasePath: overlays/dev/dev/hugi/cluster-configs +appSourceBasePath: _example/overlays/dev/dev/hugi default: app: @@ -39,7 +39,7 @@ applications: annotations: argocd.argoproj.io/sync-wave: "0" source: - path: cluster-policies + path: cluster-configs/policies/cluster-policies labels: app.kubernetes.io/managed-by: argocd disco-operator: @@ -47,7 +47,7 @@ applications: annotations: argocd.argoproj.io/sync-wave: "0" source: - path: disco-operator + path: cluster-configs/policies/disco-operator labels: app.kubernetes.io/managed-by: argocd kyverno: @@ -55,7 +55,7 @@ applications: annotations: argocd.argoproj.io/sync-wave: "0" source: - path: kyverno + path: cluster-configs/kyverno labels: app.kubernetes.io/managed-by: argocd monitoring: @@ -63,6 +63,6 @@ applications: annotations: argocd.argoproj.io/sync-wave: "0" source: - path: monitoring + path: cluster-configs/monitoring labels: app.kubernetes.io/managed-by: argocd diff --git a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc.yaml b/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc.yaml deleted file mode 100644 index 7276569..0000000 --- a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc.yaml +++ /dev/null @@ -1,2 +0,0 @@ -test: - hello: world diff --git a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc2.yaml b/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc2.yaml deleted file mode 100644 index 7276569..0000000 --- a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/abc2.yaml +++ /dev/null @@ -1,2 +0,0 @@ -test: - hello: world diff --git a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/config/sub/kustomization.yaml b/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/config/sub/kustomization.yaml deleted file mode 100644 index 190cb8d..0000000 --- a/_example/overlays/dev/dev/hugi/cluster-configs/policies/cluster-policies/config/sub/kustomization.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: - - config/abc.yaml diff --git a/_example/source/templates/appofapps/values.yaml b/_example/source/templates/appofapps/values.yaml index b1d51c1..80eade8 100644 --- a/_example/source/templates/appofapps/values.yaml +++ b/_example/source/templates/appofapps/values.yaml @@ -1,6 +1,6 @@ --- appSuffix: "{{ .ClusterName }}-{{ .Stage }}" -appSourceBasePath: overlays/{{ .Environment }}/{{ .Stage }}/{{ .ClusterName }}/cluster-configs +appSourceBasePath: {{ .ClusterPath }} default: app: @@ -40,7 +40,7 @@ applications: annotations: {{- $value.Annotations | toYaml | nindent 6 }} source: - path: {{ $key }} + path: {{ joinPath $value.Group $key }} labels: app.kubernetes.io/managed-by: argocd {{- end }}