From b357471aaeb1fa938f1285ff57723cdc9f7b4df6 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 1 Feb 2021 15:17:44 +0000 Subject: [PATCH 1/3] Create LoadBalancer by hand instead of via annotation Fixes gh-1505 --- .../examples/SpringLoadBalancerExample.java | 11 +++++- .../endpoints/InformerEndpointsGetter.java | 7 +++- ...netesEndpointsLoadBalancerCreatorTest.java | 37 ++++++++++++------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java index 69dd3697aa..a3fa23228f 100644 --- a/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ b/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java @@ -51,7 +51,16 @@ public MyService myService() { public static class MyService { - @KubernetesEndpointsLoadBalanced(namespace = "default", name = "kubernetes") private LoadBalancer defaultKubernetesLoadBalancer; + + public MyService(Lister lister) { + InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); + RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); + defaultKubernetesLoadBalancer = new EndpointsLoadBalancer( + () -> getter.get("default", "kubernetes"), + strategy + ); + } + } } diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/InformerEndpointsGetter.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/InformerEndpointsGetter.java index 1a898ca67f..b5a1912dc4 100644 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/InformerEndpointsGetter.java +++ b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/InformerEndpointsGetter.java @@ -14,11 +14,14 @@ import io.kubernetes.client.informer.cache.Lister; import io.kubernetes.client.openapi.models.V1Endpoints; -import org.springframework.beans.factory.annotation.Autowired; public class InformerEndpointsGetter implements EndpointsGetter { - @Autowired private Lister endpointsLister; + private final Lister endpointsLister; + + public InformerEndpointsGetter(Lister lister) { + this.endpointsLister = lister; + } @Override public V1Endpoints get(String namespace, String name) { diff --git a/spring/src/test/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerCreatorTest.java b/spring/src/test/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerCreatorTest.java index 1ccab284e7..8ac6a3496d 100644 --- a/spring/src/test/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerCreatorTest.java +++ b/spring/src/test/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerCreatorTest.java @@ -12,10 +12,14 @@ */ package io.kubernetes.client.spring.extended.network; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import io.kubernetes.client.extended.network.EndpointsLoadBalancer; import io.kubernetes.client.extended.network.LoadBalanceStrategy; import io.kubernetes.client.extended.network.LoadBalancer; +import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; import io.kubernetes.client.extended.network.exception.NoAvailableAddressException; import io.kubernetes.client.informer.cache.Cache; import io.kubernetes.client.informer.cache.Lister; @@ -24,8 +28,8 @@ import io.kubernetes.client.openapi.models.V1EndpointSubset; import io.kubernetes.client.openapi.models.V1Endpoints; import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.spring.extended.network.annotation.KubernetesEndpointsLoadBalanced; import io.kubernetes.client.spring.extended.network.endpoints.EndpointsGetter; +import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,28 +57,32 @@ public Lister endpointsLister(Cache endpointsCache) { } @Bean - public MyBean myBean() { - return new MyBean(); + public MyBean myBean(Lister lister) { + return new MyBean(new MyEndpointGetter(), new MyStrategy(), lister); } } static class MyBean { - @KubernetesEndpointsLoadBalanced(namespace = "default", name = "no-such") + + public MyBean( + MyEndpointGetter myEndpointGetter, MyStrategy myStrategy, Lister lister) { + InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); + RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); + noSuchLoadBalancer = + new EndpointsLoadBalancer(() -> getter.get("default", "no-such"), strategy); + fooLoadBalancer = new EndpointsLoadBalancer(() -> getter.get("default", "foo"), strategy); + customStrategyLoadBalancer = + new EndpointsLoadBalancer(() -> getter.get("default", "foo"), myStrategy); + customEndpointGetterLoadBalancer = + new EndpointsLoadBalancer(() -> myEndpointGetter.get("default", "foo"), strategy); + } + private LoadBalancer noSuchLoadBalancer; - @KubernetesEndpointsLoadBalanced(namespace = "default", name = "foo") private LoadBalancer fooLoadBalancer; - @KubernetesEndpointsLoadBalanced( - namespace = "default", - name = "foo", - strategy = MyStrategy.class) private LoadBalancer customStrategyLoadBalancer; - @KubernetesEndpointsLoadBalanced( - namespace = "default", - name = "foo", - endpointsGetter = MyEndpointGetter.class) private LoadBalancer customEndpointGetterLoadBalancer; } @@ -109,6 +117,7 @@ public V1Endpoints get(String namespace, String name) { new V1EndpointSubset() .addAddressesItem(new V1EndpointAddress().ip("127.0.0.1")) .addPortsItem(new V1EndpointPort().port(8080))); + @Autowired private MyBean myBean; @Autowired private Cache endpointsCache; From 0c899a907350237d87cca2cfc65065466f4f54cb Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 1 Feb 2021 15:23:41 +0000 Subject: [PATCH 2/3] Remove annotation and related post processor Signed-off-by: Dave Syer --- ...ernetesEndpointsLoadBalancerProcessor.java | 89 ------------------- .../KubernetesEndpointsLoadBalanced.java | 35 -------- ...tionalOnKubernetesLoadBalancerEnabled.java | 28 ------ ...bernetesLoadBalancerAutoConfiguration.java | 29 ------ .../endpoints/PollingEndpointsGetter.java | 11 ++- .../main/resources/META-INF/spring.factories | 1 - .../KubernetesInformerCreatorTest.java | 25 +++--- .../extended/network/TestApplication.java | 5 -- 8 files changed, 21 insertions(+), 202 deletions(-) delete mode 100644 spring/src/main/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerProcessor.java delete mode 100644 spring/src/main/java/io/kubernetes/client/spring/extended/network/annotation/KubernetesEndpointsLoadBalanced.java delete mode 100644 spring/src/main/java/io/kubernetes/client/spring/extended/network/config/ConditionalOnKubernetesLoadBalancerEnabled.java delete mode 100644 spring/src/main/java/io/kubernetes/client/spring/extended/network/config/KubernetesLoadBalancerAutoConfiguration.java diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerProcessor.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerProcessor.java deleted file mode 100644 index 9e64cf7fec..0000000000 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/KubernetesEndpointsLoadBalancerProcessor.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2020 The Kubernetes 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 -http://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 io.kubernetes.client.spring.extended.network; - -import io.kubernetes.client.extended.network.EndpointsLoadBalancer; -import io.kubernetes.client.extended.network.LoadBalanceStrategy; -import io.kubernetes.client.spring.extended.network.annotation.KubernetesEndpointsLoadBalanced; -import io.kubernetes.client.spring.extended.network.endpoints.EndpointsGetter; -import java.lang.reflect.Field; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.util.ReflectionUtils; - -public class KubernetesEndpointsLoadBalancerProcessor - implements InstantiationAwareBeanPostProcessor, ApplicationContextAware { - - private ApplicationContext applicationContext; - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) - throws BeansException { - Class beanClass = bean.getClass(); - for (Field field : beanClass.getDeclaredFields()) { - if (!field.isAnnotationPresent(KubernetesEndpointsLoadBalanced.class)) { - continue; - } - - KubernetesEndpointsLoadBalanced loadBalanced = - field.getAnnotation(KubernetesEndpointsLoadBalanced.class); - - EndpointsGetter epGetter; - try { - epGetter = - applicationContext - .getAutowireCapableBeanFactory() - .getBean(loadBalanced.endpointsGetter()); - } catch (NoSuchBeanDefinitionException ne) { - try { - epGetter = loadBalanced.endpointsGetter().newInstance(); - } catch (IllegalAccessException | InstantiationException e) { - throw new BeanCreationException("failed creating endpoint getter instance", e); - } - applicationContext.getAutowireCapableBeanFactory().autowireBean(epGetter); - applicationContext - .getAutowireCapableBeanFactory() - .initializeBean( - epGetter, "endpoints-getter-" + loadBalanced.endpointsGetter().getSimpleName()); - } - - LoadBalanceStrategy strategy; - try { - strategy = loadBalanced.strategy().newInstance(); - } catch (IllegalAccessException | InstantiationException e) { - throw new BeanCreationException( - "failed creating endpoint load-balance strategy instance", e); - } - - EndpointsGetter finalEpGetter = epGetter; - EndpointsLoadBalancer loadBalancer = - new EndpointsLoadBalancer( - () -> { - return finalEpGetter.get(loadBalanced.namespace(), loadBalanced.name()); - }, - strategy); - ReflectionUtils.makeAccessible(field); - ReflectionUtils.setField(field, bean, loadBalancer); - } - return bean; - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } -} diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/annotation/KubernetesEndpointsLoadBalanced.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/annotation/KubernetesEndpointsLoadBalanced.java deleted file mode 100644 index 1cc0e84682..0000000000 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/annotation/KubernetesEndpointsLoadBalanced.java +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2020 The Kubernetes 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 -http://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 io.kubernetes.client.spring.extended.network.annotation; - -import io.kubernetes.client.extended.network.LoadBalanceStrategy; -import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; -import io.kubernetes.client.spring.extended.network.endpoints.EndpointsGetter; -import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface KubernetesEndpointsLoadBalanced { - - String namespace(); - - String name(); - - Class strategy() default RoundRobinLoadBalanceStrategy.class; - - Class endpointsGetter() default InformerEndpointsGetter.class; -} diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/ConditionalOnKubernetesLoadBalancerEnabled.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/ConditionalOnKubernetesLoadBalancerEnabled.java deleted file mode 100644 index 8f676b3e9b..0000000000 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/ConditionalOnKubernetesLoadBalancerEnabled.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2020 The Kubernetes 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 -http://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 io.kubernetes.client.spring.extended.network.config; - -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; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@ConditionalOnProperty(value = "kubernetes.loadbalancer.enabled", matchIfMissing = true) -public @interface ConditionalOnKubernetesLoadBalancerEnabled {} diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/KubernetesLoadBalancerAutoConfiguration.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/KubernetesLoadBalancerAutoConfiguration.java deleted file mode 100644 index e508d0e2cb..0000000000 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/config/KubernetesLoadBalancerAutoConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Kubernetes 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 -http://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 io.kubernetes.client.spring.extended.network.config; - -import io.kubernetes.client.spring.extended.network.KubernetesEndpointsLoadBalancerProcessor; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration(proxyBeanMethods = false) -@ConditionalOnKubernetesLoadBalancerEnabled -public class KubernetesLoadBalancerAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public KubernetesEndpointsLoadBalancerProcessor kubernetesEndpointsLoadBalancerProcessor() { - return new KubernetesEndpointsLoadBalancerProcessor(); - } -} diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java index 03e3d07063..731805ba01 100644 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java +++ b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java @@ -12,22 +12,27 @@ */ package io.kubernetes.client.spring.extended.network.endpoints; +import java.time.Duration; + import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; + import io.kubernetes.client.apimachinery.NamespaceName; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.apis.CoreV1Api; import io.kubernetes.client.openapi.models.V1Endpoints; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Autowired; public class PollingEndpointsGetter implements EndpointsGetter { private static final Cache lastObservedEndpoints = Caffeine.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).build(); - @Autowired private ApiClient apiClient; + private final ApiClient apiClient; + + public PollingEndpointsGetter(ApiClient apiClient) { + this.apiClient = apiClient; + } @Override public V1Endpoints get(String namespace, String name) { diff --git a/spring/src/main/resources/META-INF/spring.factories b/spring/src/main/resources/META-INF/spring.factories index aaa853e42c..d89f340072 100644 --- a/spring/src/main/resources/META-INF/spring.factories +++ b/spring/src/main/resources/META-INF/spring.factories @@ -1,5 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ io.kubernetes.client.spring.extended.controller.config.KubernetesInformerAutoConfiguration, \ io.kubernetes.client.spring.extended.controller.config.KubernetesReconcilerAutoConfiguration, \ -io.kubernetes.client.spring.extended.network.config.KubernetesLoadBalancerAutoConfiguration, \ io.kubernetes.client.spring.extended.manifests.config.KubernetesManifestsAutoConfiguration diff --git a/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java b/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java index f5589da5fa..ff64279e78 100644 --- a/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java +++ b/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java @@ -22,8 +22,21 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.util.Arrays; + import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.Gson; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit4.SpringRunner; + import io.kubernetes.client.informer.SharedInformer; import io.kubernetes.client.informer.SharedInformerFactory; import io.kubernetes.client.informer.cache.Lister; @@ -38,16 +51,6 @@ import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformer; import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformers; import io.kubernetes.client.util.ClientBuilder; -import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = {KubernetesInformerCreatorTest.App.class}) @@ -99,8 +102,6 @@ static class TestSharedInformerFactory extends SharedInformerFactory {} @Autowired private Lister configMapLister; - @Autowired private ApiClient apiClient; - @Test public void testInformerInjection() throws InterruptedException { assertNotNull(podInformer); diff --git a/spring/src/test/java/io/kubernetes/client/spring/extended/network/TestApplication.java b/spring/src/test/java/io/kubernetes/client/spring/extended/network/TestApplication.java index 1fae0b6bdb..229de37360 100644 --- a/spring/src/test/java/io/kubernetes/client/spring/extended/network/TestApplication.java +++ b/spring/src/test/java/io/kubernetes/client/spring/extended/network/TestApplication.java @@ -12,12 +12,7 @@ */ package io.kubernetes.client.spring.extended.network; -import io.kubernetes.client.spring.extended.network.config.KubernetesLoadBalancerAutoConfiguration; import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @SpringBootConfiguration -@ImportAutoConfiguration({ - KubernetesLoadBalancerAutoConfiguration.class, -}) public class TestApplication {} From a630003cc75f6c09aad461ab987efa2e2b0acd32 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 2 Feb 2021 14:59:20 +0000 Subject: [PATCH 3/3] Fix spotless violations Signed-off-by: Dave Syer --- .../examples/SpringLoadBalancerExample.java | 15 ++++++++---- .../endpoints/PollingEndpointsGetter.java | 4 +--- .../KubernetesInformerCreatorTest.java | 23 ++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java index a3fa23228f..d0b08124a6 100644 --- a/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ b/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java @@ -12,15 +12,20 @@ */ package io.kubernetes.client.examples; -import io.kubernetes.client.extended.network.LoadBalancer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.spring.extended.network.annotation.KubernetesEndpointsLoadBalanced; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.kubernetes.client.extended.network.EndpointsLoadBalancer; +import io.kubernetes.client.extended.network.LoadBalancer; +import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; +import io.kubernetes.client.informer.SharedInformerFactory; +import io.kubernetes.client.informer.cache.Lister; +import io.kubernetes.client.openapi.models.V1Endpoints; +import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; + @SpringBootApplication public class SpringLoadBalancerExample { @@ -44,8 +49,8 @@ public CommandLineRunner loadBalancerCommandLineRunner( } @Bean - public MyService myService() { - return new MyService(); + public MyService myService(Lister lister) { + return new MyService(lister); } } diff --git a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java index 731805ba01..4c795ba014 100644 --- a/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java +++ b/spring/src/main/java/io/kubernetes/client/spring/extended/network/endpoints/PollingEndpointsGetter.java @@ -12,16 +12,14 @@ */ package io.kubernetes.client.spring.extended.network.endpoints; -import java.time.Duration; - import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; - import io.kubernetes.client.apimachinery.NamespaceName; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.apis.CoreV1Api; import io.kubernetes.client.openapi.models.V1Endpoints; +import java.time.Duration; public class PollingEndpointsGetter implements EndpointsGetter { diff --git a/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java b/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java index ff64279e78..6febe349b8 100644 --- a/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java +++ b/spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java @@ -22,21 +22,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.util.Arrays; - import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.gson.Gson; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringRunner; - import io.kubernetes.client.informer.SharedInformer; import io.kubernetes.client.informer.SharedInformerFactory; import io.kubernetes.client.informer.cache.Lister; @@ -51,6 +38,16 @@ import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformer; import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformers; import io.kubernetes.client.util.ClientBuilder; +import java.util.Arrays; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = {KubernetesInformerCreatorTest.App.class})