Skip to content
Merged
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 @@ -181,6 +181,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"}}'
Comment on lines +187 to +188
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
vars:
DRY_RUN: '{{.DRY_RUN | default "false"}}'
vars:
DRY_RUN:
default: false

I can't imagine we actually want to support setting an ENV for DRY_RUN which is very specific to this one task and not something you likely want set permanently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think the variable is already scoped locally to the helm-preflight task only.

I committed the suggestion but it looks like it is not valid Taskfile syntax

err:  "default" is not a valid variable type. Try "sh", "ref", "map" or using a scalar value
file: /Users/gerard/dev/platform-examples/applications/wg-easy/Taskfile.yaml:180:9
  178 |     vars:
  179 |       DRY_RUN:
> 180 |         default: false
      |         ^
  181 |     cmds: 
  182 |       - |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so the syntax wasn't correct but it can still be done can't it?

vars:
  DRY_RUN: false

Or something like that?

I'm asking why you're explicitly making a dynamic variable when you don't need it to be dynamic. I think you're copying a pattern that we setup when we were setting global variables and importing environments but I don't think it is necessary here.

Maybe I'm just misunderstanding Taskfile and this isn't possible or the dynamic nature of using "{{.DRY_RUN}}" provides some value that I'm not aware of. Does including "{{.DRY_RUN}}" provide some value or is that the only way to set a variable?

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 @@ -492,6 +511,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 }}
18 changes: 13 additions & 5 deletions applications/wg-easy/docs/development-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,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 ./charts/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 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