From 123d7ce94607f795fd9887f3e8f924750ce6c268 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Fri, 21 Aug 2020 20:39:55 +0100 Subject: [PATCH] Refactor argo apps factory --- charts/kubezero/Chart.yaml | 2 +- charts/kubezero/templates/_app.tpl | 37 ++++++++++++++++++ charts/kubezero/templates/_app.yaml | 39 ------------------- .../templates/aws-ebs-csi-driver.yaml | 2 +- .../templates/aws-efs-csi-driver.yaml | 2 +- charts/kubezero/templates/calico.yaml | 2 +- charts/kubezero/templates/cert-manager.yaml | 2 +- charts/kubezero/templates/istio.yaml | 2 +- charts/kubezero/templates/kiam.yaml | 2 +- .../templates/local-volume-provisioner.yaml | 2 +- charts/kubezero/templates/logging.yaml | 2 +- charts/kubezero/templates/metrics.yaml | 2 +- charts/kubezero/values.yaml | 4 ++ 13 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 charts/kubezero/templates/_app.tpl delete mode 100644 charts/kubezero/templates/_app.yaml diff --git a/charts/kubezero/Chart.yaml b/charts/kubezero/Chart.yaml index 76620990..a39534d8 100644 --- a/charts/kubezero/Chart.yaml +++ b/charts/kubezero/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: kubezero description: KubeZero ArgoCD Application - Root App of Apps chart of KubeZero type: application -version: 0.4.4 +version: 0.4.5 home: https://kubezero.com icon: https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png keywords: diff --git a/charts/kubezero/templates/_app.tpl b/charts/kubezero/templates/_app.tpl new file mode 100644 index 00000000..166550d0 --- /dev/null +++ b/charts/kubezero/templates/_app.tpl @@ -0,0 +1,37 @@ +{{- define "kubezero-app.app" }} +{{- $name := regexReplaceAll "kubezero/templates/([a-z-]*)..*" .Template.Name "${1}" }} +{{- $my_values := index .Values $name "values" }} + +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: {{ $name }} + namespace: argocd + labels: +{{ include "kubezero-lib.labels" . | indent 4 }} + {{- if not ( index .Values $name "retain" ) }} + finalizers: + - resources-finalizer.argocd.argoproj.io + {{- end }} +spec: + project: kubezero + + source: + repoURL: {{ .Values.global.defaultSource.repoURL }} + targetRevision: {{ .Values.global.defaultSource.targetRevision }} + path: {{ .Values.global.defaultSource.pathPrefix}}charts/kubezero-{{ $name }} + {{- if $my_values }} + helm: + values: | +{{- toYaml $my_values | nindent 8 }} + {{- end }} + + destination: + server: {{ .Values.global.defaultDestination.server }} + namespace: {{ default "kube-system" ( index .Values $name "namespace" ) }} + + {{- if .Values.global.syncPolicy }} + syncPolicy: + {{- toYaml .Values.global.syncPolicy | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/kubezero/templates/_app.yaml b/charts/kubezero/templates/_app.yaml deleted file mode 100644 index 4c9ef8f5..00000000 --- a/charts/kubezero/templates/_app.yaml +++ /dev/null @@ -1,39 +0,0 @@ -{{- define "kubezero-app.app" }} -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: {{ .name | lower }} - namespace: argocd - labels: -{{ include "kubezero-lib.labels" .root | indent 4 }} - {{- if not .retain }} - finalizers: - - resources-finalizer.argocd.argoproj.io - {{- end }} -spec: - project: kubezero - - source: - repoURL: {{ .root.Values.global.defaultSource.repoURL }} - targetRevision: {{ .root.Values.global.defaultSource.targetRevision }} - {{- if eq .type "helm" }} - {{- $my_values := index .root.Values .name "values" }} - path: {{ .root.Values.global.defaultSource.pathPrefix}}charts/kubezero-{{ .name }} - {{- if $my_values }} - helm: - values: | -{{- toYaml $my_values | nindent 8 }} - {{- end }} - {{- else }} - path: {{ .root.Values.global.defaultSource.pathPrefix }}artifacts/kubezero-{{ .name }} - {{- end }} - - destination: - server: {{ .root.Values.global.defaultDestination.server }} - namespace: {{ default "kube-system" .namespace }} - - {{- if .root.Values.global.syncPolicy }} - syncPolicy: - {{- toYaml .root.Values.global.syncPolicy | nindent 4 }} - {{- end }} -{{- end }} diff --git a/charts/kubezero/templates/aws-ebs-csi-driver.yaml b/charts/kubezero/templates/aws-ebs-csi-driver.yaml index cf4e108a..66d72154 100644 --- a/charts/kubezero/templates/aws-ebs-csi-driver.yaml +++ b/charts/kubezero/templates/aws-ebs-csi-driver.yaml @@ -1,3 +1,3 @@ {{- if index .Values "aws-ebs-csi-driver" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "aws-ebs-csi-driver" "type" "helm" }} +{{ include "kubezero-app.app" . }} {{- end }} diff --git a/charts/kubezero/templates/aws-efs-csi-driver.yaml b/charts/kubezero/templates/aws-efs-csi-driver.yaml index 13a43ca5..f3675d3d 100644 --- a/charts/kubezero/templates/aws-efs-csi-driver.yaml +++ b/charts/kubezero/templates/aws-efs-csi-driver.yaml @@ -1,3 +1,3 @@ {{- if index .Values "aws-efs-csi-driver" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "aws-efs-csi-driver" "type" "helm" }} +{{ include "kubezero-app.app" . }} {{- end }} diff --git a/charts/kubezero/templates/calico.yaml b/charts/kubezero/templates/calico.yaml index 156da248..fa61d2a1 100644 --- a/charts/kubezero/templates/calico.yaml +++ b/charts/kubezero/templates/calico.yaml @@ -1,5 +1,5 @@ {{- if .Values.calico.enabled }} -{{ template "kubezero-app.app" dict "root" . "name" "calico" "type" "helm" "retain" true }} +{{ include "kubezero-app.app" . }} ignoreDifferences: - group: apiextensions.k8s.io diff --git a/charts/kubezero/templates/cert-manager.yaml b/charts/kubezero/templates/cert-manager.yaml index e1550192..d7bd21b3 100644 --- a/charts/kubezero/templates/cert-manager.yaml +++ b/charts/kubezero/templates/cert-manager.yaml @@ -1,5 +1,5 @@ {{- if index .Values "cert-manager" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "cert-manager" "type" "helm" "namespace" "cert-manager" }} +{{ include "kubezero-app.app" . }} --- apiVersion: v1 diff --git a/charts/kubezero/templates/istio.yaml b/charts/kubezero/templates/istio.yaml index 7ac9cb16..f2cc09ae 100644 --- a/charts/kubezero/templates/istio.yaml +++ b/charts/kubezero/templates/istio.yaml @@ -1,5 +1,5 @@ {{- if .Values.istio.enabled }} -{{ template "kubezero-app.app" dict "root" . "name" "istio" "type" "helm" }} +{{ include "kubezero-app.app" . }} ignoreDifferences: - group: apiextensions.k8s.io diff --git a/charts/kubezero/templates/kiam.yaml b/charts/kubezero/templates/kiam.yaml index 78c34af3..a23ed626 100644 --- a/charts/kubezero/templates/kiam.yaml +++ b/charts/kubezero/templates/kiam.yaml @@ -1,3 +1,3 @@ {{- if index .Values "kiam" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "kiam" "type" "helm" }} +{{ include "kubezero-app.app" . }} {{- end }} diff --git a/charts/kubezero/templates/local-volume-provisioner.yaml b/charts/kubezero/templates/local-volume-provisioner.yaml index 9313cfef..5961f720 100644 --- a/charts/kubezero/templates/local-volume-provisioner.yaml +++ b/charts/kubezero/templates/local-volume-provisioner.yaml @@ -1,3 +1,3 @@ {{- if index .Values "local-volume-provisioner" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "local-volume-provisioner" "type" "helm" }} +{{ include "kubezero-app.app" . }} {{- end }} diff --git a/charts/kubezero/templates/logging.yaml b/charts/kubezero/templates/logging.yaml index 0f40e65a..ef8f5e4a 100644 --- a/charts/kubezero/templates/logging.yaml +++ b/charts/kubezero/templates/logging.yaml @@ -1,5 +1,5 @@ {{- if index .Values "logging" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "logging" "type" "helm" "namespace" "logging"}} +{{ include "kubezero-app.app" . }} ignoreDifferences: - group: admissionregistration.k8s.io diff --git a/charts/kubezero/templates/metrics.yaml b/charts/kubezero/templates/metrics.yaml index 6fba80af..2bef83f0 100644 --- a/charts/kubezero/templates/metrics.yaml +++ b/charts/kubezero/templates/metrics.yaml @@ -1,5 +1,5 @@ {{- if index .Values "metrics" "enabled" }} -{{ template "kubezero-app.app" dict "root" . "name" "metrics" "type" "helm" "namespace" "monitoring"}} +{{ include "kubezero-app.app" . }} --- apiVersion: v1 kind: Namespace diff --git a/charts/kubezero/values.yaml b/charts/kubezero/values.yaml index ef4ee59c..be2b3eca 100644 --- a/charts/kubezero/values.yaml +++ b/charts/kubezero/values.yaml @@ -17,9 +17,11 @@ platform: aws calico: enabled: false + retain: true cert-manager: enabled: false + namespace: cert-manager local-volume-provisioner: enabled: false @@ -38,6 +40,8 @@ istio: metrics: enabled: false + namespace: monitoring logging: enabled: false + namespace: logging