diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchIT.java index 8bd14f5410..98b1e7530b 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchIT.java @@ -47,6 +47,8 @@ import org.springframework.web.reactive.function.client.WebClient; import static org.awaitility.Awaitility.await; +import static org.springframework.cloud.kubernetes.fabric8.catalog.watch.Fabric8CatalogWatchUtil.patchForEndpointSlices; +import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion; /** * @author wind57 @@ -57,9 +59,11 @@ class Fabric8CatalogWatchIT { private static final String NAMESPACE = "default"; - private static final K3sContainer K3S = Commons.container(); + private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-catalog-watcher"; + + private static final String DOCKER_IMAGE = "docker.io/springcloud/" + IMAGE_NAME + ":" + pomVersion(); - private static KubernetesClient client; + private static final K3sContainer K3S = Commons.container(); private static Util util; @@ -67,16 +71,19 @@ class Fabric8CatalogWatchIT { static void beforeAll() throws Exception { K3S.start(); util = new Util(K3S); - client = util.client(); + KubernetesClient client = util.client(); Commons.validateImage(APP_NAME, K3S); Commons.loadSpringCloudKubernetesImage(APP_NAME, K3S); + app(Phase.CREATE); + util.setUp(NAMESPACE); } @AfterAll static void afterAll() { + app(Phase.DELETE); Commons.systemPrune(); } @@ -95,18 +102,16 @@ void beforeEach() { */ @Test void testCatalogWatchWithEndpoints() throws Exception { - app(false, Phase.CREATE); assertLogStatement("stateGenerator is of type: Fabric8EndpointsCatalogWatch"); test(); - app(false, Phase.DELETE); + + testCatalogWatchWithEndpointSlices(); } - @Test void testCatalogWatchWithEndpointSlices() throws Exception { - app(true, Phase.CREATE); + patchForEndpointSlices(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE); assertLogStatement("stateGenerator is of type: Fabric8EndpointSliceV1CatalogWatch"); test(); - app(true, Phase.DELETE); } /** @@ -143,6 +148,9 @@ private void test() { // watcher implementation // we will get the first busybox instances here. if (result != null) { + if (result.size() != 3) { + return false; + } holder[0] = result.get(0); holder[1] = result.get(1); return true; @@ -195,16 +203,13 @@ private void test() { } - private static void app(boolean useEndpointSlices, Phase phase) { + private static void app(Phase phase) { InputStream endpointsDeploymentStream = util.inputStream("app/watcher-endpoints-deployment.yaml"); - InputStream endpointSlicesDeploymentStream = util.inputStream("app/watcher-endpoint-slices-deployment.yaml"); InputStream serviceStream = util.inputStream("app/watcher-service.yaml"); InputStream ingressStream = util.inputStream("app/watcher-ingress.yaml"); - Deployment deployment = useEndpointSlices - ? Serialization.unmarshal(endpointSlicesDeploymentStream, Deployment.class) - : Serialization.unmarshal(endpointsDeploymentStream, Deployment.class); + Deployment deployment = Serialization.unmarshal(endpointsDeploymentStream, Deployment.class); Service service = Serialization.unmarshal(serviceStream, Service.class); Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class); diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchUtil.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchUtil.java new file mode 100644 index 0000000000..4f1df06f0a --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/java/org/springframework/cloud/kubernetes/fabric8/catalog/watch/Fabric8CatalogWatchUtil.java @@ -0,0 +1,71 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.fabric8.catalog.watch; + +import java.util.Map; + +import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; + +/** + * @author wind57 + */ +final class Fabric8CatalogWatchUtil { + + private static final Map POD_LABELS = Map.of(); + + private Fabric8CatalogWatchUtil() { + + } + + static final String BODY_ONE = """ + { + "spec": { + "template": { + "spec": { + "containers": [{ + "name": "spring-cloud-kubernetes-fabric8-client-discovery", + "image": "image_name_here", + "env": [ + { + "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_DISCOVERY", + "value": "DEBUG" + }, + { + "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_CLIENT_DISCOVERY_HEALTH", + "value": "DEBUG" + }, + { + "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY", + "value": "DEBUG" + }, + { + "name": "SPRING_CLOUD_DISCOVERY_REACTIVE_ENABLED", + "value": "FALSE" + } + ] + }] + } + } + } + } + """; + + static void patchForEndpointSlices(Util util, String dockerImage, String deploymentName, String namespace) { + util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_ONE, POD_LABELS); + } + +} diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoint-slices-deployment.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoint-slices-deployment.yaml deleted file mode 100644 index 531a1447d8..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoint-slices-deployment.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: spring-cloud-kubernetes-fabric8-client-catalog-watcher -spec: - selector: - matchLabels: - app: spring-cloud-kubernetes-fabric8-client-catalog-watcher - template: - metadata: - labels: - app: spring-cloud-kubernetes-fabric8-client-catalog-watcher - spec: - serviceAccountName: spring-cloud-kubernetes-serviceaccount - containers: - - name: spring-cloud-kubernetes-fabric8-client-catalog-watcher - image: docker.io/springcloud/spring-cloud-kubernetes-fabric8-client-catalog-watcher - imagePullPolicy: IfNotPresent - readinessProbe: - httpGet: - port: 8080 - path: /actuator/health/readiness - livenessProbe: - httpGet: - port: 8080 - path: /actuator/health/liveness - ports: - - containerPort: 8080 - env: - - name: LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY - value: DEBUG - - name: SPRING_CLOUD_KUBERNETES_DISCOVERY_USE_ENDPOINT_SLICES - value: true diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoints-deployment.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoints-deployment.yaml index d20024014d..a12406ed83 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoints-deployment.yaml +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-catalog-watcher/src/test/resources/app/watcher-endpoints-deployment.yaml @@ -30,4 +30,4 @@ spec: - name: LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY value: DEBUG - name: SPRING_CLOUD_KUBERNETES_DISCOVERY_USE_ENDPOINT_SLICES - value: false + value: "false"