From 2bf0da248d99a8ec89a06e74cdad31dab2b916f6 Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Thu, 22 Feb 2024 13:52:07 -0500 Subject: [PATCH] allow more characters in cluster name (#4316) --- dashboard/src/lib/clusters/types.ts | 31 ++++++------------- .../ClusterFormContextProvider.tsx | 1 + 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/dashboard/src/lib/clusters/types.ts b/dashboard/src/lib/clusters/types.ts index 66ec49c396..b650035f43 100644 --- a/dashboard/src/lib/clusters/types.ts +++ b/dashboard/src/lib/clusters/types.ts @@ -400,15 +400,16 @@ const cidrRangeValidator = z } ); +const clusterNameValidator = z + .string() + .min(1, { message: "Name must be at least 1 character" }) + .max(38, { message: "Name must be max 38 characters" }) + .regex(/^[a-z0-9-]{1,61}$/, { + message: 'Lowercase letters, numbers, and "-" only.', + }); const eksConfigValidator = z.object({ kind: z.literal("EKS"), - clusterName: z - .string() - .min(1, { message: "Name must be at least 1 character" }) - .max(31, { message: "Name must be max 31 characters" }) - .regex(/^[a-z0-9-]{1,61}$/, { - message: 'Lowercase letters, numbers, and "-" only.', - }), + clusterName: clusterNameValidator, clusterVersion: z.string().optional().default(""), region: awsRegionValidator, nodeGroups: eksNodeGroupValidator.array(), @@ -462,13 +463,7 @@ const eksConfigValidator = z.object({ }); const gkeConfigValidator = z.object({ kind: z.literal("GKE"), - clusterName: z - .string() - .min(1, { message: "Name must be at least 1 character" }) - .max(31, { message: "Name must be max 31 characters" }) - .regex(/^[a-z0-9-]{1,61}$/, { - message: 'Lowercase letters, numbers, and "-" only.', - }), + clusterName: clusterNameValidator, clusterVersion: z.string().optional().default(""), region: gcpRegionValidator, nodeGroups: gkeNodeGroupValidator.array(), @@ -476,13 +471,7 @@ const gkeConfigValidator = z.object({ }); const aksConfigValidator = z.object({ kind: z.literal("AKS"), - clusterName: z - .string() - .min(1, { message: "Name must be at least 1 character" }) - .max(31, { message: "Name must be max 31 characters" }) - .regex(/^[a-z0-9-]{1,61}$/, { - message: 'Lowercase letters, numbers, and "-" only.', - }), + clusterName: clusterNameValidator, clusterVersion: z.string().optional().default(""), region: azureRegionValidator, nodeGroups: aksNodeGroupValidator.array(), diff --git a/dashboard/src/main/home/infrastructure-dashboard/ClusterFormContextProvider.tsx b/dashboard/src/main/home/infrastructure-dashboard/ClusterFormContextProvider.tsx index 3bc6b6e179..83f8b47e08 100644 --- a/dashboard/src/main/home/infrastructure-dashboard/ClusterFormContextProvider.tsx +++ b/dashboard/src/main/home/infrastructure-dashboard/ClusterFormContextProvider.tsx @@ -107,6 +107,7 @@ const ClusterFormContextProvider: React.FC = ({ ); } if (Object.keys(errors).length > 0) { + // TODO: remove this and properly handle form validation errors console.log("errors", errors); } if (isHandlingPreflightChecks) {