Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
KSmigielski committed Jan 4, 2023
1 parent 554147a commit 0ad6bfc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EnvoySnapshotFactory(
companion object {
const val DEFAULT_HTTP_PORT = 80

internal fun tagExtractor(tagPrefix: String, servicesStates: MultiClusterState): Map<String, Set<String>> =
internal fun extractTags(tagPrefix: String, servicesStates: MultiClusterState): Map<String, Set<String>> =
servicesStates.flatMap { it.servicesState.serviceNameToInstances.asIterable() }
.fold(emptyMap()) {
acc, entry ->
Expand Down Expand Up @@ -76,7 +76,7 @@ class EnvoySnapshotFactory(
securedClusters = securedClusters,
endpoints = endpoints,
properties = properties.outgoingPermissions,
tags = tagExtractor(properties.outgoingPermissions.tagPrefix, servicesStates)
tags = extractTags(properties.outgoingPermissions.tagPrefix, servicesStates)
)
sample.stop(meterRegistry.timer("snapshot-factory.new-snapshot.time"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ class EnvoyListenersFactory(
}

private fun createEgressHttpProxyVirtualListener(
portAndDomains: Set<Int>,
ports: Set<Int>,
group: Group,
globalSnapshot: GlobalSnapshot
): List<Listener> {
return portAndDomains.map { port ->
return ports.map { port ->
Listener.newBuilder()
.setName("$DOMAIN_PROXY_LISTENER_ADDRESS:$port")
.setAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EnvoySnapshotFactoryTest {
))

// when
val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state)
val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state)

// then
assertThat(tags).isEqualTo(serviceTags)
Expand All @@ -45,7 +45,7 @@ class EnvoySnapshotFactoryTest {
))

// when
val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state)
val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state)

// then
assertThat(tags).isEqualTo(mapOf(
Expand Down Expand Up @@ -73,7 +73,7 @@ class EnvoySnapshotFactoryTest {
))

// when
val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state)
val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state)

// then
assertThat(tags).isEqualTo(mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ class EnvoyClusterFactoryTest {
)
}

@Test
fun `should not return cluster from service dependency when is not present in global snapshot`() {
// given
val properties = SnapshotProperties()
val factory = EnvoyClustersFactory(properties)
val group = serviceGroup.copy(
proxySettings = ProxySettings(
outgoing = Outgoing(
serviceDependencies = listOf(serviceDependency("service-A", 33))
)
)
)
val services = listOf("service-B", "service-C")
val globalSnapshot = buildGlobalSnapshot(
services = services,
properties = properties
)

// when
val clustersForGroup = factory.getClustersForGroup(group, globalSnapshot)

// then
assertThat(clustersForGroup)
.isEmpty()
}

@Test
fun `should return cluster from service dependency`() {
// given
Expand Down Expand Up @@ -139,7 +165,7 @@ class EnvoyClusterFactoryTest {
}

@Test
fun `should return correct configuration for clusters from tag dependency where one service has multiple tags`() {
fun `should return correct configuration for clusters from service dependency when service has tag`() {
// given
val properties = SnapshotProperties()
val factory = EnvoyClustersFactory(properties)
Expand Down

0 comments on commit 0ad6bfc

Please sign in to comment.