-
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.
* custom routes * fix linting * fix linting * fix linting * add prefix rewrite * put custom routes before admin * fix test * add changelog * fix test * fix test
- Loading branch information
1 parent
dfbf7bf
commit 866410f
Showing
22 changed files
with
290 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
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
39 changes: 39 additions & 0 deletions
39
.../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,39 @@ | ||
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) | ||
.also { route -> | ||
if (it.prefixRewrite != "") { | ||
route.setPrefixRewrite(it.prefixRewrite) | ||
} | ||
} | ||
) | ||
.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
61 changes: 61 additions & 0 deletions
61
...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,61 @@ | ||
package pl.allegro.tech.servicemesh.envoycontrol | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import pl.allegro.tech.servicemesh.envoycontrol.assertions.isFrom | ||
import pl.allegro.tech.servicemesh.envoycontrol.assertions.isOk | ||
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.StringMatcher | ||
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.StringMatcherType | ||
|
||
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) | ||
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).isOk() | ||
.isFrom(wrapper) | ||
} | ||
} |
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.