Skip to content

Commit e3886af

Browse files
committed
Add complete test cases for SparkApplication
Signed-off-by: Abhay349 <[email protected]>
1 parent 2d6e8f8 commit e3886af

File tree

4 files changed

+287
-0
lines changed

4 files changed

+287
-0
lines changed

pkg/resourceinterpreter/default/thirdparty/resourcecustomizations/sparkoperator.k8s.io/v1beta2/SparkApplication/testdata/aggregatestatus-test.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# test case for aggregating status of SparkApplication
22
# case1. SparkApplication with three status items
3+
# case2. SparkApplication with single status item
4+
# case3. SparkApplication with no status items
35

46
name: "SparkApplication with three status items"
57
description: "Test aggregating status of SparkApplication with three status items"
@@ -114,3 +116,114 @@ statusItems:
114116
terminationTime: "2025-10-12T14:12:30Z"
115117
operation: AggregateStatus
116118
output:
119+
aggregatedStatus:
120+
apiVersion: sparkoperator.k8s.io/v1beta2
121+
kind: SparkApplication
122+
metadata:
123+
name: spark-pi
124+
namespace: default
125+
spec:
126+
type: Java
127+
mode: cluster
128+
image: spark:3.5.0
129+
imagePullPolicy: Always
130+
mainClass: org.apache.spark.examples.SparkPi
131+
mainApplicationFile: local:///opt/spark/examples/jars/spark-examples_2.12-3.5.0.jar
132+
sparkVersion: "3.5.0"
133+
sparkUIOptions:
134+
serviceLabels:
135+
test-label/v1: "true"
136+
restartPolicy:
137+
type: Never
138+
volumes:
139+
- name: test-volume
140+
hostPath:
141+
path: /tmp
142+
type: Directory
143+
driver:
144+
cores: 2
145+
memory: 512m
146+
labels:
147+
version: 3.5.0
148+
serviceAccount: spark-operator-spark
149+
volumeMounts:
150+
- name: test-volume
151+
mountPath: /tmp
152+
executor:
153+
cores: 1
154+
instances: 2
155+
memory: 1g
156+
memoryOverhead: 512m
157+
labels:
158+
version: 3.5.0
159+
volumeMounts:
160+
- name: test-volume
161+
mountPath: /tmp
162+
dynamicAllocation:
163+
enabled: true
164+
initialExecutors: 3
165+
minExecutors: 3
166+
maxExecutors: 10
167+
status:
168+
applicationState:
169+
state: FAILED
170+
executionAttempts: 6
171+
submissionAttempts: 4
172+
lastSubmissionAttemptTime: "2025-10-12T14:10:00Z"
173+
terminationTime: "2025-10-12T14:12:30Z"
174+
executorState:
175+
spark-pi-b5777a99d8b732a7-exec-1: COMPLETED
176+
spark-pi-b5777a99d8b732a7-exec-2: COMPLETED
177+
spark-pi-b5777a99d8b732a8-exec-1: RUNNING
178+
spark-pi-b5777a99d8b732a8-exec-2: RUNNING
179+
spark-pi-b5777a99d8b732a9-exec-1: FAILED
180+
spark-pi-b5777a99d8b732a9-exec-2: FAILED
181+
---
182+
name: "SparkApplication with single status item"
183+
description: "AggregateStatus should directly copy single member status"
184+
desiredObj:
185+
apiVersion: sparkoperator.k8s.io/v1beta2
186+
kind: SparkApplication
187+
metadata:
188+
name: spark-pi
189+
namespace: default
190+
statusItems:
191+
- status:
192+
applicationState:
193+
state: RUNNING
194+
executionAttempts: 2
195+
submissionAttempts: 1
196+
executorState:
197+
exec-1: RUNNING
198+
operation: AggregateStatus
199+
output:
200+
aggregatedStatus:
201+
apiVersion: sparkoperator.k8s.io/v1beta2
202+
kind: SparkApplication
203+
metadata:
204+
name: spark-pi
205+
namespace: default
206+
status:
207+
applicationState:
208+
state: RUNNING
209+
executionAttempts: 2
210+
submissionAttempts: 1
211+
executorState:
212+
exec-1: RUNNING
213+
---
214+
name: "SparkApplication with no status items"
215+
description: "AggregateStatus should return desiredObj unchanged"
216+
desiredObj:
217+
apiVersion: sparkoperator.k8s.io/v1beta2
218+
kind: SparkApplication
219+
metadata:
220+
name: spark-pi
221+
namespace: default
222+
operation: AggregateStatus
223+
output:
224+
aggregatedStatus:
225+
apiVersion: sparkoperator.k8s.io/v1beta2
226+
kind: SparkApplication
227+
metadata:
228+
name: spark-pi
229+
namespace: default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# test case for interpreting component of SparkApplication
2+
# case1. SparkApplication without dynamic allocation
3+
# case2. SparkApplication with dynamic allocation
4+
# case3. SparkApplication with non-JVM job
5+
6+
name: "SparkApplication interpret component without dynamic allocation"
7+
description: "Driver has 1 replica and executor uses spec.executor.instances"
8+
observedObj:
9+
apiVersion: sparkoperator.k8s.io/v1beta2
10+
kind: SparkApplication
11+
metadata:
12+
name: spark-pi
13+
namespace: default
14+
spec:
15+
type: Java
16+
driver:
17+
cores: 2
18+
memory: "1g"
19+
executor:
20+
cores: 1
21+
instances: 2
22+
memory: "1g"
23+
operation: InterpretComponent
24+
output:
25+
components:
26+
- name: driver
27+
replicas: 1
28+
replicaRequirements:
29+
resourceRequest:
30+
cpu: "2"
31+
memory: "1408Mi"
32+
- name: executor
33+
replicas: 2
34+
replicaRequirements:
35+
resourceRequest:
36+
cpu: "1"
37+
memory: "1408Mi"
38+
---
39+
name: "SparkApplication interpret component with dynamic allocation"
40+
description: "Executor replicas come from dynamicAllocation"
41+
observedObj:
42+
apiVersion: sparkoperator.k8s.io/v1beta2
43+
kind: SparkApplication
44+
metadata:
45+
name: spark-pi
46+
namespace: default
47+
spec:
48+
type: Java
49+
executor:
50+
instances: 1
51+
memory: "1g"
52+
dynamicAllocation:
53+
enabled: true
54+
initialExecutors: 3
55+
minExecutors: 2
56+
operation: InterpretComponent
57+
output:
58+
components:
59+
- name: driver
60+
replicas: 1
61+
replicaRequirements:
62+
resourceRequest:
63+
cpu: "1"
64+
memory: "1408Mi"
65+
- name: executor
66+
replicas: 3
67+
replicaRequirements:
68+
resourceRequest:
69+
cpu: "1"
70+
memory: "1408Mi"
71+
---
72+
name: "SparkApplication interpret component for non-JVM job"
73+
description: "Non-JVM jobs still produce driver and executor components"
74+
observedObj:
75+
apiVersion: sparkoperator.k8s.io/v1beta2
76+
kind: SparkApplication
77+
metadata:
78+
name: spark-pi
79+
namespace: default
80+
spec:
81+
type: Python
82+
executor:
83+
instances: 4
84+
operation: InterpretComponent
85+
output:
86+
components:
87+
- name: driver
88+
replicas: 1
89+
replicaRequirements:
90+
resourceRequest:
91+
cpu: "1"
92+
memory: "1503238553600m"
93+
- name: executor
94+
replicas: 4
95+
replicaRequirements:
96+
resourceRequest:
97+
cpu: "1"
98+
memory: "1503238553600m"
99+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# test case for interpreting health of SparkApplication
2+
# case1. SparkApplication healthy when state is COMPLETED
3+
# case2. SparkApplication unhealthy when state is FAILED
4+
# case3. SparkApplication unhealthy when status is missing
5+
6+
name: "SparkApplication healthy when state is COMPLETED"
7+
description: "Health should be true when applicationState is not FAILED"
8+
observedObj:
9+
apiVersion: sparkoperator.k8s.io/v1beta2
10+
kind: SparkApplication
11+
metadata:
12+
name: spark-pi
13+
namespace: default
14+
status:
15+
applicationState:
16+
state: COMPLETED
17+
operation: InterpretHealth
18+
output:
19+
healthy: true
20+
---
21+
name: "SparkApplication unhealthy when state is FAILED"
22+
description: "Health should be false when applicationState is FAILED"
23+
observedObj:
24+
apiVersion: sparkoperator.k8s.io/v1beta2
25+
kind: SparkApplication
26+
metadata:
27+
name: spark-pi
28+
namespace: default
29+
status:
30+
applicationState:
31+
state: FAILED
32+
operation: InterpretHealth
33+
output:
34+
healthy: false
35+
---
36+
name: "SparkApplication unhealthy when status is missing"
37+
description: "Health should be false when status or applicationState is nil"
38+
observedObj:
39+
apiVersion: sparkoperator.k8s.io/v1beta2
40+
kind: SparkApplication
41+
metadata:
42+
name: spark-pi
43+
namespace: default
44+
operation: InterpretHealth
45+
output:
46+
healthy: false

