]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: validate mds service_id and helper text for service_id 48788/head
authorMelissa Li <melissali@redhat.com>
Tue, 19 Jul 2022 21:05:14 +0000 (17:05 -0400)
committerPere Diaz Bou <pdiazbou@redhat.com>
Tue, 8 Nov 2022 10:15:41 +0000 (11:15 +0100)
Validate mds service_id to avoid mds daemon from being created and going into error state due to invalid id.
Also add helper text to describe the role of service_id.

Fixes: https://tracker.ceph.com/issues/56077
Signed-off-by: Melissa Li <melissali@redhat.com>
(cherry picked from commit 1d6cb2882d5b9c2a058631a2c189706bcdc73e68)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts

index dcd898d8853789ef61a342becaae2e8496839d7c..7db0abfcaaf1eef9d7f0a5c6ec19e3bfabe254e9 100644 (file)
         <!-- Service id -->
         <div class="form-group row"
              *ngIf="serviceForm.controls.service_type.value !== 'snmp-gateway'">
-          <label i18n
-                 class="cd-col-form-label"
+          <label class="cd-col-form-label"
                  [ngClass]="{'required': ['mds', 'rgw', 'nfs', 'iscsi', 'ingress'].includes(serviceForm.controls.service_type.value)}"
-                 for="service_id">Id</label>
+                 for="service_id">
+            <span i18n>Id</span>
+            <cd-helper i18n>Used in the service name which is &lt;service_type.service_id&gt;</cd-helper>
+          </label>
           <div class="cd-col-form-input">
             <input id="service_id"
                    class="form-control"
@@ -84,6 +86,9 @@
             <span class="invalid-feedback"
                   *ngIf="serviceForm.showError('service_id', frm, 'rgwPattern')"
                   i18n>The value does not match the pattern <strong>&lt;service_id&gt;[.&lt;realm_name&gt;.&lt;zone_name&gt;]</strong>.</span>
+            <span class="invalid-feedback"
+                  *ngIf="serviceForm.showError('service_id', frm, 'mdsPattern')"
+                  i18n>MDS service id must start with a letter and contain alphanumeric characters or '.', '-', and '_'</span>
           </div>
         </div>
 
index b2fbe9c890cd39bd5d8e32a7f17139cf89d5cc15..0effaaef3f66490db8e5fa383532bb3179ee1c67 100644 (file)
@@ -29,6 +29,7 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
 })
 export class ServiceFormComponent extends CdForm implements OnInit {
   readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/;
+  readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
   readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
   readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
   readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
@@ -87,9 +88,20 @@ export class ServiceFormComponent extends CdForm implements OnInit {
       service_id: [
         null,
         [
-          CdValidators.requiredIf({
-            service_type: 'mds'
-          }),
+          CdValidators.composeIf(
+            {
+              service_type: 'mds'
+            },
+            [
+              Validators.required,
+              CdValidators.custom('mdsPattern', (value: string) => {
+                if (_.isEmpty(value)) {
+                  return false;
+                }
+                return !this.MDS_SVC_ID_PATTERN.test(value);
+              })
+            ]
+          ),
           CdValidators.requiredIf({
             service_type: 'nfs'
           }),