Skip to content

Commit c92e3c9

Browse files
committed
CP-34996: add tests to validate persitent volume works as expected
This mostly just adds some tests to the persistent volume support to make sure it continues to work as expected. However, I also changed the conditional to be based on server.persistentVolume.enabled instead of requiring server.persistentVolume to be set to {}.
1 parent e9ce932 commit c92e3c9

8 files changed

+304
-3
lines changed

helm/templates/agent-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
{{- else }}
1717
replicas: 1
1818
{{- end }}
19-
{{- if .Values.server.persistentVolume }}
19+
{{- if .Values.server.persistentVolume.enabled }}
2020
strategy:
2121
type: Recreate
2222
{{- end }}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
suite: test persistent volume configuration
2+
templates:
3+
- templates/agent-deploy.yaml
4+
- templates/agent-pvc.yaml
5+
tests:
6+
# Test persistent volume disabled (default behavior)
7+
- it: should use emptyDir when persistentVolume is disabled
8+
template: templates/agent-deploy.yaml
9+
set:
10+
apiKey: "test-key"
11+
existingSecretName: null
12+
server.persistentVolume.enabled: false
13+
asserts:
14+
# Verify emptyDir is used for storage
15+
- contains:
16+
path: spec.template.spec.volumes
17+
content:
18+
name: cloudzero-agent-storage-volume
19+
emptyDir:
20+
sizeLimit: 8Gi
21+
# Verify strategy is not set (should use default RollingUpdate)
22+
- isNull:
23+
path: spec.strategy
24+
25+
# Test persistent volume enabled - basic configuration
26+
- it: should use PVC when persistentVolume is enabled
27+
template: templates/agent-deploy.yaml
28+
set:
29+
apiKey: "test-key"
30+
existingSecretName: null
31+
server.persistentVolume.enabled: true
32+
server.persistentVolume.size: 10Gi
33+
asserts:
34+
# Verify PVC is used for storage
35+
- contains:
36+
path: spec.template.spec.volumes
37+
content:
38+
name: cloudzero-agent-storage-volume
39+
persistentVolumeClaim:
40+
claimName: RELEASE-NAME-cz-server
41+
# Verify strategy is set to Recreate
42+
- equal:
43+
path: spec.strategy.type
44+
value: Recreate
45+
# Verify volume mount is configured
46+
- contains:
47+
path: spec.template.spec.containers[1].volumeMounts
48+
content:
49+
name: cloudzero-agent-storage-volume
50+
mountPath: /data
51+
subPath: ""
52+
53+
# Test PVC is created when enabled
54+
- it: should create PVC when persistentVolume is enabled
55+
template: templates/agent-pvc.yaml
56+
set:
57+
apiKey: "test-key"
58+
existingSecretName: null
59+
server.persistentVolume.enabled: true
60+
server.persistentVolume.size: 15Gi
61+
server.persistentVolume.storageClass: "fast-ssd"
62+
asserts:
63+
- isKind:
64+
of: PersistentVolumeClaim
65+
- equal:
66+
path: metadata.name
67+
value: RELEASE-NAME-cz-server
68+
- equal:
69+
path: spec.resources.requests.storage
70+
value: 15Gi
71+
- equal:
72+
path: spec.storageClassName
73+
value: fast-ssd
74+
75+
# Test PVC is not created when disabled
76+
- it: should not create PVC when persistentVolume is disabled
77+
template: templates/agent-pvc.yaml
78+
set:
79+
apiKey: "test-key"
80+
existingSecretName: null
81+
server.persistentVolume.enabled: false
82+
asserts:
83+
- hasDocuments:
84+
count: 0
85+
86+
# Test existing PVC claim name is used
87+
- it: should use existingClaim when specified
88+
template: templates/agent-deploy.yaml
89+
set:
90+
apiKey: "test-key"
91+
existingSecretName: null
92+
server.persistentVolume.enabled: true
93+
server.persistentVolume.existingClaim: "my-existing-pvc"
94+
asserts:
95+
- contains:
96+
path: spec.template.spec.volumes
97+
content:
98+
name: cloudzero-agent-storage-volume
99+
persistentVolumeClaim:
100+
claimName: my-existing-pvc
101+
# Should still use Recreate strategy with existing claim
102+
- equal:
103+
path: spec.strategy.type
104+
value: Recreate
105+
106+
# Test custom mount path
107+
- it: should use custom mountPath when specified
108+
template: templates/agent-deploy.yaml
109+
set:
110+
apiKey: "test-key"
111+
existingSecretName: null
112+
server.persistentVolume.enabled: true
113+
server.persistentVolume.mountPath: /custom/data/path
114+
server.persistentVolume.subPath: "prometheus-data"
115+
asserts:
116+
- contains:
117+
path: spec.template.spec.containers[1].volumeMounts
118+
content:
119+
name: cloudzero-agent-storage-volume
120+
mountPath: /custom/data/path
121+
subPath: "prometheus-data"
122+
123+
# Test persistent volume with agent mode (Prometheus)
124+
- it: should work with agent mode (Prometheus with --enable-feature=agent)
125+
template: templates/agent-deploy.yaml
126+
set:
127+
apiKey: "test-key"
128+
existingSecretName: null
129+
components.agent.mode: agent
130+
server.persistentVolume.enabled: true
131+
asserts:
132+
# Verify Prometheus container is used
133+
- equal:
134+
path: spec.template.spec.containers[1].name
135+
value: cloudzero-agent-server
136+
# Verify strategy is Recreate
137+
- equal:
138+
path: spec.strategy.type
139+
value: Recreate
140+
# Verify PVC is mounted
141+
- contains:
142+
path: spec.template.spec.volumes
143+
content:
144+
name: cloudzero-agent-storage-volume
145+
persistentVolumeClaim:
146+
claimName: RELEASE-NAME-cz-server
147+
148+
# Test persistent volume with server mode (standard Prometheus)
149+
- it: should work with server mode (standard Prometheus)
150+
template: templates/agent-deploy.yaml
151+
set:
152+
apiKey: "test-key"
153+
existingSecretName: null
154+
components.agent.mode: server
155+
server.persistentVolume.enabled: true
156+
asserts:
157+
# Verify Prometheus container is used
158+
- equal:
159+
path: spec.template.spec.containers[1].name
160+
value: cloudzero-agent-server
161+
# Verify strategy is Recreate
162+
- equal:
163+
path: spec.strategy.type
164+
value: Recreate
165+
# Verify PVC is mounted
166+
- contains:
167+
path: spec.template.spec.volumes
168+
content:
169+
name: cloudzero-agent-storage-volume
170+
persistentVolumeClaim:
171+
claimName: RELEASE-NAME-cz-server
172+
173+
# Test persistent volume with federated mode
174+
- it: should work with federated mode
175+
template: templates/agent-deploy.yaml
176+
set:
177+
apiKey: "test-key"
178+
existingSecretName: null
179+
components.agent.mode: federated
180+
server.persistentVolume.enabled: true
181+
asserts:
182+
# Verify Prometheus container is used
183+
- equal:
184+
path: spec.template.spec.containers[1].name
185+
value: cloudzero-agent-server
186+
# Verify strategy is Recreate
187+
- equal:
188+
path: spec.strategy.type
189+
value: Recreate
190+
# Verify PVC is mounted
191+
- contains:
192+
path: spec.template.spec.volumes
193+
content:
194+
name: cloudzero-agent-storage-volume
195+
persistentVolumeClaim:
196+
claimName: RELEASE-NAME-cz-server

