Skip to content

Commit

Permalink
feat: handle failed to evaluate expression case
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed Sep 28, 2023
1 parent 719293a commit d37fe30
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const PARAMS_CONFIG_MAP: Resource = {
name: 'rule-config',
namespace: 'demo',
},
maxReplicas: 5,
data: {
maxReplicas: 5,
},
},
id: '174d42e877a174-0',
name: 'rule-config',
Expand Down Expand Up @@ -123,7 +125,7 @@ export const PARAMS_VALIDATING_ADMISSION_POLICY: Resource = {
},
validations: [
{
expression: 'object.spec.replicas > params.maxReplicas',
expression: 'object.spec.replicas > params.data.maxReplicas',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function loadWasm() {
loadGoGlueCode();
const go = new Go();

let buffer = pako.ungzip(await (await fetch('http://plugins.monokle.com/validation/cel.wasm.gz')).arrayBuffer());
let buffer = pako.ungzip(await (await fetch('https://plugins.monokle.com/validation/cel.wasm.gz')).arrayBuffer());

if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
buffer = pako.ungzip(buffer);
Expand Down
8 changes: 8 additions & 0 deletions packages/validation/src/validators/admission-policy/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ export const ADMISSION_POLICY_RULES: RuleMetadata[] = [
text: 'Check whether the admission policy conditions are met.',
},
},
{
id: 'VAP002',
name: 'admission-policy-failed-to-evaluate',
shortDescription: {text: "Admission policy couldn't be evaluated"},
help: {
text: 'Check whether the admission policy expression is properly written.',
},
},
];
12 changes: 12 additions & 0 deletions packages/validation/src/validators/admission-policy/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ export class AdmissionPolicyValidator extends AbstractPlugin {
return [];
}

if (output.includes('failed to evaluate')) {
return [
this.adaptToValidationResult(
resource,
['kind'],
'VAP002',
message ?? 'Admission policy failed to evaluate expression',
level
),
].filter(isDefined);
}

return [
this.adaptToValidationResult(
resource,
Expand Down

0 comments on commit d37fe30

Please sign in to comment.