Skip to content

Commit

Permalink
Merge pull request #221 from kubeshop/olelensmar/fix/kustomize-5.0.0-…
Browse files Browse the repository at this point in the history
…parsing

feat: added kustomization support for validating patches and additionalValuesFiles
  • Loading branch information
olensmar authored Feb 13, 2023
2 parents a4c6ec2 + ee84322 commit abf11b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
8 changes: 8 additions & 0 deletions packages/validation/src/__tests__/MonokleValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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
34 changes: 25 additions & 9 deletions packages/validation/src/references/utils/kustomizeRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});
}
});
}

Expand Down

0 comments on commit abf11b6

Please sign in to comment.