Skip to content

Commit 5331c6f

Browse files
committed
Refactored FluxCD resources and configuration for Git repository and Kustomization
1 parent 558d855 commit 5331c6f

File tree

10 files changed

+119
-45
lines changed

10 files changed

+119
-45
lines changed

Taskfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ tasks:
8383
- |
8484
flux install --export \
8585
--components-extra="image-reflector-controller,image-automation-controller" \
86-
> gotk-components.yaml
87-
dir: ./templates/fluxcd/resources
86+
> components.yaml
87+
dir: ./templates/fluxcd/templates/resources
8888

8989
pull:
9090
desc: Pulls the resources from the gitops-template ocm.

docs/Templating.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,44 @@ platformClusterKubeconfigSecretName: "platform-kubeconfig"
2626
resources files:
2727

2828
```yaml
29+
# The information for the git repo
2930
git:
30-
repoUrl: "" # The url to the github gitops repository
31-
mainBranch: "" # The main branch of the gitops repository (most of the time, set it to 'main')
31+
repoUrl: ""
32+
mainBranch: ""
33+
34+
# Image pull secrets to be added to all deployments
35+
imagePullSecrets: []
36+
# - name: my-registry-secret
37+
38+
# Image replacement variables
39+
# You can either specify a prefix which is put in front of xxx-controller or directly specify the images
40+
images:
41+
prefix: "ghcr.io/openmcp-project/fluxcd"
42+
sourceController:
43+
image: "ghcr.io/fluxcd/source-controller"
44+
tag: "latest" # optional
45+
digest: "" # optional
46+
notificationController:
47+
image: "ghcr.io/fluxcd/notification-controller"
48+
kustomizeController:
49+
image: "ghcr.io/fluxcd/kustomize-controller"
50+
helmController:
51+
image: "ghcr.io/fluxcd/helm-controller"
52+
imageReflectorController:
53+
image: "ghcr.io/fluxcd/image-reflector-controller"
54+
imageAutomationController:
55+
image: "ghcr.io/fluxcd/image-automation-controller"
3256
```
3357
3458
When rendering the `overlays` files, the following values are used:
3559

3660
```yaml
37-
fluxCDResourcesPath: "" # The path were the fluxcd resources are lying relative to the overlays
38-
gitRepoEnvBranch: "" # The branch for this environment to look at
39-
envPathFluxSystem: "" # The path were the env overlays are located at from the root of the git repo
61+
# Path from the overlays folder to the resources folder of fluxcd (e.g. ../../../resources/fluxcd)
62+
fluxCDResourcesPath: ""
63+
# Path to the env fluxCD folder (e.g. envs/%ENV%/fluxcd)
64+
fluxCDEnvPath: ""
65+
# branch of the env (e.g. dev)
66+
gitRepoEnvBranch: ""
4067
```
4168

4269
### OpenMCP

templates/fluxcd/templates/overlays/gotk-sync-kustomization.yaml renamed to templates/fluxcd/templates/overlays/flux-kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ metadata:
55
name: flux-system
66
namespace: flux-system
77
spec:
8-
path: {{ .Values.envPathFluxSystem }}
8+
path: {{ .Values.fluxCDEnvPath }}
File renamed without changes.

templates/fluxcd/templates/overlays/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ kind: Kustomization
33
resources:
44
- {{ .Values.fluxCDResourcesPath }}
55
patches:
6-
- path: gotk-sync-gitrepo.yaml
7-
- path: gotk-sync-kustomization.yaml
6+
- path: gitrepo.yaml
7+
- path: flux-kustomization.yaml

templates/fluxcd/templates/resources/gotk-components.yaml renamed to templates/fluxcd/templates/resources/components.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,8 +5344,6 @@ spec:
53445344
name: data
53455345
- mountPath: /tmp
53465346
name: tmp
5347-
imagePullSecrets:
5348-
- name: \{\{ .Values.imagePullSecret }}
53495347
nodeSelector:
53505348
kubernetes.io/os: linux
53515349
priorityClassName: system-cluster-critical
@@ -7242,8 +7240,6 @@ spec:
72427240
volumeMounts:
72437241
- mountPath: /tmp
72447242
name: temp
7245-
imagePullSecrets:
7246-
- name: \{\{ .Values.imagePullSecret }}
72477243
nodeSelector:
72487244
kubernetes.io/os: linux
72497245
priorityClassName: system-cluster-critical
@@ -11046,8 +11042,6 @@ spec:
1104611042
volumeMounts:
1104711043
- mountPath: /tmp
1104811044
name: temp
11049-
imagePullSecrets:
11050-
- name: \{\{ .Values.imagePullSecret }}
1105111045
nodeSelector:
1105211046
kubernetes.io/os: linux
1105311047
priorityClassName: system-cluster-critical
@@ -13027,8 +13021,6 @@ spec:
1302713021
volumeMounts:
1302813022
- mountPath: /tmp
1302913023
name: temp
13030-
imagePullSecrets:
13031-
- name: \{\{ .Values.imagePullSecret }}
1303213024
nodeSelector:
1303313025
kubernetes.io/os: linux
1303413026
securityContext:
@@ -14139,8 +14131,6 @@ spec:
1413914131
name: temp
1414014132
- mountPath: /data
1414114133
name: data
14142-
imagePullSecrets:
14143-
- name: \{\{ .Values.imagePullSecret }}
1414414134
nodeSelector:
1414514135
kubernetes.io/os: linux
1414614136
securityContext:
@@ -14974,8 +14964,6 @@ spec:
1497414964
volumeMounts:
1497514965
- mountPath: /tmp
1497614966
name: temp
14977-
imagePullSecrets:
14978-
- name: \{\{ .Values.imagePullSecret }}
1497914967
nodeSelector:
1498014968
kubernetes.io/os: linux
1498114969
securityContext:

