Skip to content

Commit 68f719c

Browse files
jiangzhopeter-toth
authored andcommitted
[SPARK-54120] Update assertGeneratedCRDMatchesHelmChart to include diff
### What changes were proposed in this pull request? Enhance existing test assertGeneratedCRDMatchesHelmChart to give diff upon failure ### Why are the changes needed? For better readability. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Self-contained upon success & manually tested failure scenario - e.g. remove some fields from CRD inhelm repo, the test would fail with message like ``` * What went wrong: Execution failed for task ':spark-operator-api:assertGeneratedCRDMatchesHelmChart'. > Generated CRD yaml does not match the staged version in Helm Chart, please keep the chart updated. === SparkApplication CRD Differences === --- /dev/fd/63 2025-10-31 14:33:55 +++ /dev/fd/62 2025-10-31 14:33:55 -6355,11 +6355,6 properties: currentAttemptSummary: properties: - attemptInfo: - properties: - id: - type: integer - type: object stateTransitionHistory: additionalProperties: properties: === SparkCluster CRD Differences === --- /dev/fd/63 2025-10-31 14:33:55 +++ /dev/fd/62 2025-10-31 14:33:55 -7218,8 +7218,6 type: string lastTransitionTime: type: string - message: - type: string type: object type: object type: object ``` Which gives a more clear indication about the exact failure ### Was this patch authored or co-authored using generative AI tooling? No Closes #414 from jiangzho/crd_diff. Authored-by: Zhou JIANG <[email protected]> Signed-off-by: Peter Toth <[email protected]>
1 parent f1cb200 commit 68f719c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

spark-operator-api/build.gradle

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,31 @@ tasks.register("assertGeneratedCRDMatchesHelmChart") {
8989
"${stagedCRDFileBase}sparkclusters.spark.apache.org-v1.yaml"
9090
].execute().text.trim()
9191
if (generatedAppCRD != stagedAppCRD || generatedClusterCRD != stagedClusterCRD) {
92-
throw new GradleException("Generated CRD yaml does not match the staged version in " +
93-
"Helm Chart, please keep the chart updated.")
92+
def errorMessage = new StringBuilder("Generated CRD yaml does not match the staged " +
93+
"version in Helm Chart, please keep the chart updated.\n\n")
94+
95+
if (generatedAppCRD != stagedAppCRD) {
96+
errorMessage.append("=== SparkApplication CRD Differences ===\n")
97+
def appDiff = ["bash", "-c",
98+
"diff -u <(echo '${generatedAppCRD.replace("'", "'\\''")}' " +
99+
"| yq -P 'sort_keys(..)') <(echo '${stagedAppCRD.replace("'", "'\\''")}' " +
100+
"| yq -P 'sort_keys(..)')"]
101+
.execute().text
102+
errorMessage.append(appDiff ?: "Unable to generate diff\n")
103+
errorMessage.append("\n")
104+
}
105+
106+
if (generatedClusterCRD != stagedClusterCRD) {
107+
errorMessage.append("=== SparkCluster CRD Differences ===\n")
108+
def clusterDiff = ["bash", "-c",
109+
"diff -u <(echo '${generatedClusterCRD.replace("'", "'\\''")}' " +
110+
"| yq -P 'sort_keys(..)') <(echo '${stagedClusterCRD.replace("'", "'\\''")}' " +
111+
"| yq -P 'sort_keys(..)')"]
112+
.execute().text
113+
errorMessage.append(clusterDiff ?: "Unable to generate diff\n")
114+
}
115+
116+
throw new GradleException(errorMessage.toString())
94117
}
95118
}
96119
}

0 commit comments

Comments
 (0)