-
Notifications
You must be signed in to change notification settings - Fork 61
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1890,64 +1890,85 @@ func (d *DRPCInstance) newVRGSpecSync() *rmn.VRGSyncSpec { | |
} | ||
} | ||
|
||
func dRPolicySupportsMetro(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster) (bool, map[string][]string) { | ||
syncPeerClasses := drpolicy.Status.Sync.PeerClasses | ||
aSyncPeerClasses := drpolicy.Status.Async.PeerClasses | ||
|
||
if len(syncPeerClasses) == 0 && len(aSyncPeerClasses) == 0 { | ||
// dRPolicySupportsMetro returns a boolean indicating that the policy supports a Metro(Sync) DR capability, and a | ||
// list of list of strings, where each list of strings contains the name of the clusters that are in a Sync | ||
// relationship | ||
func dRPolicySupportsMetro(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster, drClusterIDsToNames map[string]string) ( | ||
supportsMetro bool, | ||
metroClustersInPolicy [][]string, | ||
) { | ||
if len(drpolicy.Status.Sync.PeerClasses) == 0 && len(drpolicy.Status.Async.PeerClasses) == 0 { | ||
return checkMetroSupportUsingRegion(drpolicy, drclusters) | ||
} | ||
|
||
if len(syncPeerClasses) != 0 { | ||
return checkMetroSupportUsingPeerClass(drpolicy) | ||
if len(drpolicy.Status.Sync.PeerClasses) != 0 { | ||
return checkMetroSupportUsingPeerClass(drpolicy, drClusterIDsToNames) | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
func checkMetroSupportUsingPeerClass(drPolicy *rmn.DRPolicy) (bool, map[string][]string) { | ||
peerClasses := drPolicy.Status.Sync.PeerClasses | ||
if len(peerClasses) == 0 { | ||
func checkMetroSupportUsingPeerClass(drPolicy *rmn.DRPolicy, drClusterIDsToNames map[string]string) (bool, [][]string) { | ||
if len(drPolicy.Status.Sync.PeerClasses) == 0 { | ||
return false, nil | ||
} | ||
|
||
metroMap := make(map[string][]string) | ||
for _, peerClass := range peerClasses { | ||
metroMap[peerClass.StorageClassName] = peerClass.ClusterIDs | ||
if drClusterIDsToNames == nil { | ||
return true, nil | ||
} | ||
|
||
return true, metroMap | ||
metroClustersInPolicy := [][]string{} | ||
|
||
for idx := range drPolicy.Status.Sync.PeerClasses { | ||
if len(drPolicy.Status.Sync.PeerClasses[idx].StorageID) != 1 { | ||
continue | ||
} | ||
|
||
if len(drPolicy.Status.Sync.PeerClasses[idx].ClusterIDs) == 0 { | ||
return false, nil | ||
} | ||
|
||
peerClusterNames := []string{} | ||
for _, cID := range drPolicy.Status.Sync.PeerClasses[idx].ClusterIDs { | ||
peerClusterNames = append(peerClusterNames, drClusterIDsToNames[cID]) | ||
} | ||
|
||
if len(peerClusterNames) != len(drPolicy.Status.Sync.PeerClasses[idx].ClusterIDs) { | ||
return false, nil | ||
} | ||
|
||
metroClustersInPolicy = append(metroClustersInPolicy, peerClusterNames) | ||
} | ||
|
||
return true, metroClustersInPolicy | ||
} | ||
|
||
func checkMetroSupportUsingRegion(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster) ( | ||
supportsMetro bool, | ||
metroMap map[string][]string, | ||
metroClustersInPolicy [][]string, | ||
) { | ||
allRegionsMap := make(map[rmn.Region][]string) | ||
metroMap = make(map[string][]string) | ||
metroClustersInPolicy = [][]string{} | ||
|
||
for _, managedCluster := range rmnutil.DRPolicyClusterNames(drpolicy) { | ||
for _, v := range drclusters { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't line 1948-1950 be deleted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, merge issue, good catch. |
||
if v.Name == managedCluster { | ||
if v.Spec.Region == "" { | ||
return supportsMetro, metroMap | ||
} | ||
|
||
allRegionsMap[v.Spec.Region] = append( | ||
allRegionsMap[v.Spec.Region], | ||
managedCluster) | ||
} | ||
} | ||
} | ||
|
||
for k, v := range allRegionsMap { | ||
for _, v := range allRegionsMap { | ||
if len(v) > 1 { | ||
supportsMetro = true | ||
metroMap[string(k)] = v | ||
|
||
metroClustersInPolicy = append(metroClustersInPolicy, v) | ||
} | ||
} | ||
|
||
return supportsMetro, metroMap | ||
return supportsMetro, metroClustersInPolicy | ||
} | ||
|
||
func (d *DRPCInstance) ensureNamespaceManifestWork(homeCluster string) error { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.