Skip to content

feat: wg-easy add preflights #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ applications/wg-easy/release/
.aider*
# SpecStory explanation file
.specstory/.what-is-this.md
*.tar.gz
20 changes: 20 additions & 0 deletions applications/wg-easy/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ tasks:
deps:
- cluster-create

helm-preflight:
desc: Run preflight checks on Helm charts using preflight CLI (use DRY_RUN=true for dry-run)
silent: false
vars:
DRY_RUN: '{{.DRY_RUN | default "false"}}'
cmds:
- |
PREFLIGHT_FLAGS=""
if [ "{{.DRY_RUN}}" = "true" ]; then
PREFLIGHT_FLAGS="--dry-run"
fi

for chart_dir in $(find charts/ -maxdepth 2 -name "Chart.yaml" | xargs dirname); do
echo "Running preflight on $chart_dir"
helm template $chart_dir | kubectl preflight - $PREFLIGHT_FLAGS
done
deps:
- setup-kubeconfig

helm-install:
desc: Install all charts using helmfile
silent: false
Expand Down Expand Up @@ -483,6 +502,7 @@ tasks:
- task: setup-kubeconfig
- task: cluster-ports-expose
- task: dependencies-update
- task: helm-preflight
- task: helm-install
- task: test
- task: cluster-delete
21 changes: 21 additions & 0 deletions applications/wg-easy/charts/cert-manager/templates/_preflight.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- define "cert-manager.preflight" -}}
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
name: cert-manager-preflights
spec:
analyzers:
# https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/README.template.md#prerequisites
- clusterVersion:
outcomes:
- fail:
when: "< 1.22.0"
message: The application requires at least Kubernetes 1.22.0, and recommends 1.25.0.
uri: https://cert-manager.io/docs/installation/helm/#prerequisites
- warn:
when: "< 1.25.0"
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.25.0 or later.
uri: https://cert-manager.io/docs/installation/helm/#prerequisites
- pass:
message: Your cluster meets the recommended and required versions of Kubernetes.
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: cert-manager-preflights
labels:
troubleshoot.sh/kind: preflight
type: Opaque
stringData:
preflight.yaml: |
{{ include "cert-manager.preflight" . | indent 4 }}
20 changes: 20 additions & 0 deletions applications/wg-easy/charts/wg-easy/templates/_preflight.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- define "wg-easy.preflight" -}}
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
name: wg-easy-preflights
spec:
collectors:
- sysctl:
image: debian:buster-slim
analyzers:
- sysctl:
checkName: IP forwarding enabled
outcomes:
- fail:
when: 'net.ipv4.ip_forward == 0'
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'."
- pass:
when: 'net.ipv4.ip_forward == 1'
message: "IP forwarding is enabled."
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: wg-easy-preflights
labels:
troubleshoot.sh/kind: preflight
type: Opaque
stringData:
preflight.yaml: |
{{ include "wg-easy.preflight" . | indent 4 }}
20 changes: 14 additions & 6 deletions applications/wg-easy/docs/development-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,41 @@ Deploy individual charts to a test cluster to verify functionality.
task setup-kubeconfig
```

2. Install a single chart:
2. Run preflight checks on your chart:

```bash
task helm-preflight
# Or for a single chart with dry-run:
helm template ./charts/wg-easy | kubectl preflight - --dry-run
```

3. Install a single chart:

```bash
helm install cert-manager ./cert-manager -n cert-manager --create-namespace
```

3. Verify the deployment:
4. Verify the deployment:

```bash
kubectl get pods -n cert-manager
```

4. Test chart functionality:
5. Test chart functionality:

```bash
# Example: Test cert-manager with a test certificate
kubectl apply -f ./some-test-certificate.yaml
kubectl get certificate -A
```

5. Uninstall when done or making changes and repeat step 2:
6. Uninstall when done or making changes and repeat step 3:

```bash
helm uninstall cert-manager -n cert-manager
```

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

### Stage 5: Integration Testing with helmfile

Expand All @@ -172,7 +180,7 @@ Test multiple charts working together using Helmfile orchestration.
2. Deploy all charts:

```bash
task helm-deploy
task helm-install
```

3. Verify cross-component integration:
Expand Down
14 changes: 8 additions & 6 deletions applications/wg-easy/docs/task-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ These tasks support the iterative development process, focusing on fast feedback
| Task | Description | Related Workflow Stage |
|------|-------------|------------------------|
| `dependencies-update` | Updates Helm dependencies for all charts in the repository | Stage 1: Dependencies |
| `helm-deploy` | Deploys all charts using helmfile with proper sequencing | Stage 5: Integration Testing |
| `helm-preflight` | Runs preflight checks on Helm charts using the preflight CLI | Stage 4: Validation |
| `helm-install` | Installs all charts using helmfile with proper sequencing | Stage 5: Integration Testing |
| `ports-expose` | Exposes the configured ports on the cluster for testing | Stage 4-5: Chart Installation/Integration |
| `remove-k3s-traefik` | Removes pre-installed Traefik from k3s clusters to avoid conflicts | Stage 4-5: Chart Installation/Integration |

### Common Development Combinations

**Complete Update and Deploy:**
```bash
task update-dependencies && task deploy-helm
task update-dependencies && task helm-install
```

**Single Chart Testing:**
Expand Down Expand Up @@ -94,9 +95,9 @@ This task performs the following sequence:
1. Creates a cluster
2. Sets up the kubeconfig
3. Exposes ports
4. Removes pre-installed Traefik
5. Updates dependencies
6. Deploys all charts
4. Updates dependencies
5. Runs preflight checks on charts
6. Installs all charts
7. Runs tests
8. Deletes the cluster

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

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

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