diff --git a/app/kubernetes/react/components/index.ts b/app/kubernetes/react/components/index.ts index 94e8f9394..e47d6d58e 100644 --- a/app/kubernetes/react/components/index.ts +++ b/app/kubernetes/react/components/index.ts @@ -142,7 +142,14 @@ export const ngModule = angular ), { stackName: 'setStackName' } ), - ['setStackName', 'stackName', 'stacks', 'inputClassName', 'textTip'] + [ + 'setStackName', + 'stackName', + 'stacks', + 'inputClassName', + 'textTip', + 'error', + ] ) ) .component( diff --git a/app/kubernetes/views/applications/create/createApplication.html b/app/kubernetes/views/applications/create/createApplication.html index 23ca602cf..0dffb4380 100644 --- a/app/kubernetes/views/applications/create/createApplication.html +++ b/app/kubernetes/views/applications/create/createApplication.html @@ -172,6 +172,7 @@ text-tip="'Enter or select a \'stack\' name to group multiple deployments together, or else leave empty to ignore.'" stacks="ctrl.stacks" input-class-name="'col-lg-10 col-sm-9'" + error="ctrl.state.stackNameError" > @@ -234,6 +235,7 @@ text-tip="'Enter or select a \'stack\' name to group multiple deployments together, or else leave empty to ignore.'" stacks="ctrl.stacks" input-class-name="'col-lg-10 col-sm-9'" + error="ctrl.state.stackNameError" > diff --git a/app/kubernetes/views/applications/create/createApplicationController.js b/app/kubernetes/views/applications/create/createApplicationController.js index c998d5e0a..79e1fdba5 100644 --- a/app/kubernetes/views/applications/create/createApplicationController.js +++ b/app/kubernetes/views/applications/create/createApplicationController.js @@ -28,6 +28,7 @@ import { confirmUpdateAppIngress } from '@/react/kubernetes/applications/CreateV import { confirm, confirmUpdate, confirmWebEditorDiscard } from '@@/modals/confirm'; import { buildConfirmButton } from '@@/modals/utils'; import { ModalType } from '@@/modals'; +import { KUBE_STACK_NAME_VALIDATION_REGEX } from '@/react/kubernetes/DeployView/StackName/constants'; class KubernetesCreateApplicationController { /* #region CONSTRUCTOR */ @@ -127,6 +128,7 @@ class KubernetesCreateApplicationController { // a validation message will be shown. isExistingCPUReservationUnchanged and isExistingMemoryReservationUnchanged (with available resources being exceeded) is used to decide whether to show the message or not. isExistingCPUReservationUnchanged: false, isExistingMemoryReservationUnchanged: false, + stackNameError: '', }; this.isAdmin = this.Authentication.isAdmin(); @@ -186,9 +188,16 @@ class KubernetesCreateApplicationController { } /* #endregion */ - onChangeStackName(stackName) { + onChangeStackName(name) { return this.$async(async () => { - this.formValues.StackName = stackName; + if (KUBE_STACK_NAME_VALIDATION_REGEX.test(name) || name === '') { + this.state.stackNameError = ''; + } else { + this.state.stackNameError = + "Stack must consist of alphanumeric characters, '-', '_' or '.', must start and end with an alphanumeric character and must be 63 characters or less (e.g. 'my-name', or 'abc-123')."; + } + + this.formValues.StackName = name; }); } @@ -644,7 +653,8 @@ class KubernetesCreateApplicationController { const invalid = !this.isValid(); const hasNoChanges = this.isEditAndNoChangesMade(); const nonScalable = this.isNonScalable(); - return overflow || autoScalerOverflow || inProgress || invalid || hasNoChanges || nonScalable; + const stackNameInvalid = this.state.stackNameError !== ''; + return overflow || autoScalerOverflow || inProgress || invalid || hasNoChanges || nonScalable || stackNameInvalid; } isUpdateApplicationViaWebEditorButtonDisabled() { diff --git a/app/kubernetes/views/deploy/deploy.html b/app/kubernetes/views/deploy/deploy.html index 27ec85ee2..8dd33791a 100644 --- a/app/kubernetes/views/deploy/deploy.html +++ b/app/kubernetes/views/deploy/deploy.html @@ -90,7 +90,12 @@
- + diff --git a/app/kubernetes/views/deploy/deployController.js b/app/kubernetes/views/deploy/deployController.js index f214e27fe..ad074ae9a 100644 --- a/app/kubernetes/views/deploy/deployController.js +++ b/app/kubernetes/views/deploy/deployController.js @@ -12,6 +12,7 @@ import { parseAutoUpdateResponse, transformAutoUpdateViewModel } from '@/react/p import { baseStackWebhookUrl, createWebhookId } from '@/portainer/helpers/webhookHelper'; import { confirmWebEditorDiscard } from '@@/modals/confirm'; import { getVariablesFieldDefaultValues } from '@/react/portainer/custom-templates/components/CustomTemplatesVariablesField'; +import { KUBE_STACK_NAME_VALIDATION_REGEX } from '@/react/kubernetes/DeployView/StackName/constants'; class KubernetesDeployController { /* @ngInject */ @@ -57,6 +58,7 @@ class KubernetesDeployController { templateLoadFailed: false, isEditorReadOnly: false, selectedHelmChart: '', + stackNameError: '', }; this.currentUser = { @@ -117,7 +119,16 @@ class KubernetesDeployController { } setStackName(name) { - this.formValues.StackName = name; + return this.$async(async () => { + if (KUBE_STACK_NAME_VALIDATION_REGEX.test(name) || name === '') { + this.state.stackNameError = ''; + } else { + this.state.stackNameError = + "Stack must consist of alphanumeric characters, '-', '_' or '.', must start and end with an alphanumeric character and must be 63 characters or less (e.g. 'my-name', or 'abc-123')."; + } + + this.formValues.StackName = name; + }); } renderTemplate() { @@ -197,9 +208,9 @@ class KubernetesDeployController { const isWebEditorInvalid = this.state.BuildMethod === KubernetesDeployBuildMethods.WEB_EDITOR && _.isEmpty(this.formValues.EditorContent); const isURLFormInvalid = this.state.BuildMethod === KubernetesDeployBuildMethods.URL && _.isEmpty(this.formValues.ManifestURL); const isCustomTemplateInvalid = this.state.BuildMethod === KubernetesDeployBuildMethods.CUSTOM_TEMPLATE && _.isEmpty(this.formValues.EditorContent); - + const isStackNameInvalid = this.state.stackNameError !== ''; const isNamespaceInvalid = _.isEmpty(this.formValues.Namespace); - return isWebEditorInvalid || isURLFormInvalid || isCustomTemplateInvalid || this.state.actionInProgress || isNamespaceInvalid; + return isWebEditorInvalid || isURLFormInvalid || isCustomTemplateInvalid || this.state.actionInProgress || isNamespaceInvalid || isStackNameInvalid; } onChangeFormValues(newValues) { diff --git a/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html b/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html index 1644ab032..b66c0642e 100644 --- a/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html +++ b/app/portainer/components/forms/stack-from-template-form/stackFromTemplateForm.html @@ -1,86 +1,84 @@ -
- - - -
- -
-
Information
-
-
-
+ + + + + +
+
Information
+
+
- -
Configuration
- -
- -
- -
-
-
-

- - This field must consist of lower case alphanumeric characters, '_' or '-' (e.g. 'my-name', or 'abc-123'). -

-

This field is required.

-
+
+ +
Configuration
+ +
+ +
+ +
+
+
+

+ + This field must consist of lower case alphanumeric characters, '_' or '-' (e.g. 'my-name', or 'abc-123'). +

+

This field is required.

+
- - -
- -
- - -
+ + +
+ +
+ +
- - +
+ + - - - - -
Actions
-
-
- - -
-
-

{{ $ctrl.state.formValidationError }}

-
+ + + + +
Actions
+
+
+ + +
+
+

{{ $ctrl.state.formValidationError }}

-
-
-

This template type cannot be deployed on this environment.

-
+
+
+
+

This template type cannot be deployed on this environment.

- - - - -
+
+ + + + diff --git a/app/portainer/views/custom-templates/custom-templates-view/customTemplatesView.html b/app/portainer/views/custom-templates/custom-templates-view/customTemplatesView.html index d0444a972..5186ffaed 100644 --- a/app/portainer/views/custom-templates/custom-templates-view/customTemplatesView.html +++ b/app/portainer/views/custom-templates/custom-templates-view/customTemplatesView.html @@ -1,66 +1,68 @@
- - - +
+ + + -
- - -

- Custom template could not be loaded, please - click here for configuration.

-

- Custom template could not be loaded, please contact your administrator.

-
+ +

+ Custom template could not be loaded, please + click here for configuration.

+

+ Custom template could not be loaded, please contact your administrator.

+
- - - -

- You can get more information about Compose file format in the - official documentation - . -

-
-
- - - + + + +

+ You can get more information about Compose file format in the + official documentation + . +

+
+
+ + + +
- - +
+ + +
diff --git a/app/portainer/views/templates/templatesController.js b/app/portainer/views/templates/templatesController.js index 28d0b2d09..86131b458 100644 --- a/app/portainer/views/templates/templatesController.js +++ b/app/portainer/views/templates/templatesController.js @@ -1,5 +1,6 @@ import _ from 'lodash-es'; import { TemplateType } from '@/react/portainer/templates/app-templates/types'; +import { TEMPLATE_NAME_VALIDATION_REGEX } from '@/react/portainer/custom-templates/components/CommonFields'; import { AccessControlFormData } from '../../components/accessControlForm/porAccessControlFormModel'; angular.module('portainer.app').controller('TemplatesController', [ @@ -47,6 +48,7 @@ angular.module('portainer.app').controller('TemplatesController', [ showAdvancedOptions: false, formValidationError: '', actionInProgress: false, + templateNameRegex: TEMPLATE_NAME_VALIDATION_REGEX, }; $scope.enabledTypes = [TemplateType.Container, TemplateType.ComposeStack]; diff --git a/app/react/common/stacks/common/form-texts.tsx b/app/react/common/stacks/common/form-texts.tsx index 6423092c7..3ccf82973 100644 --- a/app/react/common/stacks/common/form-texts.tsx +++ b/app/react/common/stacks/common/form-texts.tsx @@ -33,7 +33,7 @@ export const textByType = { (Deployment, Secret, ConfigMap...)

- You can get more information about Kubernetes file format in the + You can get more information about Kubernetes file format in the{' '} - - {textTip} - + {textTip ? ( + + {textTip} + + ) : null}

diff --git a/app/react/kubernetes/DeployView/StackName/constants.ts b/app/react/kubernetes/DeployView/StackName/constants.ts new file mode 100644 index 000000000..5c2a01801 --- /dev/null +++ b/app/react/kubernetes/DeployView/StackName/constants.ts @@ -0,0 +1,4 @@ +// this regex is to satisfy k8s label validation rules +// alphanumeric, lowercase, uppercase, can contain dashes, dots and underscores, max 63 characters +export const KUBE_STACK_NAME_VALIDATION_REGEX = + /^(([a-zA-Z0-9](?:(?:[-a-zA-Z0-9_.]){0,61}[a-zA-Z0-9])?))$/; diff --git a/app/react/portainer/custom-templates/components/CommonFields.tsx b/app/react/portainer/custom-templates/components/CommonFields.tsx index 16ff5585b..481808065 100644 --- a/app/react/portainer/custom-templates/components/CommonFields.tsx +++ b/app/react/portainer/custom-templates/components/CommonFields.tsx @@ -91,14 +91,10 @@ export function CommonFields({ export function validation({ currentTemplateId, templates = [], - viewType = 'docker', }: { currentTemplateId?: CustomTemplate['Id']; templates?: Array; - viewType?: 'kube' | 'docker' | 'edge'; } = {}): SchemaOf { - const titlePattern = titlePatternValidation(viewType); - return object({ Title: string() .required('Title is required.') @@ -112,7 +108,10 @@ export function validation({ template.Title === value && template.Id !== currentTemplateId ) ) - .matches(titlePattern.pattern, titlePattern.error), + .max( + 200, + 'Custom template title must be less than or equal to 200 characters' + ), Description: string().required('Description is required.'), Note: string().default(''), Logo: string().default(''), @@ -120,23 +119,3 @@ export function validation({ } export const TEMPLATE_NAME_VALIDATION_REGEX = '^[-_a-z0-9]+$'; - -const KUBE_TEMPLATE_NAME_VALIDATION_REGEX = - '^(([a-z0-9](?:(?:[-a-z0-9_.]){0,61}[a-z0-9])?))$'; // alphanumeric, lowercase, can contain dashes, dots and underscores, max 63 characters - -function titlePatternValidation(type: 'kube' | 'docker' | 'edge') { - switch (type) { - case 'kube': - return { - pattern: new RegExp(KUBE_TEMPLATE_NAME_VALIDATION_REGEX), - error: - "This field must consist of lower-case alphanumeric characters, '.', '_' or '-', must start and end with an alphanumeric character and must be 63 characters or less (e.g. 'my-name', or 'abc-123').", - }; - default: - return { - pattern: new RegExp(TEMPLATE_NAME_VALIDATION_REGEX), - error: - "This field must consist of lower-case alphanumeric characters, '_' or '-' (e.g. 'my-name', or 'abc-123').", - }; - } -} diff --git a/app/react/portainer/environments/wizard/EnvironmentsCreationView/shared/MoreSettingsSection.tsx b/app/react/portainer/environments/wizard/EnvironmentsCreationView/shared/MoreSettingsSection.tsx index 1e1427c7e..089d37672 100644 --- a/app/react/portainer/environments/wizard/EnvironmentsCreationView/shared/MoreSettingsSection.tsx +++ b/app/react/portainer/environments/wizard/EnvironmentsCreationView/shared/MoreSettingsSection.tsx @@ -6,7 +6,7 @@ import { MetadataFieldset } from './MetadataFieldset'; export function MoreSettingsSection({ children }: PropsWithChildren) { return ( - +
{children} diff --git a/app/react/portainer/templates/custom-templates/CreateView/useValidation.tsx b/app/react/portainer/templates/custom-templates/CreateView/useValidation.tsx index b141750e7..1c2318f20 100644 --- a/app/react/portainer/templates/custom-templates/CreateView/useValidation.tsx +++ b/app/react/portainer/templates/custom-templates/CreateView/useValidation.tsx @@ -65,7 +65,6 @@ export function useValidation({ }).concat( commonFieldsValidation({ templates: customTemplatesQuery.data, - viewType, }) ), [customTemplatesQuery.data, gitCredentialsQuery.data, viewType] diff --git a/app/react/portainer/templates/custom-templates/EditView/useValidation.tsx b/app/react/portainer/templates/custom-templates/EditView/useValidation.tsx index d0fecd3b2..41393cd47 100644 --- a/app/react/portainer/templates/custom-templates/EditView/useValidation.tsx +++ b/app/react/portainer/templates/custom-templates/EditView/useValidation.tsx @@ -55,7 +55,6 @@ export function useValidation({ commonFieldsValidation({ templates: customTemplatesQuery.data, currentTemplateId: templateId, - viewType, }) ), [