From 0ad6bfc40a4862328f6bb532486cfd7d6fff42c8 Mon Sep 17 00:00:00 2001 From: Kamil Smigielski Date: Wed, 4 Jan 2023 08:48:54 +0100 Subject: [PATCH] cr --- .../snapshot/EnvoySnapshotFactory.kt | 4 +-- .../listeners/EnvoyListenersFactory.kt | 4 +-- .../snapshot/EnvoySnapshotFactoryTest.kt | 6 ++-- .../clusters/EnvoyClusterFactoryTest.kt | 28 ++++++++++++++++++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt index afc765945..580811522 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactory.kt @@ -40,7 +40,7 @@ class EnvoySnapshotFactory( companion object { const val DEFAULT_HTTP_PORT = 80 - internal fun tagExtractor(tagPrefix: String, servicesStates: MultiClusterState): Map> = + internal fun extractTags(tagPrefix: String, servicesStates: MultiClusterState): Map> = servicesStates.flatMap { it.servicesState.serviceNameToInstances.asIterable() } .fold(emptyMap()) { acc, entry -> @@ -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")) diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt index a88e52f26..ccb27659a 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/EnvoyListenersFactory.kt @@ -290,11 +290,11 @@ class EnvoyListenersFactory( } private fun createEgressHttpProxyVirtualListener( - portAndDomains: Set, + ports: Set, group: Group, globalSnapshot: GlobalSnapshot ): List { - return portAndDomains.map { port -> + return ports.map { port -> Listener.newBuilder() .setName("$DOMAIN_PROXY_LISTENER_ADDRESS:$port") .setAddress( diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactoryTest.kt index 1aef94a28..22cdd9712 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/EnvoySnapshotFactoryTest.kt @@ -26,7 +26,7 @@ class EnvoySnapshotFactoryTest { )) // when - val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state) + val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state) // then assertThat(tags).isEqualTo(serviceTags) @@ -45,7 +45,7 @@ class EnvoySnapshotFactoryTest { )) // when - val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state) + val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state) // then assertThat(tags).isEqualTo(mapOf( @@ -73,7 +73,7 @@ class EnvoySnapshotFactoryTest { )) // when - val tags = EnvoySnapshotFactory.tagExtractor(tagPrefix, state) + val tags = EnvoySnapshotFactory.extractTags(tagPrefix, state) // then assertThat(tags).isEqualTo(mapOf( diff --git a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClusterFactoryTest.kt b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClusterFactoryTest.kt index bce35b17e..006848c14 100644 --- a/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClusterFactoryTest.kt +++ b/envoy-control-core/src/test/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/clusters/EnvoyClusterFactoryTest.kt @@ -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 @@ -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)