Skip to content

Commit a7be7df

Browse files
committed
Update structure for Flux 2.7
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent a484a05 commit a7be7df

File tree

12 files changed

+155
-69
lines changed

12 files changed

+155
-69
lines changed

.github/workflows/e2e.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v5
1515
- name: Setup Flux
1616
uses: fluxcd/flux2/action@main
1717
- name: Setup Kubernetes
18-
uses: helm/kind-action@v1.7.0
18+
uses: helm/kind-action@v1.12.0
1919
with:
2020
cluster_name: flux
21+
version: v0.30.0
22+
node_image: kindest/node:v1.33.4
2123
- name: Install Flux in Kubernetes Kind
22-
run: flux install
24+
run: flux install --components-extra source-watcher
2325
- name: Setup cluster reconciliation
2426
run: |
2527
flux create source git flux-system \
@@ -38,6 +40,8 @@ jobs:
3840
- name: Verify helm reconciliation
3941
run: |
4042
kubectl -n podinfo wait helmrelease/podinfo --for=condition=ready --timeout=5m
43+
- name: List deployed resources
44+
run: flux tree ks flux-system
4145
- name: Debug failure
4246
if: failure()
4347
run: |

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v5
1616
- name: Setup yq
1717
uses: fluxcd/pkg/actions/yq@main
1818
- name: Setup kubeconform

README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ upgrade the Helm releases to their latest chart version based on semver ranges.
1414

1515
## Prerequisites
1616