templates/fluxcd/templates/resources/gotk-sync.yaml renamed to templates/fluxcd/templates/resources/flux-kustomization.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
---
2-
apiVersion: source.toolkit.fluxcd.io/v1
3-
kind: GitRepository
4-
metadata:
5-
name: environments
6-
namespace: flux-system
7-
spec:
8-
interval: 5m
9-
url: {{ .Values.git.repoUrl }}
10-
ref:
11-
branch: {{ .Values.git.mainBranch }}
12-
secretRef:
13-
name: git
14-
---
151
apiVersion: kustomize.toolkit.fluxcd.io/v1
162
kind: Kustomization
173
metadata:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
apiVersion: source.toolkit.fluxcd.io/v1
3+
kind: GitRepository
4+
metadata:
5+
name: environments
6+
namespace: flux-system
7+
spec:
8+
interval: 5m
9+
url: {{ .Values.git.repoUrl }}
10+
ref:
11+
branch: {{ .Values.git.mainBranch }}
12+
secretRef:
13+
name: git
Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
---
2+
{{- $prefix := .Values.images.prefix }}
3+
{{- $images := dict
4+
"source-controller" .Values.images.sourceController
5+
"notification-controller" .Values.images.notificationController
6+
"kustomize-controller" .Values.images.kustomizeController
7+
"helm-controller" .Values.images.helmController
8+
"image-reflector-controller" .Values.images.imageReflectorController
9+
"image-automation-controller" .Values.images.imageAutomationController
10+
}}
211
resources:
3-
- gotk-components.yaml
4-
- gotk-sync.yaml
12+
- components.yaml
13+
- gitrepo.yaml
14+
- flux-kustomization.yaml
515
images:
6-
- name: ghcr.io/fluxcd/source-controller
7-
newName: {{ .Values.sourceControllerImage }}
8-
- name: ghcr.io/fluxcd/notification-controller
16+
{{- range $name, $cfg := $images }}
17+
- name: ghcr.io/fluxcd/{{ $name }}
18+
newName: {{ if $cfg }}{{ $cfg.image }}{{- else if $prefix }}{{ $prefix }}/{{ $name }}{{- else }}ghcr.io/fluxcd/{{ $name }}{{- end }}
19+
{{- if and $cfg $cfg.tag }}
20+
newTag: {{ $cfg.tag }}
21+
{{- end }}
22+
{{- if and $cfg $cfg.digest }}
23+
digest: {{ $cfg.digest }}
24+
{{- end }}
25+
{{- end }}
26+
27+
{{- if .Values.imagePullSecrets }}
28+
patches:
29+
- target:
30+
kind: Deployment
31+
patch: |
32+
apiVersion: apps/v1
33+
kind: Deployment
34+
metadata:
35+
name: this_value_is_ignored
36+
spec:
37+
template:
38+
spec:
39+
imagePullSecrets:
40+
{{ toYaml .Values.imagePullSecrets | indent 8 }}
41+
{{- end }}

templates/fluxcd/values.yaml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
# Path from the overlays folder to the resources folder of fluxcd (e.g. ../../../resources/fluxcd)
2+
fluxCDResourcesPath: "../resources"
3+
# Path to the env fluxCD folder (e.g. envs/%ENV%/fluxcd)
4+
fluxCDEnvPath: ""
5+
# branch of the env (e.g. dev)
6+
gitRepoEnvBranch: ""
7+
8+
# The information for the git repo
19
git:
210
repoUrl: ""
311
mainBranch: ""
412

5-
# maybe like this
6-
envs:
7-
- git:
8-
branch: ""
13+
# Image pull secrets to be added to all deployments
14+
imagePullSecrets: []
15+
# - name: my-registry-secret
16+
17+
# Image replacement variables
18+
# You can either specify a prefix which is put in front of xxx-controller or directly specify the images
19+
images:
20+
prefix: "ghcr.io/fluxcd"
21+
# prefix: "ghcr.io/openmcp-project/fluxcd"
22+
# sourceController:
23+
# image: "ghcr.io/fluxcd/source-controller"
24+
# tag: "latest" # optional
25+
# digest: "" # optional
26+
# notificationController:
27+
# image: "ghcr.io/fluxcd/notification-controller"
28+
# kustomizeController:
29+
# image: "ghcr.io/fluxcd/kustomize-controller"
30+
# helmController:
31+
# image: "ghcr.io/fluxcd/helm-controller"
32+
# imageReflectorController:
33+
# image: "ghcr.io/fluxcd/image-reflector-controller"
34+
# imageAutomationController:
35+
# image: "ghcr.io/fluxcd/image-automation-controller"

0 commit comments

Comments
 (0)