Skip to content

Commit

Permalink
fix: intermediate fix that ignores lastProbeTime/creationTimestamp va…
Browse files Browse the repository at this point in the history
…lidation errors
  • Loading branch information
olensmar committed Nov 16, 2021
1 parent 4ccea88 commit fb215c9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/redux/services/validation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {K8sResource} from '@models/k8sresource';
import log from 'loglevel';
import Ajv, {ValidateFunction} from 'ajv';
import log from 'loglevel';

import {isKustomizationPatch} from '@redux/services/kustomize';

import {K8sResource} from '@models/k8sresource';

import {getResourceSchema} from './schema';

/**
* Validates the specified resource against its JSON Schema and adds validation details
*/

const ignoredProperties = ['lastProbeTime', 'creationTimestamp'];
const validatorCache = new Map<string, ValidateFunction>();

export function validateResource(resource: K8sResource) {
Expand All @@ -28,11 +32,11 @@ export function validateResource(resource: K8sResource) {
const validate = validatorCache.get(resource.kind);
if (validate) {
try {
const validationResult = validate(resource.content);
resource.validation = {
isValid: Boolean(validationResult),
errors: validate.errors
? validate.errors.map(err => {
validate(resource.content);
const errors = validate.errors
? validate.errors
.filter(err => !ignoredProperties.some(ignored => err.dataPath.endsWith(ignored)))
.map(err => {
const error = {
property: err.dataPath,
message: err.message || 'message',
Expand All @@ -45,7 +49,11 @@ export function validateResource(resource: K8sResource) {
}
return error;
})
: [],
: [];

resource.validation = {
isValid: errors.length === 0,
errors,
};
} catch (e) {
log.warn('Failed to validate', e);
Expand Down

0 comments on commit fb215c9

Please sign in to comment.