pl.allegro.tech.servicemesh.envoycontrol.config.consul.ConsulSetup.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of envoy-control-tests Show documentation
Show all versions of envoy-control-tests Show documentation
Production-ready Control Plane for Service Mesh based on Envoy Proxy.
package pl.allegro.tech.servicemesh.envoycontrol.config.consul
import org.testcontainers.containers.Network
import org.testcontainers.junit.jupiter.Testcontainers
import pl.allegro.tech.servicemesh.envoycontrol.utils.Ports
@Testcontainers
class ConsulSetup(
network: Network,
consulConfig: ConsulConfig,
val port: Int = Ports.nextAvailable()
) {
val container: ConsulContainer = ConsulContainer(consulConfig.dc, port, consulConfig.id, consulConfig)
.withNetwork(network)
val operations = ConsulOperations(port)
}
class ConsulClusterSetup(val consulSetups: List) {
val container = consulSetups.first()
val operations = consulSetups.first().operations
val port = consulSetups.first().port
fun start() {
consulSetups.forEach { consul ->
consul.container.start()
}
consulSetups.forEach { consul ->
val consulContainerNames = consulSetups.map { it.container.containerName() }.toTypedArray()
val args = arrayOf("consul", "join", *consulContainerNames)
consul.container.execInContainer(*args)
}
}
fun joinWith(other: ConsulClusterSetup) {
consulSetups.forEach { consul ->
val consulInDc2ContainerNames = other.consulSetups.map { it.container.containerName() }.toTypedArray()
val args = arrayOf("consul", "join", "-wan", *consulInDc2ContainerNames)
consul.container.execInContainer(*args)
}
}
}