Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create replica-1 sc for external mode if topology details are provided #2501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
iamniting marked this conversation as resolved.
Show resolved Hide resolved
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)
iamniting marked this conversation as resolved.
Show resolved Hide resolved
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)
}

malayparida2000 marked this conversation as resolved.
Show resolved Hide resolved
// 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"], ",")

malayparida2000 marked this conversation as resolved.
Show resolved Hide resolved
// 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
}
Loading