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/_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 }} diff --git a/internal/project/cluster.go b/internal/project/cluster.go index dbf3d42..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" @@ -70,6 +71,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, } @@ -78,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 3da3ddc..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 @@ -31,6 +33,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 }