helm/tests/server_deployment_name_independence_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ tests:
9999
set:
100100
apiKey: "test-key"
101101
existingSecretName: null
102-
components.agent.mode: clustered
102+
components.agent.mode: agent
103103
server.persistentVolume.enabled: true
104104
server.persistentVolume.size: 10Gi
105105
server.persistentVolume.accessModes:
@@ -117,7 +117,7 @@ tests:
117117
set:
118118
apiKey: "test-key"
119119
existingSecretName: null
120-
components.agent.mode: clustered
120+
components.agent.mode: agent
121121
server.persistentVolume.enabled: true
122122
server.persistentVolume.size: 10Gi
123123
server.persistentVolume.accessModes:

helm/values.schema.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,42 @@
54105410
}
54115411
}
54125412
}
5413+
},
5414+
{
5415+
"if": {
5416+
"properties": {
5417+
"components": {
5418+
"properties": {
5419+
"agent": {
5420+
"properties": {
5421+
"mode": {
5422+
"const": "clustered"
5423+
}
5424+
},
5425+
"type": "object"
5426+
}
5427+
},
5428+
"type": "object"
5429+
}
5430+
}
5431+
},
5432+
"then": {
5433+
"properties": {
5434+
"server": {
5435+
"properties": {
5436+
"persistentVolume": {
5437+
"properties": {
5438+
"enabled": {
5439+
"const": false
5440+
}
5441+
},
5442+
"type": "object"
5443+
}
5444+
},
5445+
"type": "object"
5446+
}
5447+
}
5448+
}
54135449
}
54145450
],
54155451
"anyOf": [

helm/values.schema.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,3 +2364,38 @@ allOf:
23642364
oneOf:
23652365
- type: "null"
23662366
- const: federated
2367+
2368+
# Conditional: Persistent volume constraint for clustered mode
2369+
#
2370+
# If components.agent.mode is "clustered" (Alloy mode), then
2371+
# server.persistentVolume.enabled must be false.
2372+
#
2373+
# This is necessary because:
2374+
# 1. Alloy doesn't use the persistent volume mount (it uses /tmp/alloy)
2375+
# 2. Alloy is designed for horizontal scaling with multiple replicas
2376+
# 3. Persistent volumes with ReadWriteOnce can't be shared across pods
2377+
# 4. The Recreate deployment strategy (required for PV) prevents proper
2378+
# rolling updates needed for multi-replica deployments
2379+
#
2380+
# In clustered/Alloy mode, metrics data should be transient and stored
2381+
# in remote storage via remote_write configuration.
2382+
- if:
2383+
properties:
2384+
components:
2385+
type: object
2386+
properties:
2387+
agent:
2388+
type: object
2389+
properties:
2390+
mode:
2391+
const: clustered
2392+
then:
2393+
properties:
2394+
server:
2395+
type: object
2396+
properties:
2397+
persistentVolume:
2398+
type: object
2399+
properties:
2400+
enabled:
2401+
const: false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Valid: Agent mode (Prometheus) with persistent volume enabled
2+
# Persistent volumes work fine with non-clustered modes (agent, server, federated)
3+
apiKey: "test-key"
4+
existingSecretName: null
5+
components:
6+
agent:
7+
mode: agent
8+
server:
9+
persistentVolume:
10+
enabled: true
11+
size: 10Gi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Valid: Clustered mode (Alloy) with persistent volume explicitly disabled
2+
# Persistent volumes are not supported in clustered mode
3+
apiKey: "test-key"
4+
existingSecretName: null
5+
components:
6+
agent:
7+
mode: clustered
8+
server:
9+
persistentVolume:
10+
enabled: false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Invalid: Clustered mode (Alloy) with persistent volume enabled
2+
# This should fail because persistent volumes are incompatible with clustered mode:
3+
# - Alloy uses /tmp/alloy for ephemeral storage, not the PV mount
4+
# - Clustered mode supports multiple replicas, but PVs with ReadWriteOnce can't be shared
5+
# - The Recreate deployment strategy (required for PV) prevents rolling updates
6+
apiKey: "test-key"
7+
existingSecretName: null
8+
components:
9+
agent:
10+
mode: clustered
11+
server:
12+
persistentVolume:
13+
enabled: true

0 commit comments

Comments
 (0)