Merge branch '3.2.x'
This commit is contained in:
@@ -51,16 +51,16 @@ class Fabric8DiscoveryFilterIT extends Fabric8DiscoveryBase {
|
||||
util.createNamespace(NAMESPACE_A_UAT);
|
||||
util.createNamespace(NAMESPACE_B_UAT);
|
||||
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE);
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE, false);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE, false);
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE);
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE, false);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE, false);
|
||||
|
||||
util.deleteNamespace(NAMESPACE_A_UAT);
|
||||
util.deleteNamespace(NAMESPACE_B_UAT);
|
||||
|
||||
@@ -44,8 +44,6 @@ import static org.springframework.cloud.kubernetes.configuration.watcher.TestUti
|
||||
*/
|
||||
class ActuatorRefreshIT {
|
||||
|
||||
private static final String WIREMOCK_PATH = "/";
|
||||
|
||||
private static final String NAMESPACE = "default";
|
||||
|
||||
private static final K3sContainer K3S = Commons.container();
|
||||
@@ -72,12 +70,12 @@ class ActuatorRefreshIT {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
util.wiremock(NAMESPACE, WIREMOCK_PATH, Phase.CREATE);
|
||||
util.wiremock(NAMESPACE, Phase.CREATE, true);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void after() {
|
||||
util.wiremock(NAMESPACE, WIREMOCK_PATH, Phase.DELETE);
|
||||
util.wiremock(NAMESPACE, Phase.DELETE, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -114,10 +112,10 @@ class ActuatorRefreshIT {
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars);
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, null);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class ActuatorRefreshMultipleNamespacesIT {
|
||||
util = new Util(K3S);
|
||||
util.createNamespace(LEFT_NAMESPACE);
|
||||
util.createNamespace(RIGHT_NAMESPACE);
|
||||
util.wiremock(DEFAULT_NAMESPACE, "/", Phase.CREATE);
|
||||
util.wiremock(DEFAULT_NAMESPACE, Phase.CREATE, true);
|
||||
util.setUpClusterWide(DEFAULT_NAMESPACE, Set.of(DEFAULT_NAMESPACE, LEFT_NAMESPACE, RIGHT_NAMESPACE));
|
||||
configWatcher(Phase.CREATE);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ class ActuatorRefreshMultipleNamespacesIT {
|
||||
@AfterAll
|
||||
static void afterAll() {
|
||||
configWatcher(Phase.DELETE);
|
||||
util.wiremock(DEFAULT_NAMESPACE, "/", Phase.DELETE);
|
||||
util.wiremock(DEFAULT_NAMESPACE, Phase.DELETE, true);
|
||||
util.deleteClusterWide(DEFAULT_NAMESPACE, Set.of(DEFAULT_NAMESPACE, LEFT_NAMESPACE, RIGHT_NAMESPACE));
|
||||
util.deleteNamespace(LEFT_NAMESPACE);
|
||||
util.deleteNamespace(RIGHT_NAMESPACE);
|
||||
@@ -128,10 +128,10 @@ class ActuatorRefreshMultipleNamespacesIT {
|
||||
.yaml("config-watcher/spring-cloud-kubernetes-configuration-watcher-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(DEFAULT_NAMESPACE, null, deployment, service, null, true);
|
||||
util.createAndWait(DEFAULT_NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else {
|
||||
util.deleteAndWait(DEFAULT_NAMESPACE, deployment, service, null);
|
||||
util.deleteAndWait(DEFAULT_NAMESPACE, deployment, service);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ final class TestUtil {
|
||||
|
||||
private static final String WIREMOCK_HOST = "localhost";
|
||||
|
||||
private static final int WIREMOCK_PORT = 80;
|
||||
private static final int WIREMOCK_PORT = 32321;
|
||||
|
||||
static final String SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME = "spring-cloud-kubernetes-configuration-watcher";
|
||||
|
||||
@@ -60,7 +60,7 @@ final class TestUtil {
|
||||
// is ready to take a request via 'Wiremock::stubFor' (because sometimes it fails)
|
||||
// As such, get the existing mappings and retrySpec() makes sure we retry until
|
||||
// we get a response back.
|
||||
WebClient client = builder().baseUrl("http://localhost:80/__admin/mappings").build();
|
||||
WebClient client = builder().baseUrl("http://localhost:32321/__admin/mappings").build();
|
||||
client.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()).block();
|
||||
|
||||
StubMapping stubMapping = WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))
|
||||
|
||||
@@ -93,10 +93,10 @@ abstract class DiscoveryServerClientBase {
|
||||
V1Service service = (V1Service) util.yaml("manifests/discoveryserver-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, null);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ class DiscoveryServerClientIT extends DiscoveryServerClientBase {
|
||||
discoveryServer(Phase.CREATE);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.CREATE, false);
|
||||
util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.CREATE, false);
|
||||
util.wiremock(NAMESPACE_LEFT, Phase.CREATE, false);
|
||||
util.wiremock(NAMESPACE_RIGHT, Phase.CREATE, false);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -87,8 +87,8 @@ class DiscoveryServerClientIT extends DiscoveryServerClientBase {
|
||||
serviceAccount(Phase.DELETE);
|
||||
discoveryServer(Phase.DELETE);
|
||||
|
||||
util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.DELETE, false);
|
||||
util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.DELETE, false);
|
||||
util.wiremock(NAMESPACE_LEFT, Phase.DELETE, false);
|
||||
util.wiremock(NAMESPACE_RIGHT, Phase.DELETE, false);
|
||||
|
||||
util.deleteNamespace(NAMESPACE_LEFT);
|
||||
util.deleteNamespace(NAMESPACE_RIGHT);
|
||||
|
||||
@@ -60,12 +60,12 @@ class KubernetesClientBlockingIT extends KubernetesClientDiscoveryBase {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadWiremock(K3S);
|
||||
util.wiremock(NAMESPACE, "/", Phase.CREATE);
|
||||
util.wiremock(NAMESPACE, Phase.CREATE, true);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.wiremock(NAMESPACE, "/", Phase.DELETE);
|
||||
util.wiremock(NAMESPACE, Phase.DELETE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,14 +63,14 @@ class KubernetesClientDiscoveryFilterIT extends KubernetesClientDiscoveryBase {
|
||||
util.createNamespace(NAMESPACE_B_UAT);
|
||||
|
||||
Images.loadWiremock(K3S);
|
||||
util.wiremock(NAMESPACE_A_UAT, "/", Phase.CREATE);
|
||||
util.wiremock(NAMESPACE_B_UAT, "/", Phase.CREATE);
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE, false);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE, false);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.wiremock(NAMESPACE_A_UAT, "/", Phase.DELETE);
|
||||
util.wiremock(NAMESPACE_B_UAT, "/", Phase.DELETE);
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE, false);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE, false);
|
||||
|
||||
util.deleteNamespace(NAMESPACE_A_UAT);
|
||||
util.deleteNamespace(NAMESPACE_B_UAT);
|
||||
|
||||
@@ -64,13 +64,13 @@ class KubernetesClientDiscoverySimpleIT extends KubernetesClientDiscoveryBase {
|
||||
util.busybox(NAMESPACE, Phase.CREATE);
|
||||
|
||||
externalNameService = (V1Service) util.yaml("external-name-service.yaml");
|
||||
util.createAndWait(NAMESPACE, null, null, externalNameService, null, true);
|
||||
util.createAndWait(NAMESPACE, null, null, externalNameService, true);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.busybox(NAMESPACE, Phase.DELETE);
|
||||
util.deleteAndWait(NAMESPACE, null, externalNameService, null);
|
||||
util.deleteAndWait(NAMESPACE, null, externalNameService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -60,12 +60,12 @@ class KubernetesClientReactiveIT extends KubernetesClientDiscoveryBase {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadWiremock(K3S);
|
||||
util.wiremock(NAMESPACE, "/", Phase.CREATE);
|
||||
util.wiremock(NAMESPACE, Phase.CREATE, true);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.wiremock(NAMESPACE, "/", Phase.DELETE);
|
||||
util.wiremock(NAMESPACE, Phase.DELETE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,8 +133,8 @@ final class TestAssertions {
|
||||
assertThat(wiremockInstance.getServiceId()).isEqualTo("service-wiremock");
|
||||
assertThat(wiremockInstance.getInstanceId()).isNotNull();
|
||||
assertThat(wiremockInstance.getHost()).isNotNull();
|
||||
assertThat(wiremockInstance.getMetadata()).isEqualTo(Map.of("k8s_namespace", "default", "type", "ClusterIP",
|
||||
"port.http", "8080", "app", "service-wiremock"));
|
||||
assertThat(wiremockInstance.getMetadata()).isEqualTo(
|
||||
Map.of("k8s_namespace", "default", "type", "NodePort", "port.http", "8080", "app", "service-wiremock"));
|
||||
|
||||
}
|
||||
|
||||
@@ -147,8 +147,8 @@ final class TestAssertions {
|
||||
assertThat(wiremockInstance.getServiceId()).isEqualTo("service-wiremock");
|
||||
assertThat(wiremockInstance.getInstanceId()).isNotNull();
|
||||
assertThat(wiremockInstance.getHost()).isNotNull();
|
||||
assertThat(wiremockInstance.getMetadata()).isEqualTo(Map.of("k8s_namespace", "default", "type", "ClusterIP",
|
||||
"port.http", "8080", "app", "service-wiremock"));
|
||||
assertThat(wiremockInstance.getMetadata()).isEqualTo(
|
||||
Map.of("k8s_namespace", "default", "type", "NodePort", "port.http", "8080", "app", "service-wiremock"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Objects;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMap;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
|
||||
import io.kubernetes.client.openapi.models.V1Deployment;
|
||||
import io.kubernetes.client.openapi.models.V1Ingress;
|
||||
import io.kubernetes.client.openapi.models.V1Service;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -153,7 +152,7 @@ class ConfigurationWatcherBusKafkaIT {
|
||||
util.createAndWait(NAMESPACE, configMap, null);
|
||||
|
||||
WebClient.Builder builder = builder();
|
||||
WebClient serviceClient = builder.baseUrl("http://localhost:80/app").build();
|
||||
WebClient serviceClient = builder.baseUrl("http://localhost:32321/app").build();
|
||||
|
||||
Boolean[] value = new Boolean[1];
|
||||
await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(240)).until(() -> {
|
||||
@@ -173,13 +172,12 @@ class ConfigurationWatcherBusKafkaIT {
|
||||
private void app(Phase phase) {
|
||||
V1Deployment deployment = (V1Deployment) util.yaml("app/app-deployment.yaml");
|
||||
V1Service service = (V1Service) util.yaml("app/app-service.yaml");
|
||||
V1Ingress ingress = (V1Ingress) util.yaml("ingress/ingress.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, ingress);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,10 +186,10 @@ class ConfigurationWatcherBusKafkaIT {
|
||||
V1Service service = (V1Service) util.yaml("config-watcher/watcher-kus-kafka-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, null);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ spec:
|
||||
- name: http
|
||||
port: 8081
|
||||
targetPort: 8081
|
||||
nodePort: 32321
|
||||
selector:
|
||||
app: app
|
||||
type: ClusterIP
|
||||
type: NodePort
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: it-ingress-app
|
||||
namespace: default
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /app
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: app
|
||||
port:
|
||||
number: 8081
|
||||
@@ -20,7 +20,6 @@ import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.kubernetes.client.openapi.models.V1Deployment;
|
||||
import io.kubernetes.client.openapi.models.V1Ingress;
|
||||
import io.kubernetes.client.openapi.models.V1Secret;
|
||||
import io.kubernetes.client.openapi.models.V1SecretBuilder;
|
||||
import io.kubernetes.client.openapi.models.V1Service;
|
||||
@@ -103,7 +102,7 @@ class ConfigurationWatcherBusAmqpIT {
|
||||
util.createAndWait(NAMESPACE, null, secret);
|
||||
|
||||
WebClient.Builder builder = builder();
|
||||
WebClient serviceClient = builder.baseUrl("http://localhost:80/app").build();
|
||||
WebClient serviceClient = builder.baseUrl("http://localhost:32321/app").build();
|
||||
|
||||
Boolean[] value = new Boolean[1];
|
||||
await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(240)).until(() -> {
|
||||
@@ -122,13 +121,12 @@ class ConfigurationWatcherBusAmqpIT {
|
||||
private void appA(Phase phase) {
|
||||
V1Deployment deployment = (V1Deployment) util.yaml("app/app-deployment.yaml");
|
||||
V1Service service = (V1Service) util.yaml("app/app-service.yaml");
|
||||
V1Ingress ingress = (V1Ingress) util.yaml("ingress/ingress.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, ingress);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,10 +135,10 @@ class ConfigurationWatcherBusAmqpIT {
|
||||
V1Service service = (V1Service) util.yaml("config-watcher/watcher-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
|
||||
util.createAndWait(NAMESPACE, null, deployment, service, true);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
util.deleteAndWait(NAMESPACE, deployment, service, null);
|
||||
util.deleteAndWait(NAMESPACE, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ spec:
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 32321
|
||||
selector:
|
||||
app: app
|
||||
type: ClusterIP
|
||||
type: NodePort
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: it-ingress
|
||||
namespace: default
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /app
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: app
|
||||
port:
|
||||
number: 8080
|
||||
@@ -105,11 +105,11 @@ abstract class K8sClientReloadBase {
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(namespace, configMap, null);
|
||||
util.createAndWait(namespace, imageName, deployment, service, null, true);
|
||||
util.createAndWait(namespace, imageName, deployment, service, true);
|
||||
}
|
||||
else {
|
||||
util.deleteAndWait(namespace, configMap, null);
|
||||
util.deleteAndWait(namespace, deployment, service, null);
|
||||
util.deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -122,11 +122,11 @@ abstract class K8sClientReloadBase {
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
util.createAndWait(namespace, null, secret);
|
||||
util.createAndWait(namespace, imageName, deployment, service, null, true);
|
||||
util.createAndWait(namespace, imageName, deployment, service, true);
|
||||
}
|
||||
else {
|
||||
util.deleteAndWait(namespace, null, secret);
|
||||
util.deleteAndWait(namespace, deployment, service, null);
|
||||
util.deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -295,7 +295,12 @@ public final class Util {
|
||||
});
|
||||
}
|
||||
|
||||
public void wiremock(String namespace, Phase phase) {
|
||||
/**
|
||||
* 'withNodePort' specifies if we add the NodePort or not. It is needed because we
|
||||
* sometimes deploy two instances of wiremock, and they can't have the same NodePort
|
||||
* exposed
|
||||
*/
|
||||
public void wiremock(String namespace, Phase phase, boolean withNodePort) {
|
||||
InputStream deploymentStream = inputStream("wiremock/wiremock-deployment.yaml");
|
||||
InputStream serviceStream = inputStream("wiremock/wiremock-service.yaml");
|
||||
|
||||
@@ -305,6 +310,11 @@ public final class Util {
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
Service service = client.services().load(serviceStream).item();
|
||||
if (!withNodePort) {
|
||||
// we assume we only have one 'http' port
|
||||
service.getSpec().getPorts().get(0).setNodePort(null);
|
||||
service.getSpec().setType("ClusterIP");
|
||||
}
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
deployment.getMetadata().setNamespace(namespace);
|
||||
|
||||
@@ -35,7 +35,6 @@ import io.kubernetes.client.openapi.Configuration;
|
||||
import io.kubernetes.client.openapi.apis.ApiregistrationV1Api;
|
||||
import io.kubernetes.client.openapi.apis.AppsV1Api;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import io.kubernetes.client.openapi.apis.NetworkingV1Api;
|
||||
import io.kubernetes.client.openapi.apis.RbacAuthorizationV1Api;
|
||||
import io.kubernetes.client.openapi.models.V1APIService;
|
||||
import io.kubernetes.client.openapi.models.V1ClusterRole;
|
||||
@@ -43,9 +42,6 @@ import io.kubernetes.client.openapi.models.V1ConfigMap;
|
||||
import io.kubernetes.client.openapi.models.V1Deployment;
|
||||
import io.kubernetes.client.openapi.models.V1DeploymentCondition;
|
||||
import io.kubernetes.client.openapi.models.V1DeploymentList;
|
||||
import io.kubernetes.client.openapi.models.V1Ingress;
|
||||
import io.kubernetes.client.openapi.models.V1IngressLoadBalancerIngress;
|
||||
import io.kubernetes.client.openapi.models.V1IngressLoadBalancerStatus;
|
||||
import io.kubernetes.client.openapi.models.V1NamespaceBuilder;
|
||||
import io.kubernetes.client.openapi.models.V1Role;
|
||||
import io.kubernetes.client.openapi.models.V1RoleBinding;
|
||||
@@ -79,8 +75,6 @@ public final class Util {
|
||||
|
||||
private final AppsV1Api appsV1Api;
|
||||
|
||||
private final NetworkingV1Api networkingV1Api;
|
||||
|
||||
private final RbacAuthorizationV1Api rbacApi;
|
||||
|
||||
private final K3sContainer container;
|
||||
@@ -101,7 +95,6 @@ public final class Util {
|
||||
this.container = container;
|
||||
this.coreV1Api = new CoreV1Api();
|
||||
this.appsV1Api = new AppsV1Api();
|
||||
this.networkingV1Api = new NetworkingV1Api();
|
||||
rbacApi = new RbacAuthorizationV1Api();
|
||||
}
|
||||
|
||||
@@ -113,7 +106,7 @@ public final class Util {
|
||||
*
|
||||
*/
|
||||
public void createAndWait(String namespace, String name, V1Deployment deployment, V1Service service,
|
||||
@Nullable V1Ingress ingress, boolean changeVersion) {
|
||||
boolean changeVersion) {
|
||||
try {
|
||||
|
||||
coreV1Api.createNamespacedService(namespace, service, null, null, null, null);
|
||||
@@ -143,10 +136,6 @@ public final class Util {
|
||||
waitForDeployment(namespace, deployment);
|
||||
}
|
||||
|
||||
if (ingress != null) {
|
||||
networkingV1Api.createNamespacedIngress(namespace, ingress, null, null, null, null);
|
||||
waitForIngress(namespace, ingress);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof ApiException apiException) {
|
||||
@@ -204,8 +193,7 @@ public final class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteAndWait(String namespace, V1Deployment deployment, V1Service service,
|
||||
@Nullable V1Ingress ingress) {
|
||||
public void deleteAndWait(String namespace, V1Deployment deployment, V1Service service) {
|
||||
|
||||
if (deployment != null) {
|
||||
try {
|
||||
@@ -220,26 +208,16 @@ public final class Util {
|
||||
labelSelector(podLabels), null, null, null, null, null, null, null, null);
|
||||
waitForDeploymentToBeDeleted(deploymentName, namespace);
|
||||
waitForDeploymentPodsToBeDeleted(podLabels, namespace);
|
||||
|
||||
service.getMetadata().setNamespace(namespace);
|
||||
coreV1Api.deleteNamespacedService(service.getMetadata().getName(), service.getMetadata().getNamespace(),
|
||||
null, null, null, null, null, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String serviceName = serviceName(service);
|
||||
try {
|
||||
coreV1Api.deleteNamespacedService(serviceName, namespace, null, null, null, null, null, null);
|
||||
if (ingress != null) {
|
||||
String ingressName = ingressName(ingress);
|
||||
networkingV1Api.deleteNamespacedIngress(ingressName, namespace, null, null, null, null, null, null);
|
||||
waitForIngressToBeDeleted(ingressName, namespace);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void busybox(String namespace, Phase phase) {
|
||||
@@ -251,10 +229,10 @@ public final class Util {
|
||||
|
||||
V1Service service = (V1Service) yaml("busybox/service.yaml");
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
createAndWait(namespace, "busybox", deployment, service, null, false);
|
||||
createAndWait(namespace, "busybox", deployment, service, false);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
deleteAndWait(namespace, deployment, service, null);
|
||||
deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,10 +246,10 @@ public final class Util {
|
||||
V1Service service = (V1Service) yaml("kafka/kafka-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
createAndWait(namespace, "kafka", deployment, service, null, false);
|
||||
createAndWait(namespace, "kafka", deployment, service, false);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
deleteAndWait(namespace, deployment, service, null);
|
||||
deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,10 +263,10 @@ public final class Util {
|
||||
V1Service service = (V1Service) yaml("rabbitmq/rabbitmq-service.yaml");
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
createAndWait(namespace, "rabbitmq", deployment, service, null, false);
|
||||
createAndWait(namespace, "rabbitmq", deployment, service, false);
|
||||
}
|
||||
else if (phase.equals(Phase.DELETE)) {
|
||||
deleteAndWait(namespace, deployment, service, null);
|
||||
deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,11 +413,7 @@ public final class Util {
|
||||
.noneMatch(x -> x.getMetadata().getName().equals(name)));
|
||||
}
|
||||
|
||||
public void wiremock(String namespace, String path, Phase phase) {
|
||||
wiremock(namespace, path, phase, true);
|
||||
}
|
||||
|
||||
public void wiremock(String namespace, String path, Phase phase, boolean withIngress) {
|
||||
public void wiremock(String namespace, Phase phase, boolean withNodePort) {
|
||||
V1Deployment deployment = (V1Deployment) yaml("wiremock/wiremock-deployment.yaml");
|
||||
|
||||
String imageWithoutVersion = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
|
||||
@@ -447,26 +421,20 @@ public final class Util {
|
||||
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageWithVersion);
|
||||
|
||||
V1Service service = (V1Service) yaml("wiremock/wiremock-service.yaml");
|
||||
|
||||
V1Ingress ingress = null;
|
||||
service.getMetadata().setNamespace(namespace);
|
||||
if (!withNodePort) {
|
||||
// we assume we only have one 'http' port
|
||||
service.getSpec().getPorts().get(0).setNodePort(null);
|
||||
service.getSpec().setType("ClusterIP");
|
||||
}
|
||||
|
||||
if (phase.equals(Phase.CREATE)) {
|
||||
|
||||
if (withIngress) {
|
||||
ingress = (V1Ingress) yaml("wiremock/wiremock-ingress.yaml");
|
||||
ingress.getMetadata().setNamespace(namespace);
|
||||
ingress.getSpec().getRules().get(0).getHttp().getPaths().get(0).setPath(path);
|
||||
}
|
||||
|
||||
deployment.getMetadata().setNamespace(namespace);
|
||||
service.getMetadata().setNamespace(namespace);
|
||||
createAndWait(namespace, "wiremock", deployment, service, ingress, false);
|
||||
createAndWait(namespace, "wiremock", deployment, service, false);
|
||||
}
|
||||
else {
|
||||
if (withIngress) {
|
||||
ingress = (V1Ingress) yaml("wiremock/wiremock-ingress.yaml");
|
||||
}
|
||||
deleteAndWait(namespace, deployment, service, ingress);
|
||||
deleteAndWait(namespace, deployment, service);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -475,14 +443,6 @@ public final class Util {
|
||||
return deployment.getMetadata().getName();
|
||||
}
|
||||
|
||||
private String serviceName(V1Service service) {
|
||||
return service.getMetadata().getName();
|
||||
}
|
||||
|
||||
private String ingressName(V1Ingress ingress) {
|
||||
return ingress.getMetadata().getName();
|
||||
}
|
||||
|
||||
private String configMapName(V1ConfigMap configMap) {
|
||||
return configMap.getMetadata().getName();
|
||||
}
|
||||
@@ -532,43 +492,6 @@ public final class Util {
|
||||
});
|
||||
}
|
||||
|
||||
private void waitForIngress(String namespace, V1Ingress ingress) {
|
||||
String ingressName = ingressName(ingress);
|
||||
await().timeout(Duration.ofSeconds(90)).pollInterval(Duration.ofSeconds(3)).until(() -> {
|
||||
try {
|
||||
V1IngressLoadBalancerStatus status = networkingV1Api.readNamespacedIngress(ingressName, namespace, null)
|
||||
.getStatus()
|
||||
.getLoadBalancer();
|
||||
|
||||
if (status == null) {
|
||||
LOG.info("ingress : " + ingressName + " not ready yet (loadbalancer not yet present)");
|
||||
return false;
|
||||
}
|
||||
|
||||
List<V1IngressLoadBalancerIngress> loadBalancerIngress = status.getIngress();
|
||||
if (loadBalancerIngress == null) {
|
||||
LOG.info("ingress : " + ingressName + " not ready yet (loadbalancer ingress not yet present)");
|
||||
return false;
|
||||
}
|
||||
|
||||
String ip = loadBalancerIngress.get(0).getIp();
|
||||
if (ip == null) {
|
||||
LOG.info("ingress : " + ingressName + " not ready yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG.info("ingress : " + ingressName + " ready with ip : " + ip);
|
||||
return true;
|
||||
}
|
||||
catch (ApiException e) {
|
||||
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
return false;
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void waitForDeploymentToBeDeleted(String deploymentName, String namespace) {
|
||||
await().timeout(Duration.ofSeconds(180)).until(() -> {
|
||||
try {
|
||||
@@ -603,21 +526,6 @@ public final class Util {
|
||||
});
|
||||
}
|
||||
|
||||
private void waitForIngressToBeDeleted(String ingressName, String namespace) {
|
||||
await().timeout(Duration.ofSeconds(90)).until(() -> {
|
||||
try {
|
||||
networkingV1Api.readNamespacedIngress(ingressName, namespace, null);
|
||||
return false;
|
||||
}
|
||||
catch (ApiException e) {
|
||||
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
return true;
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isDeploymentReady(String deploymentName, String namespace) throws ApiException {
|
||||
V1DeploymentList deployments = appsV1Api.listNamespacedDeployment(namespace, null, null, null,
|
||||
"metadata.name=" + deploymentName, null, null, null, null, null, null, null);
|
||||
@@ -648,24 +556,6 @@ public final class Util {
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForDeploymentAfterPatch(String deploymentName, String namespace,
|
||||
Map<String, String> podLabels) {
|
||||
try {
|
||||
await().pollDelay(Duration.ofSeconds(4))
|
||||
.pollInterval(Duration.ofSeconds(3))
|
||||
.atMost(60, TimeUnit.SECONDS)
|
||||
.until(() -> isDeploymentReadyAfterPatch(deploymentName, namespace, podLabels));
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof ApiException apiException) {
|
||||
LOG.error("Error: ");
|
||||
LOG.error(apiException.getResponseBody());
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean isDeploymentReadyAfterPatch(String deploymentName, String namespace,
|
||||
Map<String, String> podLabels) throws ApiException {
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: wiremock-ingress
|
||||
namespace: default
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /wiremock/
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: service-wiremock
|
||||
port:
|
||||
number: 8080
|
||||
|
||||
@@ -9,6 +9,7 @@ spec:
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 32321
|
||||
selector:
|
||||
app: service-wiremock
|
||||
type: ClusterIP
|
||||
type: NodePort
|
||||
|
||||
Reference in New Issue
Block a user