1+ apiVersion : kyverno.io/v1
2+ kind : ClusterPolicy
3+ metadata :
4+ name : apache-spark-app-generate
5+ spec :
6+ rules :
7+ - name : generate-apache-spark-app
8+ match :
9+ all :
10+ - resources :
11+ kinds :
12+ - sparkoperator.k8s.io/v1beta2/SparkApplication
13+ operations :
14+ - CREATE
15+ context :
16+ - name : driverLabels
17+ variable :
18+ value : " {{ request.object.spec.driver.labels || `{}`}}"
19+ - name : driverLabelsConfValues
20+ variable :
21+ value : " {{ driverLabels | values(@) }}"
22+ - name : driverLabelsConfKeys
23+ variable :
24+ value : ' {{ map(&join(`""`, [`"spark.kubernetes.driver.labels."`, @]), keys({{driverLabels}}))}}'
25+ - name : driverLabelsConf
26+ variable :
27+ value : ' {{object_from_lists({{driverLabelsConfKeys}}, {{driverLabelsConfValues}})}})'
28+ - name : jobName
29+ variable :
30+ jmesPath : request.object.metadata.name
31+ - name : sparkVersion
32+ variable :
33+ jmesPath : request.object.spec.sparkVersion
34+ - name : dynamicAllocationEnabledConf
35+ variable :
36+ jmesPath : ' {"spark.dynamicAllocation.enabled": to_string(`{{request.object.spec.dynamicAllocation.enabled || false}}`)}'
37+ - name : executorInstancesContains
38+ variable :
39+ jmesPath : " `{{request.object.spec.executor.instances || `0`}}` != `0`"
40+ - name : executorInstancesConf
41+ variable :
42+ 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 }}`'
45+ generate :
46+ kind : SparkApplication
47+ apiVersion : spark.apache.org/v1alpha1
48+ name : " {{ request.object.metadata.name }}"
49+ namespace : " {{ request.object.metadata.namespace }}"
50+ data :
51+ kind : SparkApplication
52+ apiVersion : spark.apache.org/v1alpha1
53+ metadata :
54+ ownerReferences :
55+ - apiVersion : sparkoperator.k8s.io/v1beta2
56+ kind : SparkApplication
57+ name : " {{request.object.metadata.name}}"
58+ uid : " {{request.object.metadata.uid}}"
59+ name : " {{ request.object.metadata.name }}"
60+ namespace : " {{ request.object.metadata.namespace }}"
61+ labels : " {{ request.object.metadata.labels || `{}`}}"
62+ spec :
63+ mainClass : " {{ request.object.spec.mainClass }}"
64+ jars : " {{ request.object.spec.mainApplicationFile }}"
65+ driverArgs : " {{ request.object.spec.arguments }}"
66+ sparkConf : " {{ merge(`{{request.object.spec.sparkConf}}`, `{{ executorInstancesConf }}`, `{{ dynamicAllocationEnabledConf }}`, `{{ driverLabelsConf }}`)}}"
67+ runtimeVersions :
68+ sparkVersion : " {{ sparkVersion }}"
0 commit comments