feat(base): own repo management for easy branch managment

This commit is contained in:
WrenIX 2024-03-27 21:24:31 +01:00
parent e1cdb09953
commit 030caf43aa
Signed by: wrenix
GPG key ID: 7AFDB012974B1BB5
7 changed files with 130 additions and 23 deletions

View file

@ -1,3 +1,19 @@
base:
helm:
release:
install:
disableWait: true
remediation:
retries: -1
crds: CreateReplace
upgrade:
disableWait: true
remediation:
retries: -1
crds: CreateReplace
driftDetection:
mode: enabled
commons:
helm:
release:

View file

@ -6,4 +6,4 @@ maintainers:
- name: WrenIX
url: https://wrenix.eu
version: 0.1.0
version: 0.2.0

View file

@ -1,14 +1,11 @@
commons:
base:
namespace:
labels:
common-label: "default"
helm:
chart:
sourceRef:
kind: GitRepository
name: wrenix-flux-charts
namespace: flux-system
release:
valuesFrom:
- name: a
components:
test-default-namespace:

View file

@ -15,7 +15,7 @@ kind: Namespace
metadata:
name: "{{ $config.namespace.name }}"
labels:
{{- $config.namespace.labels | default (dict) | mergeOverwrite $.Values.commons.namespace.labels | toYaml | nindent 4 }}
{{- $config.namespace.labels | default (dict) | mergeOverwrite $.Values.base.namespace.labels | toYaml | nindent 4 }}
{{- end }}
{{- end }}

View file

@ -10,27 +10,41 @@ spec:
chart:
spec:
sourceRef:
{{- toYaml $.Values.commons.helm.chart.sourceRef | nindent 8 }}
kind: "GitRepository"
{{- with $.Values.base.helm.repo.namespace }}
namespace: {{ . }}
{{- if $config.branch }}
name: "{{ $.Release.Namespace }}-{{ $.Release.Name }}-{{ $componentInstance }}"
{{- else }}
name: "{{ $.Release.Namespace }}-{{ $.Release.Name }}"
{{- end }}
{{- else }}
{{- if $config.branch }}
name: "{{ $.Release.Name }}-{{ $componentInstance }}"
{{- else }}
name: "{{ $.Release.Name }}"
{{- end }}
{{- end }}
chart: "./{{ $componentName }}"
reconcileStrategy: "Revision"
releaseName: "{{ printf "%s-%s" $.Release.Name $componentInstance | replace (printf "%s-%s" $.Release.Name $.Release.Name) $.Release.Name }}"
targetNamespace: "{{ ($config.namespace | default (dict)).name | default (dict) | default $.Release.Namespace }}"
install:
{{- toYaml $.Values.commons.helm.release.install | nindent 4 }}
{{- toYaml $.Values.base.helm.release.install | nindent 4 }}
test:
{{- toYaml $.Values.commons.helm.release.test | nindent 4 }}
{{- toYaml $.Values.base.helm.release.test | nindent 4 }}
upgrade:
{{- toYaml $.Values.commons.helm.release.upgrade | nindent 4 }}
{{- toYaml $.Values.base.helm.release.upgrade | nindent 4 }}
driftDetection:
{{- toYaml $.Values.commons.helm.release.driftDetection | nindent 4 }}
interval: {{ $.Values.componentCommons.helm.release.interval }}
{{- toYaml $.Values.base.helm.release.driftDetection | nindent 4 }}
interval: {{ $.Values.base.helm.release.interval }}
valuesFrom:
- kind: ConfigMap
name: "{{ $.Release.Name }}-{{ $componentInstance }}-init"
optional: true
valuesKey: init
targetPath: init.version
{{- with $.Values.componentCommons.helm.release.valuesFrom }}
{{- with $.Values.base.helm.release.valuesFrom }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $config.valuesFrom }}

58
base/templates/repo.yaml Normal file
View file

@ -0,0 +1,58 @@
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
{{- with .Values.base.helm.repo.namespace }}
name: "{{ $.Release.Namespace }}-{{ $.Release.Name }}"
namespace: {{ . }}
{{- else }}
name: "{{ $.Release.Name }}"
{{- end }}
spec:
url: {{ .Values.base.helm.repo.url | quote }}
ref:
{{- toYaml .Values.base.helm.repo.ref | nindent 4 }}
{{- with .Values.base.helm.repo.secretRef }}
secretRef:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.base.helm.repo.verify }}
verify:
{{- toYaml . | nindent 4 }}
{{- end }}
interval: {{ .Values.base.helm.repo.interval }}
{{/*
if branch is set
*/}}
{{- range $componentInstance, $config := .Values.components }}
{{- if and $config.enabled $config.branch }}
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
{{- with $.Values.base.helm.repo.namespace }}
name: "{{ $.Release.Namespace }}-{{ $.Release.Name }}-{{ $componentInstance }}"
namespace: {{ . }}
{{- else }}
name: "{{ $.Release.Name }}-{{ $componentInstance }}"
{{- end }}
spec:
url: {{ $.Values.base.helm.repo.url | quote }}
ref:
branch: {{ $config.branch | quote }}
{{- with $.Values.base.helm.repo.secretRef }}
secretRef:
{{- toYaml . | nindent 4 }}
{{- end }}
interval: 1m
{{- with $.Values.base.helm.repo.verify }}
verify:
{{- toYaml . | nindent 4 }}
{{- end }}
interval: {{ $.Values.base.helm.repo.interval }}
{{- end }}
{{- end }}

View file

@ -1,24 +1,46 @@
global: {}
##
# configuration of this helm-chart
##
commons:
base:
namespace:
# -- labels for every new created namespace (together or overwritten by components.<component-release-name.namespace.labels)
labels: {}
helm:
repo:
# -- git repo where all components are stored
url: https://codeberg.org/wrenix/flux-charts.git
# -- namespace, where the GitRepo resource is installed (maybe needed together with secretRef)
namespace:
# -- default ref (if no branch is set - maybe overwritten by semver or so)
ref:
branch: main
# -- secret to get access to the git-repo
secretRef:
# -- secret to get access to the git-repo
verify:
interval: 10m
release:
interval: 10m
install: {}
test: {}
upgrade: {}
driftDetection: {}
componentCommons:
helm:
release:
interval: 10m
# -- valuesFrom for every components (for use values from ConfigMap or Secret)
valuesFrom: []
##
# Shared Values
# between all components
##
global: {}
commons: {}
##
# Components
##
components:
<component-release-name>:
# -- enable component-release to install