-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from kubeshop/razvantopliceanu/feat/validatin…
…g-admission-policy feat: basic working version of admission policy validator
- Loading branch information
Showing
13 changed files
with
1,425 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@monokle/validation": patch | ||
--- | ||
|
||
Add admission policy basic version |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/validation/src/__tests__/MonokleValidator.vap.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
); | ||
} |
Oops, something went wrong.