bumping kubernetes client to 11.0.0
This commit is contained in:
@@ -53,7 +53,7 @@ public class KubernetesClientConfigMapPropertySource extends ConfigMapPropertySo
|
||||
}
|
||||
}
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
coreV1Api.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null)
|
||||
coreV1Api.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null, null)
|
||||
.getItems().stream().filter(cm -> names.contains(cm.getMetadata().getName()))
|
||||
.forEach(map -> result.putAll(processAllEntries(map.getData(), environment)));
|
||||
|
||||
|
||||
@@ -56,11 +56,12 @@ public class KubernetesClientSecretsPropertySource extends SecretsPropertySource
|
||||
if (!StringUtils.hasText(namespace)) {
|
||||
|
||||
// There could technically be more than one, just return the first
|
||||
secret = api.listSecretForAllNamespaces(null, null, null, null, null, null, null, null, null)
|
||||
secret = api.listSecretForAllNamespaces(null, null, null, null, null, null, null, null, null, null)
|
||||
.getItems().stream().filter(s -> name.equals(s.getMetadata().getName())).findFirst();
|
||||
}
|
||||
else {
|
||||
secret = api.listNamespacedSecret(namespace, null, null, null, null, null, null, null, null, null)
|
||||
secret = api
|
||||
.listNamespacedSecret(namespace, null, null, null, null, null, null, null, null, null, null)
|
||||
.getItems().stream().filter(s -> name.equals(s.getMetadata().getName())).findFirst();
|
||||
}
|
||||
|
||||
@@ -71,11 +72,11 @@ public class KubernetesClientSecretsPropertySource extends SecretsPropertySource
|
||||
if (labels != null && !labels.isEmpty()) {
|
||||
if (!StringUtils.hasText(namespace)) {
|
||||
api.listSecretForAllNamespaces(null, null, null, createLabelsSelector(labels), null, null, null,
|
||||
null, null).getItems().forEach(s -> putAll(s, result));
|
||||
null, null, null).getItems().forEach(s -> putAll(s, result));
|
||||
}
|
||||
else {
|
||||
api.listNamespacedSecret(namespace, null, null, null, null, createLabelsSelector(labels), null,
|
||||
null, null, null).getItems().forEach(s -> putAll(s, result));
|
||||
null, null, null, null).getItems().forEach(s -> putAll(s, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
|
||||
SharedIndexInformer<V1ConfigMap> configMapInformer = factory.sharedIndexInformerFor(
|
||||
(CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(
|
||||
kubernetesClientProperties.getNamespace(), null, null, null, null, null, null,
|
||||
params.resourceVersion, params.timeoutSeconds, params.watch, null),
|
||||
params.resourceVersion, null, params.timeoutSeconds, params.watch, null),
|
||||
V1ConfigMap.class, V1ConfigMapList.class);
|
||||
configMapInformer.addEventHandler(new ResourceEventHandler<V1ConfigMap>() {
|
||||
@Override
|
||||
|
||||
@@ -94,7 +94,7 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
|
||||
SharedIndexInformer<V1Secret> configMapInformer = factory.sharedIndexInformerFor(
|
||||
(CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(
|
||||
kubernetesClientProperties.getNamespace(), null, null, null, null, null, null,
|
||||
params.resourceVersion, params.timeoutSeconds, params.watch, null),
|
||||
params.resourceVersion, null, params.timeoutSeconds, params.watch, null),
|
||||
V1Secret.class, V1SecretList.class);
|
||||
configMapInformer.addEventHandler(new ResourceEventHandler<V1Secret>() {
|
||||
@Override
|
||||
|
||||
@@ -24,10 +24,11 @@ import io.kubernetes.client.openapi.models.V1Endpoints;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointsList;
|
||||
import io.kubernetes.client.openapi.models.V1Service;
|
||||
import io.kubernetes.client.openapi.models.V1ServiceList;
|
||||
import io.kubernetes.client.spring.extended.controller.KubernetesInformerFactoryProcessor;
|
||||
import io.kubernetes.client.spring.extended.controller.KubernetesInformerConfigurer;
|
||||
import io.kubernetes.client.spring.extended.controller.annotation.GroupVersionResource;
|
||||
import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformer;
|
||||
import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformers;
|
||||
import io.kubernetes.client.spring.extended.controller.config.KubernetesInformerAutoConfiguration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -44,8 +45,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesDiscoveryEnabled
|
||||
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class })
|
||||
@AutoConfigureAfter({ KubernetesClientAutoConfiguration.class })
|
||||
@AutoConfigureBefore({
|
||||
SimpleDiscoveryClientAutoConfiguration.class,
|
||||
CommonsClientAutoConfiguration.class,
|
||||
// So that CatalogSharedInformerFactory can be processed in prior to the default factory
|
||||
KubernetesInformerAutoConfiguration.class})
|
||||
@AutoConfigureAfter({KubernetesClientAutoConfiguration.class})
|
||||
@EnableConfigurationProperties(KubernetesDiscoveryProperties.class)
|
||||
public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@@ -55,8 +60,9 @@ public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public KubernetesInformerFactoryProcessor kubernetesInformerFactoryProcessor() {
|
||||
return new KubernetesInformerFactoryProcessor();
|
||||
public KubernetesInformerConfigurer discoveryInformerConfigurer(ApiClient apiClient,
|
||||
CatalogSharedInformerFactory sharedInformerFactory) {
|
||||
return new KubernetesInformerConfigurer(apiClient, sharedInformerFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.discovery;
|
||||
|
||||
import io.kubernetes.client.informer.SharedInformer;
|
||||
import io.kubernetes.client.informer.SharedInformerFactory;
|
||||
import io.kubernetes.client.informer.cache.Lister;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1Endpoints;
|
||||
import io.kubernetes.client.openapi.models.V1Service;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -68,31 +63,6 @@ public class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Lister<V1Service> serviceLister() {
|
||||
return mock(Lister.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Lister<V1Endpoints> endpointsLister() {
|
||||
return mock(Lister.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformerFactory sharedInformerFactory() {
|
||||
return mock(SharedInformerFactory.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformer<V1Endpoints> sharedInformerEndpoints() {
|
||||
return mock(SharedInformer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformer<V1Service> sharedInformerService() {
|
||||
return mock(SharedInformer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.discovery.reactive;
|
||||
|
||||
import io.kubernetes.client.informer.SharedInformer;
|
||||
import io.kubernetes.client.informer.SharedInformerFactory;
|
||||
import io.kubernetes.client.informer.cache.Lister;
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import io.kubernetes.client.openapi.models.V1Endpoints;
|
||||
import io.kubernetes.client.openapi.models.V1Service;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -71,31 +66,6 @@ public class KubernetesInformerReactiveDiscoveryClientAutoConfigurationTests {
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Lister<V1Service> serviceLister() {
|
||||
return mock(Lister.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Lister<V1Endpoints> endpointsLister() {
|
||||
return mock(Lister.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformerFactory sharedInformerFactory() {
|
||||
return mock(SharedInformerFactory.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformer<V1Endpoints> sharedInformerEndpoints() {
|
||||
return mock(SharedInformer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SharedInformer<V1Service> sharedInformerService() {
|
||||
return mock(SharedInformer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ public class KubernetesClientServicesListSupplier extends KubernetesServicesList
|
||||
try {
|
||||
if (discoveryProperties.isAllNamespaces()) {
|
||||
services = coreV1Api.listServiceForAllNamespaces(null, null, "metadata.name=" + this.getServiceId(),
|
||||
null, null, null, null, null, null).getItems();
|
||||
null, null, null, null, null, null, null).getItems();
|
||||
}
|
||||
else {
|
||||
services = coreV1Api.listNamespacedService(kubernetesClientProperties.getNamespace(), null, null, null,
|
||||
"metadata.name=" + this.getServiceId(), null, null, null, null, null).getItems();
|
||||
"metadata.name=" + this.getServiceId(), null, null, null, null, null, null).getItems();
|
||||
}
|
||||
services.forEach(service -> result.add(mapper.map(service)));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
@@ -38,11 +37,9 @@ import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerD
|
||||
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -58,17 +55,17 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = KubernetesClientLoadBalancerPodModeTests.App.class,
|
||||
properties = { "spring.cloud.kubernetes.client.namespace=default" })
|
||||
classes = KubernetesClientLoadBalancerPodModeTests.App.class,
|
||||
properties = {"spring.cloud.kubernetes.client.namespace=default"})
|
||||
public class KubernetesClientLoadBalancerPodModeTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void testLoadBalancer() {
|
||||
ResponseEntity<String> map = rest.getForEntity("/servicea", String.class);
|
||||
assertThat(map.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String resp = restTemplate.getForObject("http://servicea-wiremock", String.class);
|
||||
assertThat(resp).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@RestController
|
||||
@@ -114,11 +111,6 @@ public class KubernetesClientLoadBalancerPodModeTests {
|
||||
return new RestTemplateBuilder().build();
|
||||
}
|
||||
|
||||
@GetMapping("/servicea")
|
||||
public String greeting() {
|
||||
return restTemplate().getForObject("http://servicea-wiremock", String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
@@ -44,11 +43,9 @@ import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerD
|
||||
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -83,12 +80,12 @@ public class KubernetesClientLoadBalancerServiceModeTests {
|
||||
.build();
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void testLoadBalancer() {
|
||||
ResponseEntity<String> map = rest.getForEntity("/servicea", String.class);
|
||||
assertThat(map.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String resp = restTemplate.getForObject("http://servicea-wiremock", String.class);
|
||||
assertThat(resp).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@RestController
|
||||
@@ -109,8 +106,8 @@ public class KubernetesClientLoadBalancerServiceModeTests {
|
||||
CoreV1Api coreV1Api = mock(CoreV1Api.class);
|
||||
try {
|
||||
when(coreV1Api.listNamespacedService(eq("default"), eq(null), eq(null), eq(null),
|
||||
eq("metadata.name=servicea-wiremock"), eq(null), eq(null), eq(null), eq(null), eq(null)))
|
||||
.thenReturn(SERVICE_LIST);
|
||||
eq("metadata.name=servicea-wiremock"), eq(null), eq(null), eq(null), eq(null), eq(null),
|
||||
eq(null))).thenReturn(SERVICE_LIST);
|
||||
}
|
||||
catch (ApiException e) {
|
||||
e.printStackTrace();
|
||||
@@ -147,11 +144,6 @@ public class KubernetesClientLoadBalancerServiceModeTests {
|
||||
return new RestTemplateBuilder().build();
|
||||
}
|
||||
|
||||
@GetMapping("/servicea")
|
||||
public String greeting() {
|
||||
return restTemplate().getForObject("http://servicea-wiremock", String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<arquillian-cube.version>1.15.2</arquillian-cube.version>
|
||||
<hoverfly.version>0.13.0</hoverfly.version>
|
||||
<kubernetes-client.version>4.10.3</kubernetes-client.version>
|
||||
<kubernetes-java-client.version>10.0.0</kubernetes-java-client.version>
|
||||
<kubernetes-java-client.version>11.0.0</kubernetes-java-client.version>
|
||||
<istio-client.version>1.5.5</istio-client.version>
|
||||
<mockwebserver.version>0.1.2</mockwebserver.version>
|
||||
<okhttp.version>3.14.4</okhttp.version>
|
||||
|
||||
@@ -138,7 +138,7 @@ public class K8SUtils {
|
||||
|
||||
public boolean isEndpointReady(String name, String namespace) throws ApiException {
|
||||
V1EndpointsList endpoints = api.listNamespacedEndpoints(namespace, null, null, null, "metadata.name=" + name,
|
||||
null, null, null, null, null);
|
||||
null, null, null, null, null, null);
|
||||
if (endpoints.getItems().isEmpty()) {
|
||||
fail("no endpoints for " + name);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class K8SUtils {
|
||||
|
||||
public boolean isReplicationControllerReady(String name, String namespace) throws ApiException {
|
||||
V1ReplicationControllerList controllerList = api.listNamespacedReplicationController(namespace, null, null,
|
||||
null, "metadata.name=" + name, null, null, null, null, null);
|
||||
null, "metadata.name=" + name, null, null, null, null, null, null);
|
||||
if (controllerList.getItems().size() < 1) {
|
||||
fail("Replication controller with name " + name + "could not be found");
|
||||
}
|
||||
@@ -175,13 +175,13 @@ public class K8SUtils {
|
||||
Duration.ofSeconds(90)).until(
|
||||
() -> appsApi
|
||||
.listNamespacedDeployment(namespace, null, null, null,
|
||||
"metadata.name=" + deploymentName, null, null, null, null, null)
|
||||
"metadata.name=" + deploymentName, null, null, null, null, null, null)
|
||||
.getItems().isEmpty());
|
||||
}
|
||||
|
||||
public boolean isDeployentReady(String deploymentName, String namespace) throws ApiException {
|
||||
V1DeploymentList deployments = appsApi.listNamespacedDeployment(namespace, null, null, null,
|
||||
"metadata.name=" + deploymentName, null, null, null, null, null);
|
||||
"metadata.name=" + deploymentName, null, null, null, null, null, null);
|
||||
if (deployments.getItems().size() < 1) {
|
||||
fail("No deployments with the name " + deploymentName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user