From a41000b62fbbedb15628e302e15dd9a10ea7aac7 Mon Sep 17 00:00:00 2001 From: erabii Date: Sat, 9 Mar 2024 21:47:09 +0200 Subject: [PATCH 1/9] Cleanup stale it (#1589) --- .../pom.xml | 105 ---------------- .../kubernetes/fabric8/core/SimpleCoreIT.java | 116 ------------------ 2 files changed, 221 deletions(-) delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml delete mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml deleted file mode 100644 index 0831f2928c..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - org.springframework.cloud - spring-cloud-kubernetes-integration-tests - 3.1.1-SNAPSHOT - - 4.0.0 - - spring-cloud-kubernetes-fabric8-client-simple-core - - - - org.springframework.cloud - spring-cloud-starter-kubernetes-fabric8-all - - - org.springframework.boot - spring-boot-starter-webflux - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.cloud - spring-cloud-kubernetes-test-support - - - - - - - ../src/main/resources - true - - - src/main/resources - true - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - docker.io/springcloud/${project.artifactId}:${project.version} - - - - build-image - - ${skip.build.image} - - package - - build-image - - - - repackage - package - - repackage - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - - - - - - ${testsToRun} - - - - - - - diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java deleted file mode 100644 index 7a810b3b2a..0000000000 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-simple-core/src/test/java/org/springframework/cloud/kubernetes/fabric8/core/SimpleCoreIT.java +++ /dev/null @@ -1,116 +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.fabric8.core; - -import java.io.InputStream; -import java.time.Duration; -import java.util.Objects; - -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.apps.Deployment; -import io.fabric8.kubernetes.api.model.networking.v1.Ingress; -import io.fabric8.kubernetes.client.KubernetesClient; -import io.fabric8.kubernetes.client.utils.Serialization; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -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.integration.tests.commons.Commons; -import org.springframework.cloud.kubernetes.integration.tests.commons.Phase; -import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util; -import org.springframework.http.HttpMethod; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.web.reactive.function.client.WebClient; - -/** - * @author wind57 - */ -class SimpleCoreIT { - - private static final String NAMESPACE = "default"; - - private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-simple-core"; - - private static KubernetesClient client; - - private static Util util; - - private static final K3sContainer K3S = Commons.container(); - - @BeforeAll - static void beforeAll() throws Exception { - K3S.start(); - Commons.validateImage(IMAGE_NAME, K3S); - Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S); - - util = new Util(K3S); - client = util.client(); - util.setUp(NAMESPACE); - - manifests(Phase.CREATE); - } - - @AfterAll - static void after() throws Exception { - manifests(Phase.DELETE); - Commons.cleanUp(IMAGE_NAME, K3S); - Commons.systemPrune(); - } - - @Test - void test() { - WebClient client = builder().baseUrl("http://localhost/message").build(); - - String result = client.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec()) - .block(); - - // value must come from application-kubernetes.yml - Assertions.assertEquals("Hello from k8s profile", result); - } - - private static void manifests(Phase phase) { - - InputStream deploymentStream = util.inputStream("simple-core-deployment.yaml"); - InputStream serviceStream = util.inputStream("simple-core-service.yaml"); - InputStream ingressStream = util.inputStream("simple-core-ingress.yaml"); - Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class); - Service service = Serialization.unmarshal(serviceStream, Service.class); - Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class); - - if (phase.equals(Phase.CREATE)) { - 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); - } - -} From 8cd41770165a8ea8f97cc067e2153f713a8d9571 Mon Sep 17 00:00:00 2001 From: erabii Date: Sun, 10 Mar 2024 14:30:38 +0200 Subject: [PATCH 2/9] Cleanup load balancer part 1 (#1590) --- .../Fabric8ServiceInstanceMapper.java | 10 +++--- .../Fabric8ServicesListSupplier.java | 11 +++--- ...bernetesClientLoadBalancerApplication.java | 28 ++++++--------- ...rnetesClientLoadBalancerConfiguration.java | 36 +++++++++++++++++++ 4 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerConfiguration.java diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java index 1fb1948e2f..9c4d2eda8d 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java @@ -51,8 +51,8 @@ public class Fabric8ServiceInstanceMapper implements KubernetesServiceInstanceMa @Override public KubernetesServiceInstance map(Service service) { - final ObjectMeta meta = service.getMetadata(); - final List ports = service.getSpec().getPorts(); + ObjectMeta meta = service.getMetadata(); + List ports = service.getSpec().getPorts(); ServicePort port = null; if (ports.size() == 1) { port = ports.get(0); @@ -67,16 +67,16 @@ else if (ports.size() > 1 && Utils.isNotNullOrEmpty(this.properties.getPortName( if (port == null) { return null; } - final String host = KubernetesServiceInstanceMapper.createHost(service.getMetadata().getName(), + String host = KubernetesServiceInstanceMapper.createHost(service.getMetadata().getName(), service.getMetadata().getNamespace(), properties.getClusterDomain()); - final boolean secure = KubernetesServiceInstanceMapper.isSecure(service.getMetadata().getLabels(), + boolean secure = KubernetesServiceInstanceMapper.isSecure(service.getMetadata().getLabels(), service.getMetadata().getAnnotations(), port.getName(), port.getPort()); return new DefaultKubernetesServiceInstance(meta.getUid(), meta.getName(), host, port.getPort(), getServiceMetadata(service), secure); } private Map getServiceMetadata(Service service) { - final Map serviceMetadata = new HashMap<>(); + Map serviceMetadata = new HashMap<>(); KubernetesDiscoveryProperties.Metadata metadataProps = this.discoveryProperties.metadata(); if (metadataProps.addLabels()) { Map labelMetadata = KubernetesServiceInstanceMapper diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServicesListSupplier.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServicesListSupplier.java index 217e15bf67..0972271c56 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServicesListSupplier.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServicesListSupplier.java @@ -50,15 +50,14 @@ public class Fabric8ServicesListSupplier extends KubernetesServicesListSupplier< public Flux> get() { List result = new ArrayList<>(); if (discoveryProperties.allNamespaces()) { - List services = this.kubernetesClient.services().inAnyNamespace() - .withField("metadata.name", this.getServiceId()).list().getItems(); + List services = kubernetesClient.services().inAnyNamespace() + .withField("metadata.name", getServiceId()).list().getItems(); services.forEach(service -> result.add(mapper.map(service))); } else { - Service service = StringUtils.hasText(this.kubernetesClient.getNamespace()) - ? this.kubernetesClient.services().inNamespace(this.kubernetesClient.getNamespace()) - .withName(this.getServiceId()).get() - : this.kubernetesClient.services().withName(this.getServiceId()).get(); + Service service = StringUtils.hasText(kubernetesClient.getNamespace()) ? kubernetesClient.services() + .inNamespace(kubernetesClient.getNamespace()).withName(getServiceId()).get() + : kubernetesClient.services().withName(getServiceId()).get(); if (service != null) { result.add(mapper.map(service)); } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java index 15983231c4..e6ddeff651 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java @@ -19,15 +19,10 @@ import java.util.List; import java.util.Map; -import reactor.netty.http.client.HttpClient; - import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; import org.springframework.http.HttpMethod; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.client.WebClient; @@ -38,35 +33,32 @@ @SpringBootApplication @RestController -public class KubernetesClientLoadBalancerApplication { +class KubernetesClientLoadBalancerApplication { private static final String URL = "http://service-wiremock/__admin/mappings"; private final DiscoveryClient discoveryClient; - public KubernetesClientLoadBalancerApplication(DiscoveryClient discoveryClien) { - this.discoveryClient = discoveryClien; + private final WebClient.Builder client; + + KubernetesClientLoadBalancerApplication(DiscoveryClient discoveryClient, WebClient.Builder client) { + this.discoveryClient = discoveryClient; + this.client = client; } public static void main(String[] args) { SpringApplication.run(KubernetesClientLoadBalancerApplication.class, args); } - @Bean - @LoadBalanced - WebClient.Builder client() { - return WebClient.builder(); - } - @GetMapping("/loadbalancer-it/service") @SuppressWarnings("unchecked") - public Map greeting() { - return (Map) client().clientConnector(new ReactorClientHttpConnector(HttpClient.create())) - .baseUrl(URL).build().method(HttpMethod.GET).retrieve().bodyToMono(Map.class).block(); + Map greeting() { + return (Map) client.baseUrl(URL).build().method(HttpMethod.GET).retrieve().bodyToMono(Map.class) + .block(); } @GetMapping("/services") - public List services() { + List services() { return discoveryClient.getServices(); } diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerConfiguration.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerConfiguration.java new file mode 100644 index 0000000000..2c029aa38e --- /dev/null +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerConfiguration.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2024 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.k8s.client.loadbalancer; + +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * @author wind57 + */ +@Configuration +class KubernetesClientLoadBalancerConfiguration { + + @Bean + @LoadBalanced + WebClient.Builder client() { + return WebClient.builder(); + } + +} From 0435e14dd50aa977afe85134448de1d2609cf14a Mon Sep 17 00:00:00 2001 From: erabii Date: Sun, 10 Mar 2024 20:52:21 +0200 Subject: [PATCH 3/9] Cleanup load balancer part 2 (#1591) --- ...ClientLoadBalancerClientConfiguration.java | 6 +-- ...ernetesLoadBalancerServiceModeEnabled.java | 40 +++++++++++++++++++ ...abric8LoadBalancerClientConfiguration.java | 6 +-- ...bernetesClientLoadBalancerApplication.java | 12 +----- 4 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/ConditionalOnKubernetesLoadBalancerServiceModeEnabled.java diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerClientConfiguration.java b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerClientConfiguration.java index 2a0585303d..9d57b3bc01 100644 --- a/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerClientConfiguration.java +++ b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientLoadBalancerClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2024 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. @@ -18,9 +18,9 @@ import io.kubernetes.client.openapi.apis.CoreV1Api; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.loadbalancer.ConditionalOnKubernetesLoadBalancerServiceModeEnabled; import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @@ -32,7 +32,7 @@ public class KubernetesClientLoadBalancerClientConfiguration { @Bean - @ConditionalOnProperty(name = "spring.cloud.kubernetes.loadbalancer.mode", havingValue = "SERVICE") + @ConditionalOnKubernetesLoadBalancerServiceModeEnabled ServiceInstanceListSupplier kubernetesServicesListSupplier(Environment environment, CoreV1Api coreV1Api, KubernetesClientServiceInstanceMapper mapper, KubernetesDiscoveryProperties discoveryProperties, KubernetesNamespaceProvider kubernetesNamespaceProvider, ConfigurableApplicationContext context) { diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/ConditionalOnKubernetesLoadBalancerServiceModeEnabled.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/ConditionalOnKubernetesLoadBalancerServiceModeEnabled.java new file mode 100644 index 0000000000..73fd006035 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/ConditionalOnKubernetesLoadBalancerServiceModeEnabled.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019-2024 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.commons.loadbalancer; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * Provides a conditional for: spring.cloud.kubernetes.loadbalancer.mode. + * + * @author wind57 + */ +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@ConditionalOnProperty(name = "spring.cloud.kubernetes.loadbalancer.mode", havingValue = "SERVICE") +public @interface ConditionalOnKubernetesLoadBalancerServiceModeEnabled { + +} diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8LoadBalancerClientConfiguration.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8LoadBalancerClientConfiguration.java index 7d73a76814..09ca17f6e1 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8LoadBalancerClientConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8LoadBalancerClientConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2024 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. @@ -18,8 +18,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; +import org.springframework.cloud.kubernetes.commons.loadbalancer.ConditionalOnKubernetesLoadBalancerServiceModeEnabled; import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @@ -33,7 +33,7 @@ public class Fabric8LoadBalancerClientConfiguration { @Bean - @ConditionalOnProperty(name = "spring.cloud.kubernetes.loadbalancer.mode", havingValue = "SERVICE") + @ConditionalOnKubernetesLoadBalancerServiceModeEnabled ServiceInstanceListSupplier kubernetesServicesListSupplier(Environment environment, KubernetesClient kubernetesClient, Fabric8ServiceInstanceMapper mapper, KubernetesDiscoveryProperties discoveryProperties, ConfigurableApplicationContext context) { diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java index e6ddeff651..e581d1f5dd 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/k8s/client/loadbalancer/KubernetesClientLoadBalancerApplication.java @@ -16,12 +16,10 @@ package org.springframework.cloud.kubernetes.k8s.client.loadbalancer; -import java.util.List; import java.util.Map; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.http.HttpMethod; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -37,12 +35,9 @@ class KubernetesClientLoadBalancerApplication { private static final String URL = "http://service-wiremock/__admin/mappings"; - private final DiscoveryClient discoveryClient; - private final WebClient.Builder client; - KubernetesClientLoadBalancerApplication(DiscoveryClient discoveryClient, WebClient.Builder client) { - this.discoveryClient = discoveryClient; + KubernetesClientLoadBalancerApplication(WebClient.Builder client) { this.client = client; } @@ -57,9 +52,4 @@ Map greeting() { .block(); } - @GetMapping("/services") - List services() { - return discoveryClient.getServices(); - } - } From d4e71238ea9e54f3d7cce60e34e9c9a9630f1a7f Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 12 Mar 2024 10:34:32 -0400 Subject: [PATCH 4/9] Update antora-playbook.yml to 0.4.11 --- docs/antora-playbook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/antora-playbook.yml b/docs/antora-playbook.yml index 962f890e23..4841f7cf69 100644 --- a/docs/antora-playbook.yml +++ b/docs/antora-playbook.yml @@ -36,4 +36,4 @@ runtime: format: pretty ui: bundle: - url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.2/ui-bundle.zip \ No newline at end of file + url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.11/ui-bundle.zip From d21c5d5873b3b78d6e6d962c42b397501289c207 Mon Sep 17 00:00:00 2001 From: erabii Date: Tue, 12 Mar 2024 19:22:29 +0200 Subject: [PATCH 5/9] Remove stale jdk8 files (#1596) --- spring-cloud-kubernetes-fabric8-autoconfig/.jdk8 | 0 spring-cloud-kubernetes-fabric8-config/.jdk8 | 0 spring-cloud-kubernetes-fabric8-discovery/.jdk8 | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 spring-cloud-kubernetes-fabric8-autoconfig/.jdk8 delete mode 100644 spring-cloud-kubernetes-fabric8-config/.jdk8 delete mode 100644 spring-cloud-kubernetes-fabric8-discovery/.jdk8 diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/.jdk8 b/spring-cloud-kubernetes-fabric8-autoconfig/.jdk8 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-cloud-kubernetes-fabric8-config/.jdk8 b/spring-cloud-kubernetes-fabric8-config/.jdk8 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-cloud-kubernetes-fabric8-discovery/.jdk8 b/spring-cloud-kubernetes-fabric8-discovery/.jdk8 deleted file mode 100644 index e69de29bb2..0000000000 From ad09a89f10fb202ee20bc3174bd2de45a29b2647 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 13 Mar 2024 10:22:41 -0400 Subject: [PATCH 6/9] Update leader election sample (#1281) Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> --- .../README.md | 24 +++++++------------ .../kubernetes/examples/LeaderController.java | 4 ++-- .../src/main/resources/application.properties | 2 ++ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/README.md b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/README.md index 1cd7e941e1..dabb0d2e1d 100644 --- a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/README.md +++ b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/README.md @@ -83,17 +83,18 @@ items: - apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - namespace: default - name: namespace-reader + namespace: default + name: namespace-reader rules: - - apiGroups: ["", "extensions", "apps"] - resources: ["configmaps", "pods", "services", "endpoints", "secrets"] - verbs: ["get", "list", "watch"] + - apiGroups: ["", "extensions", "apps"] + resources: ["configmaps", "pods", "services", "endpoints", "secrets"] + verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] - apiVersion: apps/v1 kind: Deployment metadata: name: kubernetes-leader-election-example spec: + replicas: 4 selector: matchLabels: app: kubernetes-leader-election-example @@ -148,17 +149,10 @@ And check the leadership information again: curl $SERVICE_URL ``` -Now you should receive a message like this: -``` -I am 'kubernetes-leader-election-example-1234567890-abcde' but I am not a leader of the 'world' -``` - -If you wouldn't do anything for a few seconds, the same instance will become a leader again because it only yielded its leadership but stayed in the cluster. +If another instance was able to acquire the leadership you should see a different instance is now the leadership. You may +have to try this a few times depending on how the service is load balanced. -Now scale the application to two instances and try all the steps again: -``` -kubectl scale --replicas=2 deployment.apps/kubernetes-leader-election-example -``` +`DEBUG` logging is enabled so you can view the logs of the instances in order to see which instance is acquiring leadership. > Note: with multiple replicas in the cluster, `curl` command will access one of them depending on the Kubernetes load balancing configuration. Thus, when trying to yield the leadership, request might go to a non-leader node first. Just execute command again until it reaches the correct node. diff --git a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/java/org/springframework/cloud/kubernetes/examples/LeaderController.java b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/java/org/springframework/cloud/kubernetes/examples/LeaderController.java index 39b142ac55..674aa10685 100644 --- a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/java/org/springframework/cloud/kubernetes/examples/LeaderController.java +++ b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/java/org/springframework/cloud/kubernetes/examples/LeaderController.java @@ -47,7 +47,7 @@ public LeaderController() throws UnknownHostException { * Return a message whether this instance is a leader or not. * @return info */ - @GetMapping + @GetMapping("/") public String getInfo() { if (this.context == null) { return String.format("I am '%s' but I am not a leader of the '%s'", this.host, this.role); @@ -63,7 +63,7 @@ public String getInfo() { * to give up the leadership. * @return info about leadership */ - @PutMapping + @PutMapping("/") public ResponseEntity revokeLeadership() { if (this.context == null) { String message = String.format("Cannot revoke leadership because '%s' is not a leader", this.host); diff --git a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/resources/application.properties b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/resources/application.properties index 6c665afdb1..faf8c085c4 100644 --- a/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/resources/application.properties +++ b/spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/resources/application.properties @@ -2,3 +2,5 @@ spring.cloud.kubernetes.leader.role=world # Configmap to which leader election metadata will be saved spring.cloud.kubernetes.leader.config-map-name=leader +logging.level.org.springframework.cloud.kubernetes.fabric8.leader=DEBUG +logging.level.org.springframework.cloud.kubernetes.commons.leader=DEBUG From bd5da79ed7337171dc63e9da6de1017adb422b77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:24:06 -0400 Subject: [PATCH 7/9] Bump org.codehaus.plexus:plexus-archiver (#1389) Bumps [org.codehaus.plexus:plexus-archiver](https://github.com/codehaus-plexus/plexus-archiver) from 4.1.0 to 4.8.0. - [Release notes](https://github.com/codehaus-plexus/plexus-archiver/releases) - [Changelog](https://github.com/codehaus-plexus/plexus-archiver/blob/master/ReleaseNotes.md) - [Commits](https://github.com/codehaus-plexus/plexus-archiver/compare/plexus-archiver-4.1.0...plexus-archiver-4.8.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-archiver dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../spring-cloud-kubernetes-configuration-watcher/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/pom.xml b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/pom.xml index 664ec35a3f..6c104fb147 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/pom.xml +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/pom.xml @@ -13,7 +13,7 @@ springcloud - 4.1.0 + 4.8.0 From a0fac955a50aa6d66e8483045ed49fff532d2356 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:25:01 -0400 Subject: [PATCH 8/9] Bump org.codehaus.plexus:plexus-archiver (#1390) Bumps [org.codehaus.plexus:plexus-archiver](https://github.com/codehaus-plexus/plexus-archiver) from 4.1.0 to 4.8.0. - [Release notes](https://github.com/codehaus-plexus/plexus-archiver/releases) - [Changelog](https://github.com/codehaus-plexus/plexus-archiver/blob/master/ReleaseNotes.md) - [Commits](https://github.com/codehaus-plexus/plexus-archiver/compare/plexus-archiver-4.1.0...plexus-archiver-4.8.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-archiver dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../spring-cloud-kubernetes-configserver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/pom.xml b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/pom.xml index a4ce118da6..a9e93d679e 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/pom.xml +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/pom.xml @@ -13,7 +13,7 @@ springcloud - 4.1.0 + 4.8.0 From 0f02596a98046112cd97fad2244bbead0f5e9998 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:25:36 -0400 Subject: [PATCH 9/9] Bump org.codehaus.plexus:plexus-archiver (#1391) Bumps [org.codehaus.plexus:plexus-archiver](https://github.com/codehaus-plexus/plexus-archiver) from 4.1.0 to 4.8.0. - [Release notes](https://github.com/codehaus-plexus/plexus-archiver/releases) - [Changelog](https://github.com/codehaus-plexus/plexus-archiver/blob/master/ReleaseNotes.md) - [Commits](https://github.com/codehaus-plexus/plexus-archiver/compare/plexus-archiver-4.1.0...plexus-archiver-4.8.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-archiver dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../spring-cloud-kubernetes-discoveryserver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-discoveryserver/pom.xml b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-discoveryserver/pom.xml index cc7d42539f..83cc2eeca4 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-discoveryserver/pom.xml +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-discoveryserver/pom.xml @@ -13,7 +13,7 @@ springcloud - 4.1.0 + 4.8.0