Skip to content

Commit

Permalink
Rename peerList structure to peerInfo instead
Browse files Browse the repository at this point in the history
Signed-off-by: Shyamsundar Ranganathan <[email protected]>
  • Loading branch information
ShyamsundarR committed Oct 30, 2024
1 parent 74520bc commit b6db9f6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
52 changes: 26 additions & 26 deletions internal/controller/drpolicy_peerclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type classLists struct {
vrClasses []*volrep.VolumeReplicationClass
}

// peerList contains a single peer relationship between a PAIR of clusters for a common storageClassName across
// peerInfo contains a single peer relationship between a PAIR of clusters for a common storageClassName across
// these peers. This should directly translate to DRPolicy.Status.[Async|Sync] updates.
// NOTE: storageID discussed in comments relates to the value of the label "ramendr.openshift.io/storageid" for the
// respective class. replicationID in comments relates to the value of the label "ramendr.openshift.io/replicationid"
// for the respective class
type peerList struct {
type peerInfo struct {
// replicationID is an empty string (indicating no common VolumeReplicationClass) or the common replicationID value
// for the corresponding VRClass on each peer
replicationID string
Expand All @@ -53,7 +53,7 @@ type peerList struct {
// peerClassMatchesPeer compares the storage class name across the PeerClass and passed in peer for a match, and if
// matched compares the clusterIDs that this peer represents. No further matching is required to determine a unique
// PeerClass matching a peer
func peerClassMatchesPeer(pc ramen.PeerClass, peer peerList) bool {
func peerClassMatchesPeer(pc ramen.PeerClass, peer peerInfo) bool {
if pc.StorageClassName != peer.storageClassName {
return false
}
Expand All @@ -65,8 +65,8 @@ func peerClassMatchesPeer(pc ramen.PeerClass, peer peerList) bool {
return true
}

// findStatusPeerInPeers finds PeerClass in peers, and returns true and the peer if founds
func findStatusPeerInPeers(pc ramen.PeerClass, peers []peerList) (bool, peerList) {
// findStatusPeerInPeers finds PeerClass in passed in peers, and returns true and the peer if founds
func findStatusPeerInPeers(pc ramen.PeerClass, peers []peerInfo) (bool, peerInfo) {
for _, peer := range peers {
if !peerClassMatchesPeer(pc, peer) {
continue
Expand All @@ -75,11 +75,11 @@ func findStatusPeerInPeers(pc ramen.PeerClass, peers []peerList) (bool, peerList
return true, peer
}

return false, peerList{}
return false, peerInfo{}
}

// findPeerInStatusPeer finds passed in peer in passed in list of PeerClass, and returns true if found
func findPeerInStatusPeer(peer peerList, pcs []ramen.PeerClass) bool {
func findPeerInStatusPeer(peer peerInfo, pcs []ramen.PeerClass) bool {
for _, pc := range pcs {
if !peerClassMatchesPeer(pc, peer) {
continue
Expand All @@ -91,18 +91,18 @@ func findPeerInStatusPeer(peer peerList, pcs []ramen.PeerClass) bool {
return false
}

func peerClassFromPeer(p peerList) ramen.PeerClass {
func peerClassFromPeer(peer peerInfo) ramen.PeerClass {
return ramen.PeerClass{
ClusterIDs: p.clusterIDs,
StorageClassName: p.storageClassName,
StorageID: p.storageIDs,
ReplicationID: p.replicationID,
ClusterIDs: peer.clusterIDs,
StorageClassName: peer.storageClassName,
StorageID: peer.storageIDs,
ReplicationID: peer.replicationID,
}
}

// pruneAndUpdateStatusPeers prunes the peer classes in status based on current peers that are passed in, and also adds
// new peers to status.
func pruneAndUpdateStatusPeers(statusPeers []ramen.PeerClass, peers []peerList) []ramen.PeerClass {
func pruneAndUpdateStatusPeers(statusPeers []ramen.PeerClass, peers []peerInfo) []ramen.PeerClass {
outStatusPeers := []ramen.PeerClass{}

// Prune and update existing
Expand All @@ -128,8 +128,8 @@ func pruneAndUpdateStatusPeers(statusPeers []ramen.PeerClass, peers []peerList)
return outStatusPeers
}

// updatePeerClassStatus updates the DRPolicy.Status.[Async|Sync] peer lists based on passed in peerList values
func updatePeerClassStatus(u *drpolicyUpdater, syncPeers, asyncPeers []peerList) error {
// updatePeerClassStatus updates the DRPolicy.Status.[Async|Sync] peer lists based on passed in peerInfo values
func updatePeerClassStatus(u *drpolicyUpdater, syncPeers, asyncPeers []peerInfo) error {
u.object.Status.Async.PeerClasses = pruneAndUpdateStatusPeers(u.object.Status.Async.PeerClasses, asyncPeers)
u.object.Status.Sync.PeerClasses = pruneAndUpdateStatusPeers(u.object.Status.Sync.PeerClasses, syncPeers)

Expand Down Expand Up @@ -219,8 +219,8 @@ func getAsyncVRClassPeer(clA, clB classLists, sIDA, sIDB string, schedule string
// The clusterID and sID are the corresponding IDs for the first cluster in the classList, and the schedule is
// the desired asynchronous schedule that requires to be matched
// nolint:gocognit
func getAsyncPeers(scName string, clusterID string, sID string, cls []classLists, schedule string) []peerList {
peers := []peerList{}
func getAsyncPeers(scName string, clusterID string, sID string, cls []classLists, schedule string) []peerInfo {
peers := []peerInfo{}

for _, cl := range cls[1:] {
for scIdx := range cl.sClasses {
Expand All @@ -240,7 +240,7 @@ func getAsyncPeers(scName string, clusterID string, sID string, cls []classLists
}
}

peers = append(peers, peerList{
peers = append(peers, peerInfo{
storageClassName: scName,
storageIDs: []string{sID, sIDcl},
clusterIDs: []string{clusterID, cl.clusterID},
Expand All @@ -256,8 +256,8 @@ func getAsyncPeers(scName string, clusterID string, sID string, cls []classLists

// getSyncPeers determines if scName passed has asynchronous peers in the passed in classLists.
// The clusterID and sID are the corresponding IDs for the passed in scName to find a match
func getSyncPeers(scName string, clusterID string, sID string, cls []classLists) []peerList {
peers := []peerList{}
func getSyncPeers(scName string, clusterID string, sID string, cls []classLists) []peerInfo {
peers := []peerInfo{}

for _, cl := range cls {
for idx := range cl.sClasses {
Expand All @@ -271,7 +271,7 @@ func getSyncPeers(scName string, clusterID string, sID string, cls []classLists)

// TODO: Check provisioner match?

peers = append(peers, peerList{
peers = append(peers, peerInfo{
storageClassName: scName,
storageIDs: []string{sID},
clusterIDs: []string{clusterID, cl.clusterID},
Expand All @@ -286,7 +286,7 @@ func getSyncPeers(scName string, clusterID string, sID string, cls []classLists)

// findPeers finds all sync and async peers for the scName and cluster at the index startClsIdx of classLists,
// across other remaining elements post the startClsIdx in the classLists
func findPeers(cls []classLists, scName string, startClsIdx int, schedule string) ([]peerList, []peerList) {
func findPeers(cls []classLists, scName string, startClsIdx int, schedule string) ([]peerInfo, []peerInfo) {
scIdx := 0
for scIdx = range cls[startClsIdx].sClasses {
if cls[startClsIdx].sClasses[scIdx].Name == scName {
Expand All @@ -302,7 +302,7 @@ func findPeers(cls []classLists, scName string, startClsIdx int, schedule string
// TODO: Check if Sync is non-nil?
syncPeers := getSyncPeers(scName, cls[startClsIdx].clusterID, sID, cls[startClsIdx+1:])

asyncPeers := []peerList{}
asyncPeers := []peerInfo{}
if schedule != "" {
asyncPeers = getAsyncPeers(scName, cls[startClsIdx].clusterID, sID, cls[startClsIdx:], schedule)
}
Expand All @@ -329,9 +329,9 @@ func unionStorageClasses(cls []classLists) []string {

// findAllPeers finds all PAIRs of peers in the passed in classLists. It does an exhaustive search for each scName in
// the prior index of classLists (starting at index 0) with all clusters from that index forward
func findAllPeers(cls []classLists, schedule string) ([]peerList, []peerList) {
syncPeers := []peerList{}
asyncPeers := []peerList{}
func findAllPeers(cls []classLists, schedule string) ([]peerInfo, []peerInfo) {
syncPeers := []peerInfo{}
asyncPeers := []peerInfo{}

if len(cls) <= 1 {
return syncPeers, asyncPeers
Expand Down
66 changes: 33 additions & 33 deletions internal/controller/drpolicy_peerclass_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var _ = Describe("updatePeerClassesInternal", func() {
func(
cls []classLists,
schedule string,
syncPeers []peerList,
asyncPeers []peerList,
syncPeers []peerInfo,
asyncPeers []peerInfo,
) {
sPeers, aPeers := findAllPeers(cls, schedule)
Expect(sPeers).Should(HaveExactElements(syncPeers))
Expect(aPeers).Should(HaveExactElements(asyncPeers))
},
Entry("Empty classLists", []classLists{}, "1m", []peerList{}, []peerList{}),
Entry("Empty classLists", []classLists{}, "1m", []peerInfo{}, []peerInfo{}),
Entry("Not enough clusters",
[]classLists{
{
Expand All @@ -44,8 +44,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single sync peer",
[]classLists{
Expand Down Expand Up @@ -79,15 +79,15 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{
[]peerInfo{
{
replicationID: "",
storageIDs: []string{"identical"},
storageClassName: "sc1",
clusterIDs: []string{"cl-1", "cl-2"},
},
},
[]peerList{},
[]peerInfo{},
),
Entry("Multiple sync peer",
[]classLists{
Expand Down Expand Up @@ -139,7 +139,7 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{
[]peerInfo{
{
replicationID: "",
storageIDs: []string{"identical1"},
Expand All @@ -153,7 +153,7 @@ var _ = Describe("updatePeerClassesInternal", func() {
clusterIDs: []string{"cl-1", "cl-2"},
},
},
[]peerList{},
[]peerInfo{},
),
Entry("Single async peer, missing related [VR|VS]Classes",
[]classLists{
Expand Down Expand Up @@ -187,8 +187,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, having unrelated VRClasses",
[]classLists{
Expand Down Expand Up @@ -256,8 +256,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, having unrelated VSClasses",
[]classLists{
Expand Down Expand Up @@ -313,8 +313,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, having unrelated [VR|VS]Classes",
[]classLists{
Expand Down Expand Up @@ -404,8 +404,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, having related VRClasses",
[]classLists{
Expand Down Expand Up @@ -473,8 +473,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{
[]peerInfo{},
[]peerInfo{
{
replicationID: "cl-1-2-rID",
storageIDs: []string{"cl-1-sID", "cl-2-sID"},
Expand Down Expand Up @@ -537,8 +537,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{
[]peerInfo{},
[]peerInfo{
{
replicationID: "",
storageIDs: []string{"cl-1-sID", "cl-2-sID"},
Expand Down Expand Up @@ -601,8 +601,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, with VRClasses missing rID",
[]classLists{
Expand Down Expand Up @@ -669,8 +669,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, with VRClasses mismatching schedule",
[]classLists{
Expand Down Expand Up @@ -738,8 +738,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Single async peer, having related VRClasses with mismatching rIDs",
[]classLists{
Expand Down Expand Up @@ -807,8 +807,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{},
[]peerInfo{},
[]peerInfo{},
),
Entry("Multiple async peer, having related [VR|VS]Classes",
[]classLists{
Expand Down Expand Up @@ -916,8 +916,8 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{},
[]peerList{
[]peerInfo{},
[]peerInfo{
{
replicationID: "",
storageIDs: []string{"cl-1-sID1", "cl-2-sID1"},
Expand Down Expand Up @@ -1060,7 +1060,7 @@ var _ = Describe("updatePeerClassesInternal", func() {
},
},
"1m",
[]peerList{
[]peerInfo{
{
replicationID: "",
storageIDs: []string{"cl-[1|2]-sID1"},
Expand All @@ -1074,7 +1074,7 @@ var _ = Describe("updatePeerClassesInternal", func() {
clusterIDs: []string{"cl-3", "cl-4"},
},
},
[]peerList{
[]peerInfo{
{
replicationID: "cl-[1|2]-[3|4]-rID",
storageIDs: []string{"cl-[1|2]-sID1", "cl-[3|4]-sID1"},
Expand Down

0 comments on commit b6db9f6

Please sign in to comment.