Skip to content

Commit

Permalink
fix(ClusterController): Fix GetClusters returning only the last 2 pro…
Browse files Browse the repository at this point in the history
…viders clusterNames of application (#6210) (#6212)

(cherry picked from commit c9bba66)

Co-authored-by: Christos Arvanitis <[email protected]>
  • Loading branch information
mergify[bot] and christosarvanitis authored May 15, 2024
1 parent a047c08 commit cdc82e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
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

0 comments on commit cdc82e6

Please sign in to comment.