-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f43cedc
commit 980e439
Showing
21 changed files
with
286 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
.../pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/CustomRoutesFactory.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.routes | ||
|
||
import io.envoyproxy.envoy.config.route.v3.Route | ||
import io.envoyproxy.envoy.config.route.v3.RouteAction | ||
import io.envoyproxy.envoy.config.route.v3.RouteMatch | ||
import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.RoutesProperties | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StringMatcherType | ||
|
||
class CustomRoutesFactory(properties: RoutesProperties) { | ||
|
||
val routes: List<Route> = properties.customs.filter { it.enabled }.map { | ||
val matcher = when(it.path.type) { | ||
StringMatcherType.REGEX -> RouteMatch.newBuilder() | ||
.setSafeRegex( | ||
RegexMatcher.newBuilder() | ||
.setRegex(it.path.value) | ||
.setGoogleRe2(RegexMatcher.GoogleRE2.getDefaultInstance()) | ||
) | ||
StringMatcherType.EXACT -> RouteMatch.newBuilder().setPath(it.path.value) | ||
StringMatcherType.PREFIX -> RouteMatch.newBuilder().setPrefix(it.path.value) | ||
} | ||
RouteMatch.newBuilder() | ||
Route.newBuilder() | ||
.setName(it.cluster) | ||
.setRoute(RouteAction.newBuilder() | ||
.setCluster(it.cluster) | ||
) | ||
.setMatch(matcher) | ||
.build() | ||
} | ||
|
||
fun generateCustomRoutes() = routes | ||
|
||
|
||
} |
This file contains 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 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
66 changes: 66 additions & 0 deletions
66
...control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/CustomRouteTest.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package pl.allegro.tech.servicemesh.envoycontrol | ||
|
||
import okhttp3.Headers.Companion.toHeaders | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.RequestBody | ||
import okhttp3.Response | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.envoy.EnvoyExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.envoycontrol.EnvoyControlExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.config.service.EchoServiceExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.CustomRuteProperties | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.SecuredRoute | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StringMatcher | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StringMatcherType | ||
import java.util.stream.Stream | ||
|
||
internal class CustomRouteTest { | ||
companion object { | ||
|
||
private val properties = mapOf( | ||
"envoy-control.envoy.snapshot.routes.customs" to listOf(CustomRuteProperties().apply { | ||
enabled = true | ||
cluster = "wrapper" | ||
path = StringMatcher().apply { | ||
type = StringMatcherType.PREFIX | ||
value = "/status/wrapper/" | ||
} | ||
}), | ||
) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val consul = ConsulExtension() | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val envoyControl = EnvoyControlExtension(consul, properties) | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val service = EchoServiceExtension() | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val wrapper = EchoServiceExtension() | ||
|
||
@JvmField | ||
@RegisterExtension | ||
val envoy = EnvoyExtension(envoyControl, service, wrapperService = wrapper) | ||
} | ||
@Test | ||
fun `should redirect to wrapper`() { | ||
// when | ||
val response = envoy.ingressOperations.callLocalService( | ||
endpoint = "/status/wrapper/prometheus" | ||
) | ||
// then | ||
assertThat(response.isSuccessful).isTrue() | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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.