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+
118apiVersion : kyverno.io/v1
219kind : ClusterPolicy
320metadata :
@@ -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}}`)}'
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 }}"
0 commit comments