Skip to content

Commit a4d7404

Browse files
authored
feat: wg-easy add preflights (#59)
Adds preflight command and spec for cert-manager and wg-easy charts.
1 parent 4d24cb6 commit a4d7404

File tree

8 files changed

+103
-11
lines changed

8 files changed

+103
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ applications/wg-easy/release/
5252
.aider*
5353
# SpecStory explanation file
5454
.specstory/.what-is-this.md
55+
*.tar.gz

applications/wg-easy/Taskfile.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ tasks:
181181
deps:
182182
- cluster-create
183183

184+
helm-preflight:
185+
desc: Run preflight checks on Helm charts using preflight CLI (use DRY_RUN=true for dry-run)
186+
silent: false
187+
vars:
188+
DRY_RUN: '{{.DRY_RUN | default "false"}}'
189+
cmds:
190+
- |
191+
PREFLIGHT_FLAGS=""
192+
if [ "{{.DRY_RUN}}" = "true" ]; then
193+
PREFLIGHT_FLAGS="--dry-run"
194+
fi
195+
196+
for chart_dir in $(find charts/ -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
197+
echo "Running preflight on $chart_dir"
198+
helm template $chart_dir | kubectl preflight - $PREFLIGHT_FLAGS
199+
done
200+
deps:
201+
- setup-kubeconfig
202+
184203
helm-install:
185204
desc: Install all charts using helmfile
186205
silent: false
@@ -492,6 +511,7 @@ tasks:
492511
- task: setup-kubeconfig
493512
- task: cluster-ports-expose
494513
- task: dependencies-update
514+
- task: helm-preflight
495515
- task: helm-install
496516
- task: test
497517
- task: cluster-delete
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{- define "cert-manager.preflight" -}}
2+
apiVersion: troubleshoot.sh/v1beta2
3+
kind: Preflight
4+
metadata:
5+
name: cert-manager-preflights
6+
spec:
7+
analyzers:
8+
# https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/README.template.md#prerequisites
9+
- clusterVersion:
10+
outcomes:
11+
- fail:
12+
when: "< 1.22.0"
13+
message: The application requires at least Kubernetes 1.22.0, and recommends 1.25.0.
14+
uri: https://cert-manager.io/docs/installation/helm/#prerequisites
15+
- warn:
16+
when: "< 1.25.0"
17+
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.25.0 or later.
18+
uri: https://cert-manager.io/docs/installation/helm/#prerequisites
19+
- pass:
20+
message: Your cluster meets the recommended and required versions of Kubernetes.
21+
{{- end -}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: cert-manager-preflights
5+
labels:
6+
troubleshoot.sh/kind: preflight
7+
type: Opaque
8+
stringData:
9+
preflight.yaml: |
10+
{{ include "cert-manager.preflight" . | indent 4 }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- define "wg-easy.preflight" -}}
2+
apiVersion: troubleshoot.sh/v1beta2
3+
kind: Preflight
4+
metadata:
5+
name: wg-easy-preflights
6+
spec:
7+
collectors:
8+
- sysctl:
9+
image: debian:buster-slim
10+
analyzers:
11+
- sysctl:
12+
checkName: IP forwarding enabled
13+
outcomes:
14+
- fail:
15+
when: 'net.ipv4.ip_forward == 0'
16+
message: "IP forwarding must be enabled. To enable it, edit /etc/sysctl.conf, add or uncomment the line 'net.ipv4.ip_forward=1', and run 'sudo sysctl -p'."
17+
- pass:
18+
when: 'net.ipv4.ip_forward == 1'
19+
message: "IP forwarding is enabled."
20+
{{- end -}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: wg-easy-preflights
5+
labels:
6+
troubleshoot.sh/kind: preflight
7+
type: Opaque
8+
stringData:
9+
preflight.yaml: |
10+
{{ include "wg-easy.preflight" . | indent 4 }}

applications/wg-easy/docs/development-workflow.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,41 @@ Deploy individual charts to a test cluster to verify functionality.
135135
task setup-kubeconfig
136136
```
137137

138-
2. Install a single chart:
138+
2. Run preflight checks on your chart:
139+
140+
```bash
141+
task helm-preflight
142+
# Or for a single chart with dry-run:
143+
helm template ./charts/wg-easy | kubectl preflight - --dry-run
144+
```
145+
146+
3. Install a single chart:
139147

140148
```bash
141149
helm install cert-manager ./charts/cert-manager -n cert-manager --create-namespace
142150
```
143151

144-
3. Verify the deployment:
152+
4. Verify the deployment:
145153

146154
```bash
147155
kubectl get pods -n cert-manager
148156
```
149157

150-
4. Test chart functionality:
158+
5. Test chart functionality:
151159

152160
```bash
153161
# Example: Test cert-manager with a test certificate
154162
kubectl apply -f ./some-test-certificate.yaml
155163
kubectl get certificate -A
156164
```
157165

158-
5. Uninstall when done or making changes and repeat step 2:
166+
6. Uninstall when done or making changes and repeat step 3:
159167

160168
```bash
161169
helm uninstall cert-manager -n cert-manager
162170
```
163171

164-
**Validation point**: Chart should deploy successfully and function as expected.
172+
**Validation point**: Preflight checks should pass without errors, and the chart should deploy successfully and function as expected.
165173

166174
### Stage 5: Integration Testing with helmfile
167175

applications/wg-easy/docs/task-reference.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ These tasks support the iterative development process, focusing on fast feedback
99
| Task | Description | Related Workflow Stage |
1010
|------|-------------|------------------------|
1111
| `dependencies-update` | Updates Helm dependencies for all charts in the repository | Stage 1: Dependencies |
12-
| `helm-deploy` | Deploys all charts using helmfile with proper sequencing | Stage 5: Integration Testing |
12+
| `helm-preflight` | Runs preflight checks on Helm charts using the preflight CLI | Stage 4: Validation |
13+
| `helm-install` | Installs all charts using helmfile with proper sequencing | Stage 5: Integration Testing |
1314
| `ports-expose` | Exposes the configured ports on the cluster for testing | Stage 4-5: Chart Installation/Integration |
1415
| `remove-k3s-traefik` | Removes pre-installed Traefik from k3s clusters to avoid conflicts | Stage 4-5: Chart Installation/Integration |
1516

1617
### Common Development Combinations
1718

1819
**Complete Update and Deploy:**
1920
```bash
20-
task update-dependencies && task deploy-helm
21+
task update-dependencies && task helm-install
2122
```
2223

2324
**Single Chart Testing:**
@@ -94,9 +95,9 @@ This task performs the following sequence:
9495
1. Creates a cluster
9596
2. Sets up the kubeconfig
9697
3. Exposes ports
97-
4. Removes pre-installed Traefik
98-
5. Updates dependencies
99-
6. Deploys all charts
98+
4. Updates dependencies
99+
5. Runs preflight checks on charts
100+
6. Installs all charts
100101
7. Runs tests
101102
8. Deletes the cluster
102103

@@ -109,6 +110,7 @@ Many tasks accept parameters to customize their behavior. Here are the most comm
109110
| `CLUSTER_NAME` | `cluster-create`, `setup-kubeconfig` | Name for the cluster | "test-cluster" |
110111
| `K8S_VERSION` | `cluster-create` | Kubernetes version | "1.32.2" |
111112
| `DISTRIBUTION` | `cluster-create` | Cluster distribution | "k3s" |
113+
| `DRY_RUN` | `helm-preflight` | Run preflight checks in dry-run mode | "false" |
112114
| `CHANNEL` | `release-create` | Channel to promote to | "Unstable" |
113115
| `RELEASE_NOTES` | `release-create` | Notes for the release | "" |
114116
| `GCP_PROJECT` | `gcp-vm-create` | GCP project ID | Required |
@@ -121,7 +123,7 @@ Parameters in the Taskfile.yaml try to always have defaults so that it works out
121123
These tasks are designed to support the progressive complexity approach:
122124

123125
1. **Early Stages** - Use `dependencies-update` and helm commands directly
124-
2. **Middle Stages** - Use `cluster-create`, `helm-deploy`, and `test`
126+
2. **Middle Stages** - Use `cluster-create`, `helm-install`, and `test`
125127
3. **Later Stages** - Use `release-prepare`, `release-create`, and embedded cluster tasks
126128

127129
This organization allows developers to focus on the appropriate level of complexity at each stage of development.

0 commit comments

Comments
 (0)