From 5a174ab1932d3a2c0d791e6d9c03e9168c1af17b Mon Sep 17 00:00:00 2001 From: Topliceanu Razvan <47887589+topliceanurazvan@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:18:43 +0300 Subject: [PATCH 1/3] fix: add key to full path --- packages/validation/src/validators/metadata/rules.ts | 2 +- packages/validation/src/validators/metadata/validator.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/validation/src/validators/metadata/rules.ts b/packages/validation/src/validators/metadata/rules.ts index b5803c848..8e7aa0a91 100644 --- a/packages/validation/src/validators/metadata/rules.ts +++ b/packages/validation/src/validators/metadata/rules.ts @@ -14,7 +14,7 @@ export const METADATA_RULES: RuleMetadata[] = [ text: 'Add all recommended labels. You can hover the key for documentation.', }, defaultConfiguration: { - level: 'error', + level: 'warning', // Based on https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/ parameters: { configValue: [ diff --git a/packages/validation/src/validators/metadata/validator.ts b/packages/validation/src/validators/metadata/validator.ts index 92cb2de0e..183c4138f 100644 --- a/packages/validation/src/validators/metadata/validator.ts +++ b/packages/validation/src/validators/metadata/validator.ts @@ -113,7 +113,7 @@ export class MetadataValidator extends AbstractPlugin { .map(key => this.adaptToValidationResult( resource, - ['metadata', isLabelRule ? 'labels' : 'annotations'], + ['metadata', isLabelRule ? 'labels' : 'annotations', key], rule.id, `Missing valid '${key}' ${isLabelRule ? 'label' : 'annotation'} in '${resource.kind}'${expectedValuesText}.` ) @@ -179,7 +179,7 @@ export class MetadataValidator extends AbstractPlugin { const region = this.resourceParser.parseErrorRegion(resource, valueNode.range); - const locations = createLocations(resource, region); + const locations = createLocations(resource, region, path); return this.createValidationResult(ruleId, { message: { From 0af6ba5002cd5ab7a80dd3a705f41d49d807f735 Mon Sep 17 00:00:00 2001 From: Topliceanu Razvan <47887589+topliceanurazvan@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:19:10 +0300 Subject: [PATCH 2/3] chore: changeset --- .changeset/fifty-colts-stare.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fifty-colts-stare.md diff --git a/.changeset/fifty-colts-stare.md b/.changeset/fifty-colts-stare.md new file mode 100644 index 000000000..f3074f5ad --- /dev/null +++ b/.changeset/fifty-colts-stare.md @@ -0,0 +1,5 @@ +--- +"@monokle/validation": patch +--- + +Add key to metadata yaml path From e1f893db26ca10767bf57781295ca9460d89766f Mon Sep 17 00:00:00 2001 From: Topliceanu Razvan <47887589+topliceanurazvan@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:34:06 +0300 Subject: [PATCH 3/3] fix: tests --- .../MonokleValidator.metadata.test.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/validation/src/__tests__/MonokleValidator.metadata.test.ts b/packages/validation/src/__tests__/MonokleValidator.metadata.test.ts index 4f52bcdda..0d1fb9909 100644 --- a/packages/validation/src/__tests__/MonokleValidator.metadata.test.ts +++ b/packages/validation/src/__tests__/MonokleValidator.metadata.test.ts @@ -21,20 +21,20 @@ it('should detect missing recommended labels (MTD-recommended-labels)', async () expect(hasErrors).toBe(4); const result1 = response.runs[0].results[0]; - expectResult(result1, 'MTD-recommended-labels', 'error', 'ReplicaSet'); - expect(result1.message.text).toMatch('app.kubernetes.io/component'); + expectResult(result1, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); + expect(result1.message.text).toMatch('app.kubernetes.io/part-of'); const result2 = response.runs[0].results[1]; - expectResult(result2, 'MTD-recommended-labels', 'error', 'ReplicaSet'); - expect(result2.message.text).toMatch('app.kubernetes.io/managed'); + expectResult(result2, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); + expect(result2.message.text).toMatch('app.kubernetes.io/version'); const result3 = response.runs[0].results[2]; - expectResult(result3, 'MTD-recommended-labels', 'error', 'ReplicaSet'); - expect(result3.message.text).toMatch('app.kubernetes.io/part-of'); + expectResult(result3, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); + expect(result3.message.text).toMatch('app.kubernetes.io/managed'); const result4 = response.runs[0].results[3]; - expectResult(result4, 'MTD-recommended-labels', 'error', 'ReplicaSet'); - expect(result4.message.text).toMatch('app.kubernetes.io/version'); + expectResult(result4, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); + expect(result4.message.text).toMatch('app.kubernetes.io/component'); }); it('should not override recommended labels but allow to config level (MTD-recommended-labels)', async () => { @@ -48,19 +48,19 @@ it('should not override recommended labels but allow to config level (MTD-recomm const result1 = response.runs[0].results[0]; expectResult(result1, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); - expect(result1.message.text).toMatch('app.kubernetes.io/component'); + expect(result1.message.text).toMatch('app.kubernetes.io/part-of'); const result2 = response.runs[0].results[1]; expectResult(result2, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); - expect(result2.message.text).toMatch('app.kubernetes.io/managed'); + expect(result2.message.text).toMatch('app.kubernetes.io/version'); const result3 = response.runs[0].results[2]; expectResult(result3, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); - expect(result3.message.text).toMatch('app.kubernetes.io/part-of'); + expect(result3.message.text).toMatch('app.kubernetes.io/managed'); const result4 = response.runs[0].results[3]; expectResult(result4, 'MTD-recommended-labels', 'warning', 'ReplicaSet'); - expect(result4.message.text).toMatch('app.kubernetes.io/version'); + expect(result4.message.text).toMatch('app.kubernetes.io/component'); }); it('should detect missing custom labels (MTD-custom-labels)', async () => { @@ -90,14 +90,15 @@ it('should detect missing annotations labels (MTD-custom-annotations)', async () expect(hasErrors).toBe(2); const result1 = response.runs[0].results[0]; + expectResult(result1, 'MTD-custom-annotations', 'warning', 'ReplicaSet'); - expectMatchList(result1.message.text, ['annotation-1']); - expectNotMatchList(result1.message.text, ['revision', 'hash', 'annotation-2']); + expectMatchList(result1.message.text, ['annotation-2']); + expectNotMatchList(result1.message.text, ['revision', 'hash', 'annotation-1']); const result2 = response.runs[0].results[1]; expectResult(result2, 'MTD-custom-annotations', 'warning', 'ReplicaSet'); - expectMatchList(result2.message.text, ['annotation-2']); - expectNotMatchList(result2.message.text, ['revision', 'hash', 'annotation-1']); + expectMatchList(result2.message.text, ['annotation-1']); + expectNotMatchList(result2.message.text, ['revision', 'hash', 'annotation-2']); }); it('should not trigger when predefined custom rules have no names defined (MTD-custom-labels, MTD-custom-annotations)', async () => {