From 27aaf322b216bc475bc7363846ad0f007a94e7e2 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Sun, 10 Mar 2024 09:42:33 +0200 Subject: [PATCH] fix(kube/config): validate change window start [EE-6830] (#11329) --- .../ConfigureView/ConfigureForm/validation.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/react/kubernetes/cluster/ConfigureView/ConfigureForm/validation.ts b/app/react/kubernetes/cluster/ConfigureView/ConfigureForm/validation.ts index bb5c3def9..8313118e3 100644 --- a/app/react/kubernetes/cluster/ConfigureView/ConfigureForm/validation.ts +++ b/app/react/kubernetes/cluster/ConfigureView/ConfigureForm/validation.ts @@ -1,5 +1,7 @@ import { object, string, boolean, array, number, SchemaOf } from 'yup'; +import { isBE } from '@/react/portainer/feature-flags/feature-flags.service'; + import { IngressControllerClassMap } from '../../ingressClass/types'; import { ConfigureFormValues } from './types'; @@ -37,6 +39,20 @@ const storageClassFormValuesSchema = array() } ); +// Define Yup schema for EndpointChangeWindow +const endpointChangeWindowSchema = object().shape({ + Enabled: boolean().required(), + StartTime: string().test( + 'startTime should not be the same as endTime', + 'The chosen time configuration is invalid.', + (value, context) => { + const { EndTime, Enabled } = context.parent; + return !Enabled || value !== EndTime; + } + ), + EndTime: string(), +}); + // Define Yup schema for IngressControllerClassMap const ingressControllerClassMapSchema: SchemaOf = object().shape({ @@ -58,6 +74,7 @@ export const configureValidationSchema: SchemaOf = object({ restrictStandardUserIngressW: boolean().required(), ingressAvailabilityPerNamespace: boolean().required(), allowNoneIngressClass: boolean().required(), + changeWindow: isBE ? endpointChangeWindowSchema.required() : undefined, storageClasses: storageClassFormValuesSchema.required(), ingressClasses: array().of(ingressControllerClassMapSchema).required(), });