Skip to content

Commit

Permalink
Merge pull request #540 from kubeshop/razvantopliceanu/fix/metadata-y…
Browse files Browse the repository at this point in the history
…aml-path

fix: metadata yaml path
  • Loading branch information
topliceanurazvan authored Oct 10, 2023
2 parents 2bf13c0 + e1f893d commit fcc298a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-colts-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@monokle/validation": patch
---

Add key to metadata yaml path
33 changes: 17 additions & 16 deletions packages/validation/src/__tests__/MonokleValidator.metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/validation/src/validators/metadata/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions packages/validation/src/validators/metadata/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`
)
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit fcc298a

Please sign in to comment.