Skip to content

Commit ded2303

Browse files
committed
Generate driver labels
1 parent 130e10a commit ded2303

File tree

7 files changed

+50
-97
lines changed

7 files changed

+50
-97
lines changed

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
- name: Run E2E Test with Dynamic Configuration Enabled
147147
if: matrix.mode == 'dynamic'
148148
run: |
149-
chainsaw test --test-dir ./tests/e2e/${{ matrix.test-group }} --parallel 2
149+
chainsaw test --test-dir ./tests/e2e/${{ matrix.test-group }} --parallel 2
150150
151151
lint:
152152
name: "Linter and documentation"

migration/apache-spark-app-generate-policy.yaml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
118
apiVersion: kyverno.io/v1
219
kind: ClusterPolicy
320
metadata:
@@ -15,22 +32,24 @@ spec:
1532
context:
1633
- name: driverLabels
1734
variable:
18-
value: "{{ request.object.spec.driver.labels || `{}`}}"
35+
jmesPath: "items(request.object.spec.driver.labels || `{}`, 'key', 'value')"
1936
- name: driverLabelsConfValues
2037
variable:
21-
value: "{{ driverLabels | values(@) }}"
38+
value: "{{ driverLabels | [].value }}"
2239
- name: driverLabelsConfKeys
2340
variable:
24-
value: '{{ map(&join(`""`, [`"spark.kubernetes.driver.labels."`, @]), keys({{driverLabels}}))}}'
41+
value: "{{ map(&join('.', ['spark', 'kubernetes', 'driver', 'label', @]), driverLabels | [].key) }}"
2542
- name: driverLabelsConf
2643
variable:
27-
value: '{{object_from_lists({{driverLabelsConfKeys}}, {{driverLabelsConfValues}})}})'
44+
jmesPath: object_from_lists(driverLabelsConfKeys, driverLabelsConfValues)
2845
- name: jobName
2946
variable:
30-
jmesPath: request.object.metadata.name
47+
value: "{{request.object.metadata.name}}"
48+
jmesPath: 'to_string(@)'
3149
- name: sparkVersion
3250
variable:
33-
jmesPath: request.object.spec.sparkVersion
51+
value: "{{request.object.spec.sparkVersion}}"
52+
jmesPath: 'to_string(@)'
3453
- name: dynamicAllocationEnabledConf
3554
variable:
3655
jmesPath: '{"spark.dynamicAllocation.enabled": to_string(`{{request.object.spec.dynamicAllocation.enabled || false}}`)}'
@@ -40,8 +59,22 @@ spec:
4059
- name: executorInstancesConf
4160
variable:
4261
jmesPath: '[{"key": `true`, "value": {"spark.executor.instances": to_string(`{{request.object.spec.executor.instances || "foo"}}`)}}, {"key": `false`, "value": `{}`}][?key==`{{executorInstancesContains}}`]|[0].value'
43-
reportProperties:
44-
sparkAppName: '`{{ jobName }}`'
62+
- name: sparkContainerImageConf
63+
variable:
64+
value:
65+
spark.kubernetes.container.image: "{{ request.object.spec.image }}"
66+
- name: sparkK8sDriverServiceAccountConf
67+
variable:
68+
value:
69+
spark.kubernetes.authenticate.driver.serviceAccountName: "{{request.object.spec.driver.serviceAccount}}"
70+
- name: sparkConf
71+
variable:
72+
jmesPath: request.object.spec.sparkConf
73+
default: {}
74+
- name: sparkConf
75+
variable:
76+
jmesPath: merge(sparkConf, sparkK8sDriverServiceAccountConf, sparkContainerImageConf,
77+
driverLabelsConf, executorInstancesConf)
4578
generate:
4679
kind: SparkApplication
4780
apiVersion: spark.apache.org/v1alpha1
@@ -58,11 +91,11 @@ spec:
5891
uid: "{{request.object.metadata.uid}}"
5992
name: "{{ request.object.metadata.name }}"
6093
namespace: "{{ request.object.metadata.namespace }}"
61-
labels: "{{ request.object.metadata.labels || `{}`}}"
6294
spec:
6395
mainClass: "{{ request.object.spec.mainClass }}"
6496
jars: "{{ request.object.spec.mainApplicationFile }}"
6597
driverArgs: "{{ request.object.spec.arguments }}"
66-
sparkConf: "{{ merge(`{{request.object.spec.sparkConf}}`, `{{ executorInstancesConf }}`, `{{ dynamicAllocationEnabledConf }}`, `{{ driverLabelsConf }}`)}}"
98+
sparkConf:
99+
"{{ sparkConf }}"
67100
runtimeVersions:
68101
sparkVersion: "{{ sparkVersion }}"

migration/foo.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

spark-pi.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/e2e/assertions/spark-application/spark-apache-pi.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ metadata:
2424
- apiVersion: "sparkoperator.k8s.io/v1beta2"
2525
kind: "SparkApplication"
2626
name: "spark-pi"
27-
# uid: "*"
2827
spec:
2928
mainClass: "org.apache.spark.examples.SparkPi"
3029
jars: "local:///opt/spark/examples/jars/spark-examples_2.12-3.5.2.jar"
@@ -35,11 +34,7 @@ spec:
3534
spark.kubernetes.container.image: "spark:3.5.2"
3635
spark.kubernetes.driver.label.version: "3.5.2"
3736
spark.kubernetes.driver.label.nodeType: "p1"
38-
spark.driver.cores: "1"
39-
spark.driver.memory: "512m"
40-
spark.kubernetes.authenticate.driver.serviceAccountName: "spark"
41-
spark.executor.memory: "512m"
37+
spark.kubernetes.authenticate.driver.serviceAccountName: "spark-sa"
4238
spark.executor.instances: "10"
43-
spark.executor.cores: "2"
4439
runtimeVersions:
4540
sparkVersion: "3.5.2"

tests/e2e/migration/chainsaw-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
- create:
3232
file: spark-kubeflow-pi.yaml
3333
- assert:
34-
timeout: 2m
34+
timeout: 1m
3535
file: "../assertions/spark-application/spark-apache-pi.yaml"
3636
finally:
3737
- script:

tests/e2e/migration/spark-kubeflow-pi.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ spec:
3434
sparkVersion: 3.5.2
3535
driver:
3636
labels:
37-
version: 3.5.2
38-
nodeType: p1
39-
cores: 1
40-
memory: 512m
41-
serviceAccount: spark
37+
version: "3.5.2"
38+
nodeType: "p1"
39+
serviceAccount: spark-sa
4240
executor:
43-
instances: 10
44-
cores: 2
45-
memory: 512m
41+
instances: 10

0 commit comments

Comments
 (0)