Refactor argo apps factory

This commit is contained in:
Stefan Reimer 2020-08-21 20:39:55 +01:00
parent 3cfa3512e6
commit 47fa523694
13 changed files with 51 additions and 49 deletions

View File

@ -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:

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,3 @@
{{- if index .Values "kiam" "enabled" }}
{{ template "kubezero-app.app" dict "root" . "name" "kiam" "type" "helm" }}
{{ include "kubezero-app.app" . }}
{{- end }}

View File

@ -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 }}

View File

@ -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

View File

@ -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

View File

@ -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