Skip to content

Commit c74c7b0

Browse files
committed
Update structure for Flux 2.7
Signed-off-by: Stefan Prodan <[email protected]>
1 parent a484a05 commit c74c7b0

File tree

12 files changed

+180
-133
lines changed

12 files changed

+180
-133
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: 62 additions & 85 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,17 +245,23 @@ 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

240-
The clusters dir contains the Flux configuration:
250+
A cluster is configured inside its own directory under **clusters/** dir, containing:
251+
252+
- **artifacts.yaml** contains an `ArtifactGenerator` that splits the monorepo into infrastructure and apps artifacts
253+
- **infrastructure.yaml** contains the Flux `Kustomization` definitions for reconciling the infrastructure controllers and configs
254+
- **apps.yaml** contains the Flux `Kustomization` definition for reconciling the apps Kustomize overlay for the specific cluster
241255

242256
```
243257
./clusters/
244258
├── production
245259
│   ├── apps.yaml
260+
│   ├── artifacts.yaml
246261
│   └── infrastructure.yaml
247262
└── staging
248263
├── apps.yaml
264+
├── artifacts.yaml
249265
└── infrastructure.yaml
250266
```
251267
@@ -258,19 +274,27 @@ metadata:
258274
name: apps
259275
namespace: flux-system
260276
spec:
261-
interval: 10m0s
262277
dependsOn:
263278
- name: infra-configs
279+
interval: 1h
280+
retryInterval: 2m
281+
timeout: 5m
264282
sourceRef:
265-
kind: GitRepository
266-
name: flux-system
267-
path: ./apps/staging
283+
kind: ExternalArtifact
284+
name: apps
285+
path: ./staging
268286
prune: true
269287
wait: true
270288
```
271289

272-
Note that with `path: ./apps/staging` we configure Flux to sync the staging Kustomize overlay and
273-
with `dependsOn` we tell Flux to create the infrastructure items before deploying the apps.
290+
With `path: ./staging` we configure Flux to sync the apps staging Kustomize overlay and
291+
with `dependsOn` we tell Flux to wait for the infrastructure configs to be installed before applying the apps.
292+
293+
Note that the `ExternalArtifact` source is generated by the `ArtifactGenerator` from the contents of the **apps/** directory.
294+
The `ArtifactGenerator` allows us to split the monorepo into smaller artifacts that can be synced independently.
295+
Changes to files outside the **apps/** dir will not trigger a reconciliation of the apps Kustomization.
296+
297+
## Bootstrap
274298

275299
Fork this repository on your personal GitHub account and export your GitHub access token, username and repo name:
276300

@@ -290,6 +314,7 @@ Set the kubectl context to your staging cluster and bootstrap Flux:
290314

291315
```sh
292316
flux bootstrap github \
317+
--components-extra=source-watcher \
293318
--context=staging \
294319
--owner=${GITHUB_USER} \
295320
--repository=${GITHUB_REPO} \
@@ -307,9 +332,9 @@ Watch for the Helm releases being installed on staging:
307332
$ watch flux get helmreleases --all-namespaces
308333

309334
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
335+
cert-manager cert-manager 1.19.1 False True Helm install succeeded
336+
ingress-nginx ingress-nginx 4.13.4 False True Helm install succeeded
337+
podinfo podinfo 6.9.2 False True Helm install succeeded
313338
```
314339

315340
Verify that the demo app can be accessed via ingress:
@@ -320,14 +345,15 @@ $ kubectl -n ingress-nginx port-forward svc/ingress-nginx-controller 8080:80 &
320345
$ curl -H "Host: podinfo.staging" http://localhost:8080
321346
{
322347
"hostname": "podinfo-59489db7b5-lmwpn",
323-
"version": "6.2.3"
348+
"version": "6.9.2"
324349
}
325350
```
326351

327352
Bootstrap Flux on production by setting the context and path to your production cluster:
328353

329354
```sh
330355
flux bootstrap github \
356+
--components-extra=source-watcher \
331357
--context=production \
332358
--owner=${GITHUB_USER} \
333359
--repository=${GITHUB_REPO} \
@@ -341,14 +367,14 @@ Watch the production reconciliation:
341367
```console
342368
$ flux get kustomizations --watch
343369

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
370+
NAME REVISION READY MESSAGE
371+
flux-system main@sha1:a7be7dff True Applied revision: main@sha1:a7be7dff
372+
infra-controllers latest@sha256:c0ac3648 True Applied revision: latest@sha256:c0ac3648
373+
infra-configs latest@sha256:c0ac3648 True Applied revision: latest@sha256:c0ac3648
374+
apps latest@sha256:26785ee4 True Applied revision: latest@sha256:26785ee4
349375
```
350376

351-
## Add clusters
377+
### Add clusters
352378

353379
If you want to add a cluster to your fleet, first clone your repo locally:
354380

@@ -366,6 +392,7 @@ mkdir -p clusters/dev
366392
Copy the sync manifests from staging:
367393

368394
```sh
395+
cp clusters/staging/artifacts.yaml clusters/dev
369396
cp clusters/staging/infrastructure.yaml clusters/dev
370397
cp clusters/staging/apps.yaml clusters/dev
371398
```
@@ -383,6 +410,7 @@ Set the kubectl context and path to your dev cluster and bootstrap Flux:
383410

384411
```sh
385412
flux bootstrap github \
413+
--components-extra=source-watcher \
386414
--context=dev \
387415
--owner=${GITHUB_USER} \
388416
--repository=${GITHUB_REPO} \
@@ -391,57 +419,6 @@ flux bootstrap github \
391419
--path=clusters/dev
392420
```
393421

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-
445422
## Testing
446423

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

0 commit comments

Comments
 (0)