17-
You will need a Kubernetes cluster version 1.28 or newer.
17+
You will need a Kubernetes cluster version 1.33 or newer.
1818
For a quick local test, you can use [Kubernetes kind](https://kind.sigs.k8s.io/docs/user/quick-start/).
1919
Any other Kubernetes setup will work as well though.
2020

@@ -122,7 +122,7 @@ spec:
122122
- host: podinfo.staging
123123
```
124124
125-
Note that with ` version: ">=1.0.0-alpha"` we configure Flux to automatically upgrade
125+
Note that with `version: ">=1.0.0-alpha"` we configure Flux to automatically upgrade
126126
the `HelmRelease` to the latest chart version including alpha, beta and pre-releases.
127127

128128
In **apps/production/** dir we have a Kustomize patch with the production specific values:
@@ -164,31 +164,41 @@ The infrastructure is structured into:
164164
└── kustomization.yaml
165165
```
166166
167-
In **infrastructure/controllers/** dir we have the Flux `HelmRepository` and `HelmRelease` definitions such as:
167+
In **infrastructure/controllers/** dir we have the Flux definitions such as:
168168
169169
```yaml
170+
apiVersion: source.toolkit.fluxcd.io/v1
171+
kind: OCIRepository
172+
metadata:
173+
name: cert-manager
174+
namespace: cert-manager
175+
spec:
176+
interval: 24h
177+
url: oci://quay.io/jetstack/charts/cert-manager
178+
layerSelector:
179+
mediaType: "application/vnd.cncf.helm.chart.content.v1.tar+gzip"
180+
operation: copy
181+
ref:
182+
semver: "1.x"
183+
---
170184
apiVersion: helm.toolkit.fluxcd.io/v2
171185
kind: HelmRelease
172186
metadata:
173187
name: cert-manager
174188
namespace: cert-manager
175189
spec:
176-
interval: 30m
177-
chart:
178-
spec:
179-
chart: cert-manager
180-
version: "1.x"
181-
sourceRef:
182-
kind: HelmRepository
183-
name: cert-manager
184-
namespace: cert-manager
185-
interval: 12h
190+
interval: 12h
191+
chartRef:
192+
kind: OCIRepository
193+
name: cert-manager
186194
values:
187-
installCRDs: true
195+
crds:
196+
enabled: true
197+
keep: false
188198
```
189199

190-
Note that with ` interval: 12h` we configure Flux to pull the Helm repository index every twelfth hours to check for updates.
191-
If the new chart version that matches the `1.x` semver range is found, Flux will upgrade the release.
200+
Note that in the `OCIRepository` we configure Flux to check for new chart versions every 24 hours.
201+
If a newer chart is found that matches the `semver: 1.x` constraint, Flux will upgrade the release accordingly.
192202

193203
In **infrastructure/configs/** dir we have Kubernetes custom resources, such as the Let's Encrypt issuer:
194204

@@ -258,18 +268,20 @@ metadata:
258268
name: apps
259269
namespace: flux-system
260270
spec:
261-
interval: 10m0s
262271
dependsOn:
263272
- name: infra-configs
273+
interval: 1h
274+
retryInterval: 2m
275+
timeout: 5m
264276
sourceRef:
265-
kind: GitRepository
266-
name: flux-system
267-
path: ./apps/staging
277+
kind: ExternalArtifact
278+
name: apps
279+
path: ./staging
268280
prune: true
269281
wait: true
270282
```
271283

272-
Note that with `path: ./apps/staging` we configure Flux to sync the staging Kustomize overlay and
284+
Note that with `path: ./staging` we configure Flux to sync the apps staging Kustomize overlay and
273285
with `dependsOn` we tell Flux to create the infrastructure items before deploying the apps.
274286

275287
Fork this repository on your personal GitHub account and export your GitHub access token, username and repo name:
@@ -290,6 +302,7 @@ Set the kubectl context to your staging cluster and bootstrap Flux:
290302

291303
```sh
292304
flux bootstrap github \
305+
--components-extra=source-watcher \
293306
--context=staging \
294307
--owner=${GITHUB_USER} \
295308
--repository=${GITHUB_REPO} \
@@ -328,6 +341,7 @@ Bootstrap Flux on production by setting the context and path to your production
328341

329342
```sh
330343
flux bootstrap github \
344+
--components-extra=source-watcher \
331345
--context=production \
332346
--owner=${GITHUB_USER} \
333347
--repository=${GITHUB_REPO} \
@@ -383,6 +397,7 @@ Set the kubectl context and path to your dev cluster and bootstrap Flux:
383397

384398
```sh
385399
flux bootstrap github \
400+
--components-extra=source-watcher \
386401
--context=dev \
387402
--owner=${GITHUB_USER} \
388403
--repository=${GITHUB_REPO} \
@@ -400,6 +415,7 @@ Bootstrap the `production-clone` cluster:
400415

401416
```sh
402417
flux bootstrap github \
418+
--components-extra=source-watcher \
403419
--context=production-clone \
404420
--owner=${GITHUB_USER} \
405421
--repository=${GITHUB_REPO} \

clusters/production/apps.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ metadata:
55
name: apps
66
namespace: flux-system
77
spec:
8-
interval: 10m0s
98
dependsOn:
109
- name: infra-configs
10+
interval: 1h
11+
retryInterval: 2m
12+
timeout: 5m
1113
sourceRef:
12-
kind: GitRepository
13-
name: flux-system
14-
path: ./apps/production
14+
kind: ExternalArtifact
15+
name: apps
16+
path: ./production
1517
prune: true
1618
wait: true
17-
timeout: 5m0s

clusters/production/artifacts.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: source.extensions.fluxcd.io/v1beta1
3+
kind: ArtifactGenerator
4+
metadata:
5+
name: flux-system
6+
namespace: flux-system
7+
spec:
8+
sources:
9+
- alias: monorepo
10+
kind: GitRepository
11+
name: flux-system
12+
artifacts:
13+
- name: infrastructure
14+
originRevision: "@monorepo"
15+
copy:
16+
- from: "@monorepo/infrastructure/**"
17+
to: "@artifact/"
18+
- name: apps
19+
originRevision: "@monorepo"
20+
copy:
21+
- from: "@monorepo/apps/**"
22+
to: "@artifact/"

clusters/production/infrastructure.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ metadata:
66
namespace: flux-system
77
spec:
88
interval: 1h
9-
retryInterval: 1m
9+
retryInterval: 2m
1010
timeout: 5m
1111
sourceRef:
12-
kind: GitRepository
13-
name: flux-system
14-
path: ./infrastructure/controllers
12+
kind: ExternalArtifact
13+
name: infrastructure
14+
path: ./controllers
1515
prune: true
1616
wait: true
1717
---
@@ -24,12 +24,12 @@ spec:
2424
dependsOn:
2525
- name: infra-controllers
2626
interval: 1h
27-
retryInterval: 1m
27+
retryInterval: 2m
2828
timeout: 5m
2929
sourceRef:
30-
kind: GitRepository
31-
name: flux-system
32-
path: ./infrastructure/configs
30+
kind: ExternalArtifact
31+
name: infrastructure
32+
path: ./configs
3333
prune: true
3434
patches:
3535
- patch: |

clusters/staging/apps.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
---
12
apiVersion: kustomize.toolkit.fluxcd.io/v1
23
kind: Kustomization
34
metadata:
45
name: apps
56
namespace: flux-system
67
spec:
7-
interval: 10m0s
88
dependsOn:
99
- name: infra-configs
10+
interval: 1h
11+
retryInterval: 2m
12+
timeout: 5m
1013
sourceRef:
11-
kind: GitRepository
12-
name: flux-system
13-
path: ./apps/staging
14+
kind: ExternalArtifact
15+
name: apps
16+
path: ./staging
1417
prune: true
1518
wait: true
16-
timeout: 5m0s

clusters/staging/artifacts.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: source.extensions.fluxcd.io/v1beta1
3+
kind: ArtifactGenerator
4+
metadata:
5+
name: flux-system
6+
namespace: flux-system
7+
spec:
8+
sources:
9+
- alias: monorepo
10+
kind: GitRepository
11+
name: flux-system
12+
artifacts:
13+
- name: infrastructure
14+
originRevision: "@monorepo"
15+
copy:
16+
- from: "@monorepo/infrastructure/**"
17+
to: "@artifact/"
18+
- name: apps
19+
originRevision: "@monorepo"
20+
copy:
21+
- from: "@monorepo/apps/**"
22+
to: "@artifact/"

clusters/staging/infrastructure.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ metadata:
66
namespace: flux-system
77
spec:
88
interval: 1h
9-
retryInterval: 1m
9+
retryInterval: 2m
1010
timeout: 5m
1111
sourceRef:
12-
kind: GitRepository
13-
name: flux-system
14-
path: ./infrastructure/controllers
12+
kind: ExternalArtifact
13+
name: infrastructure
14+
path: ./controllers
1515
prune: true
1616
wait: true
1717
---
@@ -24,12 +24,12 @@ spec:
2424
dependsOn:
2525
- name: infra-controllers
2626
interval: 1h
27-
retryInterval: 1m
27+
retryInterval: 2m
2828
timeout: 5m
2929
sourceRef:
30-
kind: GitRepository
31-
name: flux-system
32-
path: ./infrastructure/configs
30+
kind: ExternalArtifact
31+
name: infrastructure
32+
path: ./configs
3333
prune: true
3434
patches:
3535
- patch: |

infrastructure/controllers/cert-manager.yaml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,37 @@ metadata:
77
toolkit.fluxcd.io/tenant: sre-team
88
---
99
apiVersion: source.toolkit.fluxcd.io/v1
10-
kind: HelmRepository
10+
kind: OCIRepository
1111
metadata:
1212
name: cert-manager
1313
namespace: cert-manager
1414
spec:
1515
interval: 24h
16-
url: https://charts.jetstack.io
16+
url: oci://quay.io/jetstack/charts/cert-manager
17+
layerSelector:
18+
mediaType: "application/vnd.cncf.helm.chart.content.v1.tar+gzip"
19+
operation: copy
20+
ref:
21+
semver: "1.x"
1722
---
1823
apiVersion: helm.toolkit.fluxcd.io/v2
1924
kind: HelmRelease
2025
metadata:
2126
name: cert-manager
2227
namespace: cert-manager
2328
spec:
24-
interval: 30m
25-
chart:
26-
spec:
27-
chart: cert-manager
28-
version: "1.x"
29-
sourceRef:
30-
kind: HelmRepository
31-
name: cert-manager
32-
namespace: cert-manager
33-
interval: 12h
29+
interval: 12h
30+
install:
31+
strategy:
32+
name: RetryOnFailure
33+
retryInterval: 2m
34+
upgrade:
35+
strategy:
36+
name: RetryOnFailure
37+
retryInterval: 3m
38+
chartRef:
39+
kind: OCIRepository
40+
name: cert-manager
3441
values:
3542
crds:
3643
enabled: true

0 commit comments

Comments
 (0)