Skip to content

Commit fd14333

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

File tree

12 files changed

+167
-130
lines changed

12 files changed

+167
-130
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: 49 additions & 82 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

@@ -235,7 +245,7 @@ spec:
235245
Note that with `dependsOn` we tell Flux to first install or upgrade the controllers and only then the configs.
236246
This ensures that the Kubernetes CRDs are registered on the cluster, before Flux applies any custom resources.
237247

238-
## Bootstrap staging and production
248+
### Clusters
239249

240250
The clusters dir contains the Flux configuration:
241251

@@ -258,20 +268,24 @@ 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

287+
## Bootstrap staging and production
288+
275289
Fork this repository on your personal GitHub account and export your GitHub access token, username and repo name:
276290

277291
```sh
@@ -290,6 +304,7 @@ Set the kubectl context to your staging cluster and bootstrap Flux:
290304

291305
```sh
292306
flux bootstrap github \
307+
--components-extra=source-watcher \
293308
--context=staging \
294309
--owner=${GITHUB_USER} \
295310
--repository=${GITHUB_REPO} \
@@ -307,9 +322,9 @@ Watch for the Helm releases being installed on staging:
307322
$ watch flux get helmreleases --all-namespaces
308323
309324
NAMESPACE NAME REVISION SUSPENDED READY MESSAGE
310-
cert-manager cert-manager v1.11.0 False True Release reconciliation succeeded
311-
ingress-nginx ingress-nginx 4.4.2 False True Release reconciliation succeeded
312-
podinfo podinfo 6.3.0 False True Release reconciliation succeeded
325+
cert-manager cert-manager 1.19.1 False True Helm install succeeded
326+
ingress-nginx ingress-nginx 4.13.4 False True Helm install succeeded
327+
podinfo podinfo 6.9.2 False True Helm install succeeded
313328
```
314329

315330
Verify that the demo app can be accessed via ingress:
@@ -320,14 +335,15 @@ $ kubectl -n ingress-nginx port-forward svc/ingress-nginx-controller 8080:80 &
320335
$ curl -H "Host: podinfo.staging" http://localhost:8080
321336
{
322337
"hostname": "podinfo-59489db7b5-lmwpn",
323-
"version": "6.2.3"
338+
"version": "6.9.2"
324339
}
325340
```
326341

327342
Bootstrap Flux on production by setting the context and path to your production cluster:
328343

329344
```sh
330345
flux bootstrap github \
346+
--components-extra=source-watcher \
331347
--context=production \
332348
--owner=${GITHUB_USER} \
333349
--repository=${GITHUB_REPO} \
@@ -341,11 +357,11 @@ Watch the production reconciliation:
341357
```console
342358
$ flux get kustomizations --watch
343359
344-
NAME REVISION SUSPENDED READY MESSAGE
345-
apps main/696182e False True Applied revision: main/696182e
346-
flux-system main/696182e False True Applied revision: main/696182e
347-
infra-configs main/696182e False True Applied revision: main/696182e
348-
infra-controllers main/696182e False True Applied revision: main/696182e
360+
NAME REVISION READY MESSAGE
361+
flux-system main@sha1:a7be7dff True Applied revision: main@sha1:a7be7dff
362+
infra-controllers latest@sha256:c0ac3648 True Applied revision: latest@sha256:c0ac3648
363+
infra-configs latest@sha256:c0ac3648 True Applied revision: latest@sha256:c0ac3648
364+
apps latest@sha256:26785ee4 True Applied revision: latest@sha256:26785ee4
349365
```
350366

351367
## Add clusters
@@ -366,6 +382,7 @@ mkdir -p clusters/dev
366382
Copy the sync manifests from staging:
367383

368384
```sh
385+
cp clusters/staging/artifacts.yaml clusters/dev
369386
cp clusters/staging/infrastructure.yaml clusters/dev
370387
cp clusters/staging/apps.yaml clusters/dev
371388
```
@@ -383,6 +400,7 @@ Set the kubectl context and path to your dev cluster and bootstrap Flux:
383400

384401
```sh
385402
flux bootstrap github \
403+
--components-extra=source-watcher \
386404
--context=dev \
387405
--owner=${GITHUB_USER} \
388406
--repository=${GITHUB_REPO} \
@@ -391,57 +409,6 @@ flux bootstrap github \
391409
--path=clusters/dev
392410
```
393411

394-
## Identical environments
395-
396-
If you want to spin up an identical environment, you can bootstrap a cluster
397-
e.g. `production-clone` and reuse the `production` definitions.
398-
399-
Bootstrap the `production-clone` cluster:
400-
401-
```sh
402-
flux bootstrap github \
403-
--context=production-clone \
404-
--owner=${GITHUB_USER} \
405-
--repository=${GITHUB_REPO} \
406-
--branch=main \
407-
--personal \
408-
--path=clusters/production-clone
409-
```
410-
411-
Pull the changes locally:
412-
413-
```sh
414-
git pull origin main
415-
```
416-
417-
Create a `kustomization.yaml` inside the `clusters/production-clone` dir:
418-
419-
```yaml
420-
apiVersion: kustomize.config.k8s.io/v1beta1
421-
kind: Kustomization
422-
resources:
423-
- flux-system
424-
- ../production/infrastructure.yaml
425-
- ../production/apps.yaml
426-
```
427-
428-
Note that besides the `flux-system` kustomize overlay, we also include
429-
the `infrastructure` and `apps` manifests from the production dir.
430-
431-
Push the changes to the main branch:
432-
433-
```sh
434-
git add -A && git commit -m "add production clone" && git push
435-
```
436-
437-
Tell Flux to deploy the production workloads on the `production-clone` cluster:
438-
439-
```sh
440-
flux reconcile kustomization flux-system \
441-
--context=production-clone \
442-
--with-source
443-
```
444-
445412
## Testing
446413

447414
Any change to the Kubernetes manifests or to the repository structure should be validated in CI before

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

0 commit comments

Comments
 (0)