Skip to content

Refactor haveOverlappingMetroZones to return a list of cluster lists #2006

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

Merged
merged 1 commit into from
Apr 19, 2025

Conversation

ShyamsundarR
Copy link
Member

As a part of deprecating spec.Region from DRCluster, the way to process overlapping metro DRPolicies was amended to return different maps from the corresponsing region based or peerClass based policies.

This is now refactored to return only a list of list of clusters as required to detect overlapping metro zones.

@ShyamsundarR ShyamsundarR requested a review from BenamarMk as a code owner April 17, 2025 23:31
@ShyamsundarR ShyamsundarR requested review from rakeshgm and raghavendra-talur and removed request for BenamarMk and rakeshgm April 17, 2025 23:33
@ShyamsundarR
Copy link
Member Author

We still need fixes from #2001

This also requires some unit tests added, and also to be run through a e2e run with non-region specifics.

return nil, nil, fmt.Errorf("drclusters list: %w", err)
}

drClusterIDToName := map[string]string{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to rename this map to drClusterIDsToNames or drClusterIDNameMap. This drClusterIDToName looked like it holds a single value.

d2ClusterIDs := sets.NewString(getClusterIDSFromPolicy(d2)...)
d2SupportsMetro, d2MetroMap := dRPolicySupportsMetro(d2, drclusters.Items)

d2SupportsMetro, d2MetroRegions := dRPolicySupportsMetro(d2, drclusters.Items, drClusterIDToName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about renaming d2MetroRegions to d2MetroMap since we are not returning region anymore. The same goes to d1MetroRegions

return true, nil
}

metroMap := [][]string{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) name maybe misleading thinking is a map but it is a list of lists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, some cleanup of names is still required. Will update with better names (for this and IDsToNames comment as well)

clList = append(clList, drClusterIDToName[cID])
}

metroMap = append(metroMap, clList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might add an empty list if drPolicy.Status.Sync.PeerClasses[idx].ClusterIDs is empty.
It is caught in haveOverlappingMetroZones but it is better to return false, nil if metroMap has no valid metroRegions.

) {
allRegionsMap := make(map[rmn.Region][]string)
metroMap = make(map[string][]string)
metroMap = [][]string{}

for _, managedCluster := range rmnutil.DRPolicyClusterNames(drpolicy) {
for _, v := range drclusters {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't line 1948-1950 be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, merge issue, good catch.

As a part of deprecating spec.Region from DRCluster, the way to process
overlapping metro DRPolicies was amended to return different maps
from the corresponsing region based or peerClass based policies.

This is now refactored to return only a list of list of clusters as
required to detect overlapping metro zones.

Signed-off-by: Shyamsundar Ranganathan <[email protected]>
@ShyamsundarR
Copy link
Member Author

All comments (till now) are addressed @BenamarMk and @rakeshgm

Copy link
Member

@rakeshgm rakeshgm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good.

for _, peerClass := range peerClasses {
metroMap[peerClass.StorageClassName] = peerClass.ClusterIDs
if drClusterIDsToNames == nil {
return true, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be true, nil or false, nil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be true, nil since we want to process further only when ClusterIDToNames are present and these are present only when validatingConflicts. we can just return true,nil in all other cases where we just want to check if Metro is true or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous check is sufficient to determine that Sync is supported, so when callers do not pass in the ID map, the answer is true and a nil return clusters list. So I am stating this is correct as is.

@BenamarMk BenamarMk merged commit d61f673 into RamenDR:main Apr 19, 2025
23 checks passed
@ShyamsundarR ShyamsundarR deleted the overlap-refactor branch April 26, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants