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

fix(ClusterController): Fix GetClusters to return all providers clusterNames of an application (backport #6210) #6213

Merged
merged 1 commit into from
May 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,14 @@ class ClusterController {
.sorted(Comparator.comparing({ Application it -> it.getName().toLowerCase() }))
.collect(Collectors.toList())

Map<String, Set<String>> clusterNames = Map.of()
def lastApp = null
for (app in apps) {
if (!lastApp) {
clusterNames = app.getClusterNames()
} else {
clusterNames = mergeClusters(lastApp, app)
}
lastApp = app
}
Map<String, Set<String>> clusterNames = mergeClusters(apps)
return clusterNames
}

private Map<String, Set<String>> mergeClusters(Application a, Application b) {
private Map<String, Set<String>> mergeClusters(List<Application> a) {
Map<String, Set<String>> map = new HashMap<>()

Stream.of(a, b)
a.stream()
.flatMap({ it.getClusterNames().entrySet().stream() })
.forEach({ entry ->
map.computeIfAbsent(entry.getKey(), { new HashSet<>() }).addAll(entry.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ class ClusterControllerSpec extends Specification {
getApplication("app") >> app2
}

clusterController.applicationProviders = [appProvider1, appProvider2]
def app3 = Stub(Application) {
getName() >> "app"
getClusterNames() >> ["stage": ["we-need-all-clusters-to-be-returned"] as Set]
}
def appProvider3 = Stub(ApplicationProvider) {
getApplication("app") >> app3
}

clusterController.applicationProviders = [appProvider1, appProvider2, appProvider3]

when:
def result = clusterController.listByAccount("app")

then:
result == [test: ["foo", "bar"] as Set, prod: ["baz"] as Set]
result == [test: ["foo", "bar"] as Set, prod: ["baz"] as Set, stage: ["we-need-all-clusters-to-be-returned"] as Set]
}

void "should throw exception when looking for specific cluster that doesnt exist"() {
Expand Down