Skip to content

Commit abff445

Browse files
Merge pull request #21 from cookielab/feat/complex-add-tests
test(complex): add helm-unittest suites and testing-values for recent…
2 parents d421b35 + 08ee730 commit abff445

34 files changed

Lines changed: 3251 additions & 31 deletions

.github/workflows/ci.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ jobs:
8282
helm lint complex -f complex/testing-values/values-volume-mounts.yaml
8383
helm lint complex -f complex/testing-values/values-initcontainers.yaml
8484
helm lint complex -f complex/testing-values/values-pvc-efs-shared.yaml
85+
helm lint complex -f complex/testing-values/values-recreate.yaml
86+
helm lint complex -f complex/testing-values/values-host-network.yaml
87+
helm lint complex -f complex/testing-values/values-node-name.yaml
8588
8689
template-test:
8790
runs-on: ubuntu-latest
@@ -123,7 +126,10 @@ jobs:
123126
helm template test ./complex --debug -f complex/testing-values/values-pod-disruption-budget.yaml
124127
helm template test ./complex --debug -f complex/testing-values/values-initcontainers.yaml
125128
helm template test ./complex --debug -f complex/testing-values/values-pvc-efs-shared.yaml
126-
129+
helm template test ./complex --debug -f complex/testing-values/values-recreate.yaml
130+
helm template test ./complex --debug -f complex/testing-values/values-host-network.yaml
131+
helm template test ./complex --debug -f complex/testing-values/values-node-name.yaml
132+
127133
# Test infrastructure configurations
128134
helm template test ./complex --debug -f complex/testing-values/values-ingress.yaml
129135
helm template test ./complex --debug -f complex/testing-values/values-values-from.yaml
@@ -133,6 +139,29 @@ jobs:
133139
helm template test ./complex --debug -f complex/testing-values/values-volume-mounts.yaml
134140
helm template test ./complex --debug -f complex/testing-values/values-tolerations.yaml
135141
142+
unit-test:
143+
runs-on: ubuntu-latest
144+
needs: init
145+
steps:
146+
- uses: actions/checkout@v6
147+
148+
- name: Install Helm
149+
uses: azure/setup-helm@v5
150+
with:
151+
version: '3.13.0'
152+
153+
- name: Download dependencies
154+
uses: actions/download-artifact@v8
155+
with:
156+
name: helm-dependencies
157+
path: complex/charts
158+
159+
- name: Install helm-unittest plugin
160+
run: helm plugin install https://github.com/helm-unittest/helm-unittest --version 1.0.3
161+
162+
- name: Run unit tests
163+
run: helm unittest complex
164+
136165
docs-check:
137166
runs-on: ubuntu-latest
138167
steps:

complex/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: complex
33
description: For deploying applications with consumers and cronjobs
44
type: application
5-
version: 1.8.3
5+
version: 1.8.4
66
kubeVersion: ">= 1.25.0-0 < 2.0.0-0"
77

88
dependencies:

complex/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# complex
44

