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 replica-1 is enabled & topology details are provided
then create a storage class for replica-1. We construct the
TopologyConstrainedPools from the topology details provided in the
external cluster details secret.

Signed-off-by: Malay Kumar Parida <[email protected]>
  • Loading branch information
malayparida2000 committed Mar 14, 2024
1 parent 2d082fc commit ea52338
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 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 @@ -380,6 +381,9 @@ 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"] = getTopologyConstrainedPoolsExternalMode(d.Data)
} else if d.Name == cephRgwStorageClassName {
rgwEndpoint := d.Data[externalCephRgwEndpointKey]
if err := checkEndpointReachable(rgwEndpoint, 5*time.Second); err != nil {
Expand Down
36 changes: 36 additions & 0 deletions controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,39 @@ 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 {
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"], ",")

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 ""
}
return string(topologyConstrainedPoolsStr)
}

0 comments on commit ea52338

Please sign in to comment.