Skip to content

Commit

Permalink
Simplify isAsyncVSClassPeer using a subroutine for repeted loops
Browse files Browse the repository at this point in the history
Signed-off-by: Shyamsundar Ranganathan <[email protected]>
  • Loading branch information
ShyamsundarR authored and BenamarMk committed Nov 1, 2024
1 parent c93fd21 commit 618ab18
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions internal/controller/drpolicy_peerclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,11 @@ func updatePeerClassStatus(u *drpolicyUpdater, syncPeers, asyncPeers []peerInfo)
return u.statusUpdate()
}

// isAsyncVSClassPeer inspects provided pair of classLists for a matching VolumeSnapshotClass, that is linked to the
// StorageClass whose storageID is respectively sIDA or sIDB
func isAsyncVSClassPeer(clA, clB classLists, sIDA, sIDB string) bool {
sidA := ""
sidB := ""

// No provisioner match as we can do cross provisioner VSC based protection
for vscAidx := range clA.vsClasses {
sidA = clA.vsClasses[vscAidx].GetLabels()[StorageIDLabel]
if sidA == "" || sidA != sIDA {
// reset on mismatch, to exit the loop with an empty string if there is no match
sidA = ""

continue
}

break
}

if sidA == "" {
return false
}

for vscBidx := range clB.vsClasses {
sidB = clB.vsClasses[vscBidx].GetLabels()[StorageIDLabel]
if sidB == "" || sidB != sIDB {
// hasVSClassMatchingSID returns if classLists has a VolumeSnapshotClass matching the passed in storageID
func hasVSClassMatchingSID(cl classLists, sID string) bool {
for idx := range cl.vsClasses {
sid := cl.vsClasses[idx].GetLabels()[StorageIDLabel]
if sid == "" || sid != sID {
continue
}

Expand All @@ -171,6 +150,13 @@ func isAsyncVSClassPeer(clA, clB classLists, sIDA, sIDB string) bool {
return false
}

// isAsyncVSClassPeer inspects provided pair of classLists for a matching VolumeSnapshotClass, that is linked to the
// StorageClass whose storageID is respectively sIDA or sIDB
func isAsyncVSClassPeer(clA, clB classLists, sIDA, sIDB string) bool {
// No provisioner match as we can do cross provisioner VSC based protection
return hasVSClassMatchingSID(clA, sIDA) && hasVSClassMatchingSID(clB, sIDB)
}

// getVRID inspects VolumeReplicationClass in the passed in classLists at the specified index, and returns,
// - an empty string if the VRClass fails to match the passed in storageID or schedule, or
// - the value of replicationID on the VRClass
Expand Down

0 comments on commit 618ab18

Please sign in to comment.