5-
![Version: 1.6.0](https://img.shields.io/badge/Version-1.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
5+
![Version: 1.8.4](https://img.shields.io/badge/Version-1.8.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
66

77
For deploying applications, consumers and cronjobs
88

@@ -222,7 +222,6 @@ Each init container supports the same properties as regular containers:
222222
| `resources` | CPU/memory requests and limits | No |
223223
| `volumeMounts` | Mount ConfigMaps or Secrets as files | No |
224224

225-
226225
## Configuration Structure
227226

228227
### Global vs Component-Specific Configuration

complex/README.md.gotmpl

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The **complex** Helm chart provides a comprehensive solution for deploying conta
1515
- **ConfigMap integration**: Environment variables and file mounting from ConfigMaps
1616
- **Secret integration**: Environment variables and file mounting from Secrets
1717
- **Volume mounts**: Mount ConfigMaps and Secrets as files with custom paths
18+
- **Persistent storage**: Create new PVCs or reference existing ones for shared storage (EFS)
1819
- **Consumer workloads**: Support for consumer-type deployments
1920
- **CronJob support**: Scheduled job execution
2021
- **Enterprise features**: Immutable ConfigMaps, custom labels/annotations
@@ -355,6 +356,122 @@ components:
355356
secrets: [] # Empty array = no secret volumes
356357
```
357358

359+
## Persistent Volume Claims
360+
361+
The chart supports creating PersistentVolumeClaims (PVCs) for components that need persistent storage. You can either create a new PVC or reference an existing one to share storage across multiple pods.
362+
363+
### Creating a New PVC
364+
365+
When `persistentVolumeClaim` is configured without `useExistingClaim`, the chart creates a new PVC for the component:
366+
367+
```yaml
368+
components:
369+
api:
370+
type: http
371+
persistentVolumeClaim:
372+
size: 10Gi
373+
accessModes:
374+
- ReadWriteOnce
375+
storageClassName: standard
376+
# Optional: Add custom annotations (e.g., for EFS access points)
377+
annotations:
378+
efs.csi.aws.com/access-point-id: "fsap-0123456789abcdef0"
379+
# Optional: Add custom labels
380+
labels:
381+
storage-tier: "premium"
382+
volumeMounts:
383+
others:
384+
- name: data
385+
mountPath: /app/data
386+
readOnly: false
387+
```
388+
389+
**PVC Properties:**
390+
391+
| Property | Type | Default | Description |
392+
|----------|------|---------|-------------|
393+
| `size` | string | `"1Gi"` | Storage size (e.g., "1Gi", "10Gi") |
394+
| `accessModes` | array | `["ReadWriteOnce"]` | Access modes: `ReadWriteOnce`, `ReadOnlyMany`, `ReadWriteMany`, `ReadWriteOncePod` |
395+
| `storageClassName` | string | - | Storage class name for the PVC |
396+
| `annotations` | object | `{}` | Custom annotations (useful for storage-specific configurations) |
397+
| `labels` | object | `{}` | Custom labels |
398+
| `selector` | object | - | Label selector for binding to specific PVs |
399+
| `volumeName` | string | - | Name of the PersistentVolume to bind to |
400+
401+
### Using an Existing PVC
402+
403+
To share storage across multiple pods or reference a PVC created outside the chart, use `useExistingClaim`:
404+
405+
```yaml
406+
components:
407+
api:
408+
type: http
409+
persistentVolumeClaim:
410+
useExistingClaim: true
411+
existingClaimName: "shared-storage-pvc"
412+
volumeMounts:
413+
others:
414+
- name: data
415+
mountPath: /app/data
416+
readOnly: false
417+
418+
worker:
419+
type: consumer
420+
persistentVolumeClaim:
421+
useExistingClaim: true
422+
existingClaimName: "shared-storage-pvc" # Same PVC as api component
423+
volumeMounts:
424+
others:
425+
- name: data
426+
mountPath: /data
427+
readOnly: false
428+
```
429+
430+
**Benefits of Using Existing PVCs:**
431+
432+
- **Shared storage**: Multiple pods can mount the same PVC (requires `ReadWriteMany` access mode)
433+
- **Pre-existing storage**: Reference PVCs created manually or by other charts
434+
- **Storage reuse**: Avoid creating duplicate PVCs for the same storage
435+
436+
**Important Notes:**
437+
438+
- When `useExistingClaim: true`, the chart does **not** create a PVC - it only references the existing one
439+
- The existing PVC must already exist in the same namespace
440+
- Ensure the PVC's access mode supports your use case (e.g., `ReadWriteMany` for multi-pod access)
441+
442+
### Complete Example
443+
444+
```yaml
445+
components:
446+
# Component that creates a new PVC
447+
web:
448+
type: http
449+
persistentVolumeClaim:
450+
size: 5Gi
451+
accessModes:
452+
- ReadWriteMany # Allows multiple pods to mount
453+
storageClassName: efs-sc
454+
annotations:
455+
efs.csi.aws.com/access-point-id: "fsap-0123456789abcdef0"
456+
volumeMounts:
457+
others:
458+
- name: data
459+
mountPath: /usr/share/nginx/html
460+
461+
# Component that uses the existing PVC created above
462+
api:
463+
type: http
464+
persistentVolumeClaim:
465+
useExistingClaim: true
466+
existingClaimName: "my-release-web" # References the PVC created by web component
467+
volumeMounts:
468+
others:
469+
- name: data
470+
mountPath: /app/data
471+
```
472+
473+
See `testing-values/values-pvc.yaml` and `testing-values/values-pvc-efs-shared.yaml` for more examples.
474+
358475
## Installation
359476

360477
```bash
@@ -445,6 +562,8 @@ The following complete configuration examples are available in the `testing-valu
445562
- [`values-minimal.yaml`](testing-values/values-minimal.yaml) - Basic HTTP service
446563
- [`values-configmap.yaml`](testing-values/values-configmap.yaml) - ConfigMap integration
447564
- [`values-volume-mounts.yaml`](testing-values/values-volume-mounts.yaml) - Volume mount examples
565+
- [`values-pvc.yaml`](testing-values/values-pvc.yaml) - PersistentVolumeClaim examples
566+
- [`values-pvc-efs-shared.yaml`](testing-values/values-pvc-efs-shared.yaml) - Shared storage with existing PVCs
448567
- [`values-consumer.yaml`](testing-values/values-consumer.yaml) - Consumer workloads
449568
- [`values-cronjob.yaml`](testing-values/values-cronjob.yaml) - Scheduled jobs
450569
- [`values-hpa.yaml`](testing-values/values-hpa.yaml) - Auto-scaling configuration

complex/templates/_container.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ volumeMounts:
5050
{{- range . }}
5151
- name: {{ .name }}
5252
mountPath: {{ .mountPath }}
53-
readOnly: {{ .readOnly | default true }}
53+
readOnly: {{ ne .readOnly false }}
5454
{{- if .subPath }}
5555
subPath: {{ .subPath }}
5656
{{- end }}
@@ -60,7 +60,7 @@ volumeMounts:
6060
{{- range . }}
6161
- name: {{ .name }}
6262
mountPath: {{ .mountPath }}
63-
readOnly: {{ .readOnly | default true }}
63+
readOnly: {{ ne .readOnly false }}
6464
{{- if .subPath }}
6565
subPath: {{ .subPath }}
6666
{{- end }}

complex/templates/deployment.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ metadata:
2020
spec:
2121
replicas: {{ $component.replicas }}
2222
progressDeadlineSeconds: {{ default 300 $component.progressDeadlineSeconds }}
23-
{{- if eq (default "RollingUpdate" $component.strategyType) "Recreate" }}
2423
strategy:
25-
type: Recreate
26-
{{- else }}
27-
strategy:
28-
type: RollingUpdate
24+
type: {{ default "RollingUpdate" $component.strategyType }}
25+
{{- if ne (default "RollingUpdate" $component.strategyType) "Recreate" }}
2926
rollingUpdate:
3027
maxUnavailable: {{ coalesce (index $component "rollingUpdate" | default dict).maxUnavailable $.Values.global.rollingUpdate.maxUnavailable | quote}}
3128
maxSurge: {{ coalesce (index $component "rollingUpdate" | default dict).maxSurge $.Values.global.rollingUpdate.maxSurge | quote}}
32-
{{- end }}
29+
{{- end }}
3330
selector:
3431
matchLabels:
3532
{{ include "cookielab.kubernetes.labels.selector" $kubeLabels | indent 6 | trim }}

complex/templates/keda-scaledobject.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
triggers:
1919
{{- range $i, $trigger := $keda.triggers }}
2020
{{- if eq $trigger.type "kafka" }}
21-
{{- $awsRegion := $trigger.awsRegion | default $.Values.global.keda.awsRegion }}
21+
{{- $awsRegion := $trigger.awsRegion | default ($.Values.global.keda).awsRegion }}
2222
{{- if (not $awsRegion) }}
2323
{{- fail (printf "Kafka trigger for '%s' is missing required field(s)." $componentName) }}
2424
{{- end }}
@@ -41,7 +41,7 @@ spec:
4141
{{- end }}
4242

4343
{{- else if eq $trigger.type "aws-sqs-queue" }}
44-
{{- $awsRegion := $trigger.awsRegion | default $.Values.global.keda.awsRegion }}
44+
{{- $awsRegion := $trigger.awsRegion | default ($.Values.global.keda).awsRegion }}
4545
{{- if (not $awsRegion) }}
4646
{{- fail (printf "SQS trigger for '%s' is missing required field(s)." $componentName) }}
4747
{{- end }}

complex/templates/keda-triggerauthentication.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{- if and (eq $component.type "consumer") (hasKey $component "keda") }}
33
{{- $name := include "component.name" (dict "name" $componentName "Release" $.Release) }}
44
{{- range $i, $trigger := $component.keda.triggers }}
5-
{{- if and (eq $trigger.type "aws-sqs-queue") (ne (default "operator" $trigger.identityOwner) "operator") (default true $trigger.triggerAuthEnabled) }}
5+
{{- if and (eq $trigger.type "aws-sqs-queue") (ne (default "operator" $trigger.identityOwner) "operator") (ne $trigger.triggerAuthEnabled false) }}
66
---
77
apiVersion: keda.sh/v1alpha1
88
kind: TriggerAuthentication

complex/templates/serviceaccount.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{- if and (ne $component.type "cronjob") (ne $component.type "pre-job") (ne $component.type "ingress") -}}
33
{{- $kubeLabels := (merge (dict "name" $.Release.Name "instance" (printf "%s-%d" (include "component.name" (dict "name" $componentName "Release" $.Release)) $.Release.Revision) "component" $componentName) $.Values.global.metadata) -}}
44
{{- if and $component.serviceAccountCreate $component.serviceAccountName }}
5-
--
5+
---
66
apiVersion: v1
77
kind: ServiceAccount
88
metadata:
@@ -16,7 +16,7 @@ metadata:
1616
{{- end }}
1717
{{- end }}
1818

19-
{{- if and .Values.global.serviceAccountCreate -}}
19+
{{- if .Values.global.serviceAccountCreate }}
2020
---
2121
apiVersion: v1
2222
kind: ServiceAccount
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
global:
2+
container:
3+
image:
4+
repository: cookielab/deployer
5+
tag: 1.0.0-rc2
6+
7+
components:
8+
edge:
9+
type: http
10+
replicas: 1
11+
hostNetwork: true
12+
dnsPolicy: ClusterFirstWithHostNet
13+
strategyType: Recreate
14+
ports:
15+
- port: 8443
16+
probes:
17+
readinessProbe:
18+
httpGet:
19+
port: 8443
20+
path: /health-check
21+
scheme: HTTPS
22+
livenessProbe:
23+
httpGet:
24+
port: 8443
25+
path: /health-check
26+
scheme: HTTPS
27+
targetGroup:
28+
arn: 'arn:fake'
29+
securityGroupIds:
30+
- sg-fake
31+
worker-on-host:
32+
type: consumer
33+
replicas: 1
34+
hostNetwork: true
35+
dnsPolicy: ClusterFirstWithHostNet
36+
command:
37+
- bin/consume
38+
scheduled-host-task:
39+
type: cronjob
40+
schedule: "*/5 * * * *"
41+
hostNetwork: true
42+
dnsPolicy: ClusterFirstWithHostNet
43+
command:
44+
- bin/cron-task

0 commit comments

Comments
 (0)