Skip to content

Commit

Permalink
Merge pull request #530 from kubeshop/razvantopliceanu/feat/validatin…
Browse files Browse the repository at this point in the history
…g-admission-policy

feat: basic working version of admission policy validator
  • Loading branch information
topliceanurazvan authored Oct 2, 2023
2 parents b09521c + f411a8b commit acd9b27
Show file tree
Hide file tree
Showing 13 changed files with 1,425 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-oranges-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@monokle/validation": patch
---

Add admission policy basic version
43 changes: 32 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
"@monokle/parser": "*",
"@types/isomorphic-fetch": "0.0.36",
"@types/lodash": "4.14.185",
"@types/pako": "^2.0.1",
"@types/require-from-string": "1.2.1",
"@types/uuid": "9.0.1",
"rimraf": "3.0.2",
"esbuild": "0.17.18",
"rimraf": "3.0.2",
"tiny-glob": "0.2.9",
"type-fest": "3.0.0",
"typescript": "4.8.3",
Expand All @@ -65,9 +66,11 @@
"@rollup/plugin-virtual": "3.0.1",
"ajv": "6.12.6",
"change-case": "4.1.2",
"get-random-values": "^3.0.0",
"isomorphic-fetch": "3.0.0",
"lodash": "4.17.21",
"node-fetch": "3.3.0",
"pako": "^2.1.0",
"require-from-string": "2.0.2",
"rollup": "3.18.0",
"uuid": "9.0.0",
Expand Down
86 changes: 86 additions & 0 deletions packages/validation/src/__tests__/MonokleValidator.vap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {expect, it} from 'vitest';
import {MonokleValidator} from '../MonokleValidator.js';

import {ResourceParser} from '../common/resourceParser.js';
import {DefaultPluginLoader} from '../pluginLoaders/PluginLoader';
import {ValidationConfig} from '@monokle/types';
import {DisabledFixer, SchemaLoader} from '../node.js';
import {
NAMESPACE,
VALIDATING_ADMISSION_POLICY,
VALIDATING_ADMISSION_POLICY_BINDING,
DEPLOYMENT,
} from './resources/admissionPolicy/BasicValidatorResources.js';
import {
PARAMS_CONFIG_MAP,
PARAMS_DEPLOYMENT,
PARAMS_NAMESPACE,
PARAMS_VALIDATING_ADMISSION_POLICY,
PARAMS_VALIDATING_ADMISSION_POLICY_BINDING,
} from './resources/admissionPolicy/ParamsValidatorResources.js';

it('test basic admission policy', async () => {
const parser = new ResourceParser();

const validator = createTestValidator(parser, {
plugins: {
'admission-policy': true,
},
});

const response = await validator.validate({
resources: [NAMESPACE, VALIDATING_ADMISSION_POLICY, VALIDATING_ADMISSION_POLICY_BINDING, DEPLOYMENT],
});

const hasErrors = response.runs.reduce((sum, r) => sum + r.results.length, 0);
expect(hasErrors).toBe(1);
});

it('test params admission policy', async () => {
const parser = new ResourceParser();

const validator = createTestValidator(parser, {
plugins: {
'admission-policy': true,
},
});

const response = await validator.validate({
resources: [
PARAMS_NAMESPACE,
PARAMS_VALIDATING_ADMISSION_POLICY,
PARAMS_VALIDATING_ADMISSION_POLICY_BINDING,
PARAMS_DEPLOYMENT,
PARAMS_CONFIG_MAP,
],
});

const hasErrors = response.runs.reduce((sum, r) => sum + r.results.length, 0);
expect(hasErrors).toBe(1);
});

function createTestValidator(parser: ResourceParser, config?: ValidationConfig) {
return new MonokleValidator(
{
loader: new DefaultPluginLoader(),
parser,
schemaLoader: new SchemaLoader(),
suppressors: [],
fixer: new DisabledFixer(),
},
config ?? {
plugins: {
'yaml-syntax': true,
'resource-links': true,
'kubernetes-schema': true,
'open-policy-agent': true,
},
settings: {
'kubernetes-schema': {
schemaVersion: '1.24.2',
},
debug: true,
},
}
);
}
Loading

0 comments on commit acd9b27

Please sign in to comment.