diff --git a/packages/validation/src/__tests__/MonokleValidator.test.ts b/packages/validation/src/__tests__/MonokleValidator.test.ts index afad4307e..9945fba3e 100644 --- a/packages/validation/src/__tests__/MonokleValidator.test.ts +++ b/packages/validation/src/__tests__/MonokleValidator.test.ts @@ -70,6 +70,14 @@ it("should support relative folder paths in kustomizations", async () => { expect(hasErrors).toBe(16); }); +it("should support patches and additionalValuesFiles", async () => { + const {response} = await processResourcesInFolder("src/__tests__/resources/kustomize-5.0.0-patches-and-values-files"); + + const hasErrors = response.runs.reduce((sum, r) => sum + r.results.length, 0); + expect(hasErrors).toBe(2); +}); + + it("should be flexible to configure", async () => { const parser = new ResourceParser(); diff --git a/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/kustomization.yaml b/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/kustomization.yaml new file mode 100644 index 000000000..e7830f83a --- /dev/null +++ b/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +patches: + - path: patches/existing-patch.yaml + - path: patches/missing-patch.yaml + +helmCharts: + - name: testChart + additionalValuesFiles: + - valuesFiles/existing-values.yaml + - valuesFiles/missing-values.yaml diff --git a/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/patches/existing-patch.yaml b/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/patches/existing-patch.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/valuesFiles/existing-values.yaml b/packages/validation/src/__tests__/resources/kustomize-5.0.0-patches-and-values-files/valuesFiles/existing-values.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/packages/validation/src/references/utils/kustomizeRefs.ts b/packages/validation/src/references/utils/kustomizeRefs.ts index eeba5b442..01a57008f 100644 --- a/packages/validation/src/references/utils/kustomizeRefs.ts +++ b/packages/validation/src/references/utils/kustomizeRefs.ts @@ -145,8 +145,8 @@ function extractPatches( patchPath: string, parser: ResourceParser ) { - let strategicMergePatches = getScalarNodes(kustomization, patchPath, parser); - strategicMergePatches + let patchPaths = getScalarNodes(kustomization, patchPath, parser); + patchPaths .filter((refNode) => refNode.node.type === "PLAIN") .filter(refNode => !isExternalResourceRef(refNode)) .forEach((refNode: NodeWrapper) => { @@ -192,13 +192,6 @@ export function processKustomizations( ) { resources .filter((r) => isKustomizationResource(r)) - .filter( - (k) => - k.content.resources || - k.content.bases || - k.content.patchesStrategicMerge || - k.content.patchesJson6902 - ) .forEach((kustomization) => { let resourceNodes = getScalarNodes(kustomization, "resources", parser); if (kustomization.content.bases) { @@ -236,6 +229,29 @@ export function processKustomizations( parser ); } + if (kustomization.content.patches) { + extractPatches( + kustomization, + files, + resources, + "patches:path", + parser + ); + } + + // extract refs to additional helm values files introduced in Kustomize 5.0.0 + if (kustomization.content.helmCharts) { + let valuesPaths = getScalarNodes(kustomization, "helmCharts:additionalValuesFiles", parser); + valuesPaths.filter((refNode) => refNode.node.type === "PLAIN") + .filter(refNode => !isExternalResourceRef(refNode)) + .forEach((refNode: NodeWrapper) => { + let targetPath = path.join( + path.parse(kustomization.filePath).dir, + refNode.nodeValue() + ); + createKustomizationFileRef(kustomization, refNode, targetPath, files); + }); + } }); }