pkg/resourceinterpreter/default/thirdparty/resourcecustomizations/sparkoperator.k8s.io/v1beta2/SparkApplication/testdata/interpretstatus-test.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,32 @@ observedObj:
7575
terminationTime: "2025-10-12T13:58:39Z"
7676
operation: InterpretStatus
7777
output:
78+
status:
79+
applicationState:
80+
state: COMPLETED
81+
driverInfo:
82+
podName: spark-pi-driver
83+
webUIAddress: 10.11.254.226:4040
84+
webUIPort: 4040
85+
webUIServiceName: spark-pi-ui-svc
86+
executorState:
87+
spark-pi-b5777a99d8b732a7-exec-1: COMPLETED
88+
spark-pi-b5777a99d8b732a7-exec-2: COMPLETED
89+
sparkApplicationId: spark-ff27607fd312454b92455e2feabdd343
90+
lastSubmissionAttemptTime: "2025-10-12T13:57:17Z"
91+
submissionAttempts: 1
92+
executionAttempts: 1
93+
submissionID: 0df4a04b-620b-425e-997a-e4404010e26a
94+
terminationTime: "2025-10-12T13:58:39Z"
95+
---
96+
name: "SparkApplication interpret status with no status"
97+
description: "InterpretStatus should return empty status when observed status is nil"
98+
observedObj:
99+
apiVersion: sparkoperator.k8s.io/v1beta2
100+
kind: SparkApplication
101+
metadata:
102+
name: spark-pi
103+
namespace: default
104+
operation: InterpretStatus
105+
output:
106+
status: {}

0 commit comments

Comments
 (0)