Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added kustomization support for validating patches and additionalValuesFiles #221

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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