Skip to content

Commit 198e3c8

Browse files
jiangzhodongjoon-hyun
authored andcommitted
[SPARK-52702] Verify generated CRD yaml with Helm chart crds content
### What changes were proposed in this pull request? This PR adds a gradle task to compare latest CRD version vs the one used by Helm charts ### Why are the changes needed? To avoid potential human error when updating spark-operator-api ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? CIs ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#283 from jiangzho/crd_validator. Authored-by: Zhou JIANG <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 311c5fd commit 198e3c8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

spark-operator-api/build.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,43 @@ tasks.register('relocateGeneratedCRD', Copy) {
5757
into "../build-tools/helm/spark-kubernetes-operator/crds"
5858
rename '(.+).yml', '$1.yaml'
5959
}
60+
61+
tasks.register("assertGeneratedCRDMatchesHelmChart") {
62+
dependsOn 'finalizeGeneratedCRD'
63+
description = 'Asserts that the generated CRD yaml matches the staged version in Helm Chart'
64+
doLast {
65+
def currentPath = projectDir.absolutePath
66+
def generatedCRDFileBase = "$currentPath/build/classes/java/main/META-INF/fabric8/"
67+
def stagedCRDFileBase = "$currentPath/../build-tools/helm/spark-kubernetes-operator/crds/"
68+
def generatedAppCRD = [
69+
"yq",
70+
"e",
71+
".spec.versions[0]",
72+
"${generatedCRDFileBase}sparkapplications.spark.apache.org-v1.yml"
73+
].execute().text.trim()
74+
def generatedClusterCRD = [
75+
"yq",
76+
"e",
77+
".spec.versions[0]",
78+
"${generatedCRDFileBase}sparkclusters.spark.apache.org-v1.yml"
79+
].execute().text.trim()
80+
def stagedAppCRD = [
81+
"yq",
82+
"e",
83+
".spec.versions[-1]",
84+
"${stagedCRDFileBase}sparkapplications.spark.apache.org-v1.yaml"
85+
].execute().text.trim()
86+
def stagedClusterCRD = [
87+
"yq",
88+
"e",
89+
".spec.versions[-1]",
90+
"${stagedCRDFileBase}sparkclusters.spark.apache.org-v1.yaml"
91+
].execute().text.trim()
92+
if (generatedAppCRD != stagedAppCRD || generatedClusterCRD != stagedClusterCRD) {
93+
throw new GradleException("Generated CRD yaml does not match the staged version in " +
94+
"Helm Chart, please keep the chart updated.")
95+
}
96+
}
97+
}
98+
99+
test.finalizedBy('assertGeneratedCRDMatchesHelmChart')

0 commit comments

Comments
 (0)