From 51e6de4d80c001d4d6f1806a4064ab923f4f7322 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 20 Sep 2023 21:54:39 +0000 Subject: [PATCH 1/2] Bumping versions --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 5dfeafc2aa..bde839223c 100644 --- a/README.adoc +++ b/README.adoc @@ -2265,7 +2265,7 @@ author credit if we do. Active contributors might be asked to join the core tea given the ability to merge pull requests. === Code of Conduct -This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of +This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/{spring-cloud-build-branch}/docs/src/main/asciidoc/code-of-conduct.adoc[code of conduct]. By participating, you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io. @@ -2276,7 +2276,7 @@ added after the original pull request but before a merge. * Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the `eclipse-code-formatter.xml` file from the - https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring + https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring Cloud Build] project. If using IntelliJ, you can use the https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter Plugin] to import the same file. From 4c5eecf133aa775a8e41f15bace6deaaede12c9a Mon Sep 17 00:00:00 2001 From: erabii Date: Thu, 21 Sep 2023 15:45:52 +0300 Subject: [PATCH 2/2] clean-up some un-used test (#1448) --- .../it/ReactiveDiscoveryClientIT.java | 150 ------------ .../it/DiscoveryClientFilterNamespaceIT.java | 218 ------------------ 2 files changed, 368 deletions(-) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-reactive-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/client/reactive/discovery/it/ReactiveDiscoveryClientIT.java delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-reactive-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/client/reactive/discovery/it/ReactiveDiscoveryClientIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-reactive-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/client/reactive/discovery/it/ReactiveDiscoveryClientIT.java deleted file mode 100644 index c9de33d25a..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-client-reactive-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/client/reactive/discovery/it/ReactiveDiscoveryClientIT.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2013-2020 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.client.reactive.discovery.it; - -import java.time.Duration; -import java.util.Arrays; -import java.util.Map; -import java.util.Objects; - -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.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.k3s.K3sContainer; -import reactor.netty.http.client.HttpClient; -import reactor.util.retry.Retry; -import reactor.util.retry.RetryBackoffSpec; - -import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; -import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; -import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.ResolvableType; -import org.springframework.http.HttpMethod; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.web.reactive.function.client.WebClient; - -/** - * @author Ryan Baxter - */ -class ReactiveDiscoveryClientIT { - - private static final String HEALTH_URL = "http://localhost:80/reactive-discovery-it/actuator/health"; - - private static final String SERVICES_URL = "http://localhost:80/reactive-discovery-it/services"; - - private static final String SPRING_CLOUD_K8S_REACTIVE_DISCOVERY_APP_NAME = "spring-cloud-kubernetes-client-reactive-discoveryclient-it"; - - private static final String NAMESPACE = "default"; - - private static final K3sContainer K3S = Commons.container(); - - private static Util util; - - @BeforeAll - static void beforeAll() throws Exception { - K3S.start(); - Commons.validateImage(SPRING_CLOUD_K8S_REACTIVE_DISCOVERY_APP_NAME, K3S); - Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_REACTIVE_DISCOVERY_APP_NAME, K3S); - util = new Util(K3S); - util.setUp(NAMESPACE); - } - - @AfterAll - static void afterAll() throws Exception { - Commons.cleanUp(SPRING_CLOUD_K8S_REACTIVE_DISCOVERY_APP_NAME, K3S); - Commons.systemPrune(); - } - - @BeforeEach - void setup() { - util.wiremock(NAMESPACE, "/wiremock", Phase.CREATE, false); - } - - @AfterEach - void after() { - util.wiremock(NAMESPACE, "/wiremock", Phase.DELETE, false); - reactiveDiscoveryIt(Phase.DELETE); - } - - @Test - void testReactiveDiscoveryClient() { - reactiveDiscoveryIt(Phase.CREATE); - testLoadBalancer(); - testHealth(); - } - - @SuppressWarnings("unchecked") - private void testHealth() { - - WebClient.Builder builder = builder(); - WebClient serviceClient = builder.baseUrl(HEALTH_URL).build(); - ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Map.class, String.class, Object.class); - @SuppressWarnings("unchecked") - Map health = (Map) serviceClient.method(HttpMethod.GET).retrieve() - .bodyToMono(ParameterizedTypeReference.forType(resolvableType.getType())).retryWhen(retrySpec()) - .block(); - - Map components = (Map) health.get("components"); - - Assertions.assertTrue(components.containsKey("reactiveDiscoveryClients")); - Map discoveryComposite = (Map) components.get("discoveryComposite"); - Assertions.assertEquals(discoveryComposite.get("status"), "UP"); - } - - private void testLoadBalancer() { - - WebClient.Builder builder = builder(); - WebClient serviceClient = builder.baseUrl(SERVICES_URL).build(); - String servicesResponse = serviceClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class) - .retryWhen(retrySpec()).block(); - - Assertions - .assertTrue(Arrays.stream(servicesResponse.split(",")).anyMatch("service-wiremock"::equalsIgnoreCase)); - } - - private void reactiveDiscoveryIt(Phase phase) { - V1Deployment deployment = (V1Deployment) util - .yaml("spring-cloud-kubernetes-client-reactive-discoveryclient-it-deployment.yaml"); - V1Service service = (V1Service) util - .yaml("spring-cloud-kubernetes-client-reactive-discoveryclient-it-service.yaml"); - V1Ingress ingress = (V1Ingress) util - .yaml("spring-cloud-kubernetes-client-reactive-discoveryclient-it-ingress.yaml"); - - if (phase.equals(Phase.CREATE)) { - util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); - } - else if (phase.equals(Phase.DELETE)) { - util.deleteAndWait(NAMESPACE, deployment, service, ingress); - } - } - - private WebClient.Builder builder() { - return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create())); - } - - private RetryBackoffSpec retrySpec() { - return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull); - } - -} diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java deleted file mode 100644 index fe10560904..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-discoveryclient-it/src/test/java/org/springframework/cloud/kubernetes/discoveryclient/it/DiscoveryClientFilterNamespaceIT.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2013-2021 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.discoveryclient.it; - -import java.time.Duration; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import io.kubernetes.client.openapi.apis.RbacAuthorizationV1Api; -import io.kubernetes.client.openapi.models.V1ClusterRoleBinding; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1EnvVar; -import io.kubernetes.client.openapi.models.V1EnvVarBuilder; -import io.kubernetes.client.openapi.models.V1Ingress; -import io.kubernetes.client.openapi.models.V1Service; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.testcontainers.k3s.K3sContainer; -import reactor.netty.http.client.HttpClient; -import reactor.util.retry.Retry; -import reactor.util.retry.RetryBackoffSpec; - -import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance; -import org.springframework.cloud.kubernetes.integration.tests.commons.Commons; -import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; -import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.ResolvableType; -import org.springframework.http.HttpMethod; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author mbialkowski1 - */ -class DiscoveryClientFilterNamespaceIT { - - private static final String DISCOVERY_SERVER_APP_NAME = "spring-cloud-kubernetes-discoveryserver"; - - private static final String SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME = "spring-cloud-kubernetes-discoveryclient-it"; - - private static final String NAMESPACE = "default"; - - private static final String NAMESPACE_LEFT = "left"; - - private static final String NAMESPACE_RIGHT = "right"; - - private static final K3sContainer K3S = Commons.container(); - - private static Util util; - - private static RbacAuthorizationV1Api rbacApi; - - private static V1ClusterRoleBinding clusterRoleBinding; - - @BeforeAll - static void beforeAll() throws Exception { - K3S.start(); - - Commons.validateImage(DISCOVERY_SERVER_APP_NAME, K3S); - Commons.loadSpringCloudKubernetesImage(DISCOVERY_SERVER_APP_NAME, K3S); - - Commons.validateImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); - Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); - - util = new Util(K3S); - rbacApi = new RbacAuthorizationV1Api(); - clusterRoleBinding = (V1ClusterRoleBinding) util - .yaml("namespace-filter/cluster-admin-serviceaccount-role.yaml"); - util.createNamespace(NAMESPACE_LEFT); - util.createNamespace(NAMESPACE_RIGHT); - util.setUp(NAMESPACE); - - rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null); - discoveryServer(Phase.CREATE); - } - - @AfterAll - static void afterAll() throws Exception { - rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null, - null); - Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S); - Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S); - discoveryServer(Phase.DELETE); - util.deleteNamespace(NAMESPACE_LEFT); - util.deleteNamespace(NAMESPACE_RIGHT); - Commons.systemPrune(); - } - - @AfterEach - void afterEach() { - util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.DELETE, false); - util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.DELETE, false); - discoveryIt(Phase.DELETE); - } - - @Test - void testDiscoveryClient() { - util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.CREATE, false); - util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.CREATE, false); - discoveryIt(Phase.CREATE); - - testLoadBalancer(); - testHealth(); - } - - private void testLoadBalancer() { - - WebClient.Builder builder = builder(); - WebClient serviceClient = builder.baseUrl("http://localhost:80/discoveryclient-it/services").build(); - - String[] result = serviceClient.method(HttpMethod.GET).retrieve().bodyToMono(String[].class) - .retryWhen(retrySpec()).block(); - assertThat(result).containsAnyOf("service-wiremock"); - - // ServiceInstance - WebClient serviceInstanceClient = builder - .baseUrl("http://localhost:80/discoveryclient-it/service/service-wiremock").build(); - List serviceInstances = serviceInstanceClient.method(HttpMethod.GET).retrieve() - .bodyToMono(new ParameterizedTypeReference>() { - }).retryWhen(retrySpec()).block(); - - assertThat(serviceInstances).isNotNull(); - assertThat(serviceInstances.size()).isEqualTo(1); - assertThat(serviceInstances.get(0).getNamespace()).isEqualTo(NAMESPACE_LEFT); - - } - - @SuppressWarnings("unchecked") - void testHealth() { - WebClient.Builder builder = builder(); - WebClient serviceClient = builder.baseUrl("http://localhost:80/discoveryclient-it/actuator/health").build(); - - ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Map.class, String.class, Object.class); - @SuppressWarnings("unchecked") - Map health = (Map) serviceClient.method(HttpMethod.GET).retrieve() - .bodyToMono(ParameterizedTypeReference.forType(resolvableType.getType())).retryWhen(retrySpec()) - .block(); - - Map components = (Map) health.get("components"); - - Map discoveryComposite = (Map) components.get("discoveryComposite"); - assertThat(discoveryComposite.get("status")).isEqualTo("UP"); - } - - private void discoveryIt(Phase phase) { - - V1Deployment deployment = (V1Deployment) util - .yaml("client/spring-cloud-kubernetes-discoveryclient-it-deployment.yaml"); - V1Service service = (V1Service) util.yaml("client/spring-cloud-kubernetes-discoveryclient-it-service.yaml"); - V1Ingress ingress = (V1Ingress) util.yaml("client/spring-cloud-kubernetes-discoveryclient-it-ingress.yaml"); - - if (phase.equals(Phase.CREATE)) { - // add namespaces filter property for left namespace - var env = new V1EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_NAMESPACES_0") - .withValue(NAMESPACE_LEFT).build(); - var container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0); - container.setEnv(List.of(env)); - - util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); - } - else { - util.deleteAndWait(NAMESPACE, deployment, service, ingress); - } - - } - - private static void discoveryServer(Phase phase) { - - V1Deployment deployment = (V1Deployment) util - .yaml("server/spring-cloud-kubernetes-discoveryserver-deployment.yaml"); - V1Service service = (V1Service) util.yaml("server/spring-cloud-kubernetes-discoveryserver-service.yaml"); - V1Ingress ingress = (V1Ingress) util.yaml("server/spring-cloud-kubernetes-discoveryserver-ingress.yaml"); - - if (phase.equals(Phase.CREATE)) { - // add namespaces filter property for left namespace - // setup all-namespaces property - V1EnvVar env = new V1EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_DISCOVERY_ALL_NAMESPACES") - .withValue("TRUE").build(); - V1Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0); - container.setEnv(List.of(env)); - - util.createAndWait(NAMESPACE, null, deployment, service, ingress, true); - } - else { - util.deleteAndWait(NAMESPACE, deployment, service, ingress); - } - } - - private WebClient.Builder builder() { - return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create())); - } - - private RetryBackoffSpec retrySpec() { - return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull); - } - -}