Skip to content

Commit

Permalink
static provisioner name for csi
Browse files Browse the repository at this point in the history
set the static provisioner names for
storageclass and snapshotclass for
cephfs/nfs/rbd driver.

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 committed Jan 30, 2024
1 parent 23e2dd0 commit e22a728
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions controllers/storagecluster/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func generateNameForSnapshotClass(initData *ocsv1.StorageCluster, snapshotType S
return fmt.Sprintf("%s-%splugin-snapclass", initData.Name, snapshotType)
}

func generateNameForSnapshotClassDriver(initData *ocsv1.StorageCluster, snapshotType SnapshotterType) string {
return fmt.Sprintf("%s.%s.csi.ceph.com", initData.Namespace, snapshotType)
func generateNameForSnapshotClassDriver(snapshotType SnapshotterType) string {
return fmt.Sprintf("%s.%s.csi.ceph.com", csiDriverNamePrefix, snapshotType)
}

func generateNameForSnapshotClassSecret(instance *ocsv1.StorageCluster, snapshotType SnapshotterType) string {
Expand Down
27 changes: 16 additions & 11 deletions controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ import (
const (
storageClassSkippedError = "some StorageClasses were skipped while waiting for pre-requisites to be met"
defaultStorageClassAnnotation = "storageclass.kubernetes.io/is-default-class"

//csi driver name prefix
csiDriverNamePrefix = "openshift-storage"
)

var (
rbdDriverName = csiDriverNamePrefix + ".rbd.csi.ceph.com"
cephFSDriverName = csiDriverNamePrefix + ".cephfs.csi.ceph.com"
nfsDriverName = csiDriverNamePrefix + ".nfs.csi.ceph.com"
)

// StorageClassConfiguration provides configuration options for a StorageClass.
Expand Down Expand Up @@ -92,10 +101,6 @@ func (obj *ocsStorageClass) ensureDeleted(r *StorageClusterReconciler, instance
}

func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfiguration, namespace string) error {
operatorNamespace, err := util.GetOperatorNamespace()
if err != nil {
return err
}
var skippedSC []string
for _, scc := range sccs {
if scc.reconcileStrategy == ReconcileStrategyIgnore || scc.disable {
Expand All @@ -104,7 +109,7 @@ func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfi
sc := scc.storageClass

switch {
case (strings.Contains(sc.Name, "-ceph-rbd") || strings.Contains(sc.Provisioner, fmt.Sprintf("%s.rbd.csi.ceph.com", operatorNamespace))) && !scc.isClusterExternal:
case (strings.Contains(sc.Name, "-ceph-rbd") || strings.Contains(sc.Provisioner, rbdDriverName)) && !scc.isClusterExternal:
// wait for CephBlockPool to be ready
cephBlockPool := cephv1.CephBlockPool{}
key := types.NamespacedName{Name: sc.Parameters["pool"], Namespace: namespace}
Expand Down Expand Up @@ -166,7 +171,7 @@ func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfi
skippedSC = append(skippedSC, sc.Name)
continue
}
case (strings.Contains(sc.Name, "-cephfs") || strings.Contains(sc.Provisioner, fmt.Sprintf("%s.cephfs.csi.ceph.com", operatorNamespace))) && !scc.isClusterExternal:
case (strings.Contains(sc.Name, "-cephfs") || strings.Contains(sc.Provisioner, cephFSDriverName)) && !scc.isClusterExternal:
// wait for CephFilesystem to be ready
cephFilesystem := cephv1.CephFilesystem{}
key := types.NamespacedName{Name: sc.Parameters["fsName"], Namespace: namespace}
Expand All @@ -179,7 +184,7 @@ func (r *StorageClusterReconciler) createStorageClasses(sccs []StorageClassConfi
skippedSC = append(skippedSC, sc.Name)
continue
}
case strings.Contains(sc.Name, "-nfs") || strings.Contains(sc.Provisioner, fmt.Sprintf("%s.nfs.csi.ceph.com", operatorNamespace)):
case strings.Contains(sc.Name, "-nfs") || strings.Contains(sc.Provisioner, nfsDriverName):
// wait for CephNFS to be ready
cephNFS := cephv1.CephNFS{}
key := types.NamespacedName{Name: sc.Parameters["nfsCluster"], Namespace: namespace}
Expand Down Expand Up @@ -250,7 +255,7 @@ func newCephFilesystemStorageClassConfiguration(initData *ocsv1.StorageCluster)
"description": "Provides RWO and RWX Filesystem volumes",
},
},
Provisioner: fmt.Sprintf("%s.cephfs.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)),
Provisioner: cephFSDriverName,
ReclaimPolicy: &persistentVolumeReclaimDelete,
// AllowVolumeExpansion is set to true to enable expansion of OCS backed Volumes
AllowVolumeExpansion: &allowVolumeExpansion,
Expand Down Expand Up @@ -284,7 +289,7 @@ func newCephBlockPoolStorageClassConfiguration(initData *ocsv1.StorageCluster) S
"description": "Provides RWO Filesystem volumes, and RWO and RWX Block volumes",
},
},
Provisioner: fmt.Sprintf("%s.rbd.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)),
Provisioner: rbdDriverName,
ReclaimPolicy: &persistentVolumeReclaimDelete,
// AllowVolumeExpansion is set to true to enable expansion of OCS backed Volumes
AllowVolumeExpansion: &allowVolumeExpansion,
Expand Down Expand Up @@ -339,7 +344,7 @@ func newNonResilientCephBlockPoolStorageClassConfiguration(initData *ocsv1.Stora
"description": "Ceph Non Resilient Pools : Provides RWO Filesystem volumes, and RWO and RWX Block volumes",
},
},
Provisioner: fmt.Sprintf("%s.rbd.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)),
Provisioner: rbdDriverName,
ReclaimPolicy: &persistentVolumeReclaimDelete,
VolumeBindingMode: &volumeBindingWaitForFirstConsumer,
// AllowVolumeExpansion is set to true to enable expansion of OCS backed Volumes
Expand Down Expand Up @@ -375,7 +380,7 @@ func newCephNFSStorageClassConfiguration(initData *ocsv1.StorageCluster) Storage
"description": "Provides RWO and RWX Filesystem volumes",
},
},
Provisioner: fmt.Sprintf("%s.nfs.csi.ceph.com", os.Getenv(util.OperatorNamespaceEnvVar)),
Provisioner: nfsDriverName,
ReclaimPolicy: &persistentVolumeReclaimDelete,
AllowVolumeExpansion: &allowVolumeExpansion,
Parameters: map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion controllers/storagecluster/volumesnapshotterclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newVolumeSnapshotClass(instance *ocsv1.StorageCluster, snapShotterType Snap
ObjectMeta: metav1.ObjectMeta{
Name: generateNameForSnapshotClass(instance, snapShotterType),
},
Driver: generateNameForSnapshotClassDriver(instance, snapShotterType),
Driver: generateNameForSnapshotClassDriver(snapShotterType),
Parameters: map[string]string{
"clusterID": instance.Namespace,
snapshotterSecretName: generateNameForSnapshotClassSecret(instance, snapShotterType),
Expand Down

0 comments on commit e22a728

Please sign in to comment.