Skip to content

Commit

Permalink
Create replica-1 sc for external mode if topology details are provided
Browse files Browse the repository at this point in the history
In external mode if topology details are provided then create a
storageClass for replica-1. We construct the TopologyConstrainedPools
from the topology details provided in the external cluster secret.

Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Mar 15, 2024
1 parent 2d082fc commit 64e288d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/storagecluster/external_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
cephFsStorageClassName = "cephfs"
cephRbdStorageClassName = "ceph-rbd"
cephRbdRadosNamespaceStorageClassName = "ceph-rbd-rados-namespace"
cephRbdTopologyStorageClassName = "ceph-rbd-topology"
cephRgwStorageClassName = "ceph-rgw"
externalCephRgwEndpointKey = "endpoint"
cephRgwTLSSecretKey = "ceph-rgw-tls-cert"
Expand Down Expand Up @@ -371,6 +372,7 @@ func (r *StorageClusterReconciler) createExternalStorageClusterResources(instanc

case "StorageClass":
var scc StorageClassConfiguration
var err error
if d.Name == cephFsStorageClassName {
scc = newCephFilesystemStorageClassConfiguration(instance)
enableRookCSICephFS = true
Expand All @@ -380,6 +382,13 @@ func (r *StorageClusterReconciler) createExternalStorageClusterResources(instanc
scc = newCephBlockPoolStorageClassConfiguration(instance)
// update the storageclass name to rados storagesclass name
scc.storageClass.Name = fmt.Sprintf("%s-%s", instance.Name, d.Name)
} else if d.Name == cephRbdTopologyStorageClassName {
scc = newNonResilientCephBlockPoolStorageClassConfiguration(instance)
scc.storageClass.Parameters["topologyConstrainedPools"], err = getTopologyConstrainedPoolsExternalMode(d.Data)
if err != nil {
r.Log.Error(err, "Failed to get topologyConstrainedPools from external mode secret.", "StorageClass", klog.KRef(instance.Namespace, d.Name))
return err
}
} else if d.Name == cephRgwStorageClassName {
rgwEndpoint := d.Data[externalCephRgwEndpointKey]
if err := checkEndpointReachable(rgwEndpoint, 5*time.Second); err != nil {
Expand Down
41 changes: 41 additions & 0 deletions controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,44 @@ func getTopologyConstrainedPools(initData *ocsv1.StorageCluster) string {
}
return string(topologyConstrainedPoolsStr)
}

// getTopologyConstrainedPoolsExternalMode constructs the topologyConstrainedPools string for external mode from the data map
func getTopologyConstrainedPoolsExternalMode(data map[string]string) (string, error) {
type topologySegment struct {
DomainLabel string `json:"domainLabel"`
DomainValue string `json:"value"`
}
// TopologyConstrainedPool stores the pool name and a list of its associated topology domain values.
type topologyConstrainedPool struct {
PoolName string `json:"poolName"`
DomainSegments []topologySegment `json:"domainSegments"`
}
var topologyConstrainedPools []topologyConstrainedPool

domainLabel := data["topologyFailureDomainLabel"]
domainValues := strings.Split(data["topologyFailureDomainValues"], ",")
poolNames := strings.Split(data["topologyPools"], ",")

// Check if the number of pool names and domain values are equal
if len(poolNames) != len(domainValues) {
return "", fmt.Errorf("number of pool names and domain values are not equal")
}

for i, poolName := range poolNames {
topologyConstrainedPools = append(topologyConstrainedPools, topologyConstrainedPool{
PoolName: poolName,
DomainSegments: []topologySegment{
{
DomainLabel: domainLabel,
DomainValue: domainValues[i],
},
},
})
}
// returning as string as parameters are of type map[string]string
topologyConstrainedPoolsStr, err := json.MarshalIndent(topologyConstrainedPools, "", " ")
if err != nil {
return "", err
}
return string(topologyConstrainedPoolsStr), nil
}

0 comments on commit 64e288d

Please sign in to comment.