diff --git a/pkg/operator/ceph/csi/csi.go b/pkg/operator/ceph/csi/csi.go index 9e91f89f0..0b21d6674 100644 --- a/pkg/operator/ceph/csi/csi.go +++ b/pkg/operator/ceph/csi/csi.go @@ -18,6 +18,7 @@ package csi import ( "context" + "fmt" "strconv" "strings" "time" @@ -369,5 +370,25 @@ func (r *ReconcileCSI) setParams() error { } } + if strings.HasSuffix(CSIParam.DriverNamePrefix, ".") { + // As operator is adding a dot at the end of the prefix, we should not + // allow the user to add a dot at the end of the prefix. as it will + // result in two dots at the end of the prefix. which cases the csi + // driver name creation failure + return errors.Errorf("driver name prefix %q should not end with a dot", CSIParam.DriverNamePrefix) + } + + err = validateCSIDriverNamePrefix(r.opManagerContext, r.context.Clientset, r.opConfig.OperatorNamespace, CSIParam.DriverNamePrefix) + if err != nil { + return err + } + // Add a dot at the end of the prefix for having the driver name prefix + // with format . + CSIParam.DriverNamePrefix = fmt.Sprintf("%s.", CSIParam.DriverNamePrefix) + + // Set the driver names + CephFSDriverName = CSIParam.DriverNamePrefix + cephFSDriverSuffix + RBDDriverName = CSIParam.DriverNamePrefix + rbdDriverSuffix + NFSDriverName = CSIParam.DriverNamePrefix + nfsDriverSuffix return nil } diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go index 77e908902..ef02dd96c 100644 --- a/pkg/operator/ceph/csi/spec.go +++ b/pkg/operator/ceph/csi/spec.go @@ -19,7 +19,6 @@ package csi import ( "context" _ "embed" - "fmt" "path" "strings" "time" @@ -313,26 +312,6 @@ func (r *ReconcileCSI) startDrivers(ownerInfo *k8sutil.OwnerInfo) error { Namespace: r.opConfig.OperatorNamespace, } - if strings.HasSuffix(tp.DriverNamePrefix, ".") { - // As operator is adding a dot at the end of the prefix, we should not - // allow the user to add a dot at the end of the prefix. as it will - // result in two dots at the end of the prefix. which cases the csi - // driver name creation failure - return errors.Errorf("driver name prefix %q should not end with a dot", tp.DriverNamePrefix) - } - - err = validateCSIDriverNamePrefix(r.opManagerContext, r.context.Clientset, r.opConfig.OperatorNamespace, tp.DriverNamePrefix) - if err != nil { - return err - } - // Add a dot at the end of the prefix for having the driver name prefix - // with format . - tp.DriverNamePrefix = fmt.Sprintf("%s.", tp.DriverNamePrefix) - - CephFSDriverName = tp.DriverNamePrefix + cephFSDriverSuffix - RBDDriverName = tp.DriverNamePrefix + rbdDriverSuffix - NFSDriverName = tp.DriverNamePrefix + nfsDriverSuffix - tp.Param.MountCustomCephConf = CustomCSICephConfigExists if EnableRBD { @@ -662,10 +641,6 @@ func (r *ReconcileCSI) startDrivers(ownerInfo *k8sutil.OwnerInfo) error { } func (r *ReconcileCSI) stopDrivers() error { - RBDDriverName = fmt.Sprintf("%s.rbd.csi.ceph.com", r.opConfig.OperatorNamespace) - CephFSDriverName = fmt.Sprintf("%s.cephfs.csi.ceph.com", r.opConfig.OperatorNamespace) - NFSDriverName = fmt.Sprintf("%s.nfs.csi.ceph.com", r.opConfig.OperatorNamespace) - if !EnableRBD || EnableCSIOperator() { logger.Debugf("either EnableRBD if `false` or EnableCSIOperator is `true`, `EnableRBD is %t` and `EnableCSIOperator is %t", EnableRBD, EnableCSIOperator()) err := r.deleteCSIDriverResources(CsiRBDPlugin, csiRBDProvisioner, "csi-rbdplugin-metrics", RBDDriverName)