csi: always initialize driver names

The driver names were only being initialized in certain code paths
where the drivers were being started and stopped. However, another
code path relied on those names being set. Now, we initialize the
driver names every time the CSI params are initialized, instead of
initializing the names separately.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
Travis Nielsen
2025-08-27 11:06:49 -06:00
parent 87fa0a9a65
commit af548ef2f6
2 changed files with 21 additions and 25 deletions
+21
View File
@@ -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 <prefix>.<driver-name>
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
}
-25
View File
@@ -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 <prefix>.<driver-name>
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)