Renaming modules and moving common code to commons module. Updating tests.
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -93,7 +93,8 @@
|
||||
<module>spring-cloud-kubernetes-client-config</module>
|
||||
<module>spring-cloud-kubernetes-fabric8-autoconfig</module>
|
||||
<module>spring-cloud-kubernetes-fabric8-config</module>
|
||||
<module>spring-cloud-kubernetes-discovery</module>
|
||||
<module>spring-cloud-kubernetes-fabric8-discovery</module>
|
||||
<module>spring-cloud-kubernetes-client-discovery</module>
|
||||
<module>spring-cloud-starter-kubernetes</module>
|
||||
<module>spring-cloud-starter-kubernetes-config</module>
|
||||
<module>spring-cloud-starter-kubernetes-all</module>
|
||||
@@ -106,7 +107,6 @@
|
||||
<module>docs</module>
|
||||
<module>spring-cloud-kubernetes-loadbalancer</module>
|
||||
<module>spring-cloud-starter-kubernetes-loadbalancer</module>
|
||||
<module>spring-cloud-kubernetes-client-discovery</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.profile;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -40,6 +41,9 @@ class KubernetesClientProfileEnvironmentPostProcessorNoProfileTests {
|
||||
@MockBean
|
||||
CoreV1Api coreV1Api;
|
||||
|
||||
@MockBean
|
||||
ApiClient apiClient;
|
||||
|
||||
@Test
|
||||
void whenNoKubernetesEnvironmentAndNoApiAccessThenNoProfileEnabled() {
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.profile;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -43,6 +44,9 @@ class KubernetesClientProfileEnvironmentPostProcessorTests {
|
||||
@MockBean
|
||||
CoreV1Api coreV1Api;
|
||||
|
||||
@MockBean
|
||||
ApiClient apiClient;
|
||||
|
||||
@Test
|
||||
void whenKubernetesEnvironmentAndNoApiAccessThenProfileEnabled() {
|
||||
assertThat(environment.getActiveProfiles()).contains(KUBERNETES_PROFILE);
|
||||
|
||||
@@ -32,6 +32,7 @@ import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInfo
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
|
||||
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
||||
@@ -39,6 +40,7 @@ import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfigura
|
||||
import org.springframework.cloud.kubernetes.client.discovery.gson.EndpointsTrimmingStrategy;
|
||||
import org.springframework.cloud.kubernetes.client.discovery.gson.ServiceTrimmingStrategy;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -46,12 +48,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
@ConditionalOnKubernetesDiscoveryEnabled
|
||||
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class })
|
||||
@AutoConfigureAfter({ KubernetesClientAutoConfiguration.class })
|
||||
public class KubernetesReactiveDiscoveryClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public KubernetesDiscoveryProperties getKubernetesDiscoveryProperties() {
|
||||
return new KubernetesDiscoveryProperties();
|
||||
}
|
||||
@EnableConfigurationProperties(KubernetesDiscoveryProperties.class)
|
||||
public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnBlockingDiscoveryEnabled
|
||||
@@ -23,7 +23,7 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
|
||||
@Import({ KubernetesClientAutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.class })
|
||||
@Import({ KubernetesClientAutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class })
|
||||
public class KubernetesDiscoveryClientConfigClientBootstrapConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,275 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 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.discovery;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
@ConfigurationProperties("spring.cloud.kubernetes.discovery")
|
||||
public class KubernetesDiscoveryProperties {
|
||||
|
||||
/** If Kubernetes Discovery is enabled. */
|
||||
private boolean enabled = true;
|
||||
|
||||
/** The service name of the local instance. */
|
||||
@Value("${spring.application.name:unknown}")
|
||||
private String serviceName = "unknown";
|
||||
|
||||
/** If discovering all namespaces. */
|
||||
private boolean allNamespaces = false;
|
||||
|
||||
/*
|
||||
* If wait for the discovery cache (service and endpoints) to be fully loaded,
|
||||
* otherwise aborts the application on starting.
|
||||
*/
|
||||
private boolean waitCacheReady = true;
|
||||
|
||||
/** Timeout for initializing discovery cache, will abort the application if exceeded. **/
|
||||
private long cacheLoadingTimeoutSeconds = 60;
|
||||
|
||||
/**
|
||||
* SpEL expression to filter services AFTER they have been retrieved from the
|
||||
* Kubernetes API server.
|
||||
*/
|
||||
private String filter;
|
||||
|
||||
/** Set the port numbers that are considered secure and use HTTPS. */
|
||||
private Set<Integer> knownSecurePorts = new HashSet<Integer>() {
|
||||
{
|
||||
add(443);
|
||||
add(8443);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If set, then only the services matching these labels will be fetched from the
|
||||
* Kubernetes API server.
|
||||
*/
|
||||
private Map<String, String> serviceLabels = new HashMap<>();
|
||||
|
||||
/**
|
||||
* If set then the port with a given name is used as primary when multiple ports are
|
||||
* defined for a service.
|
||||
*/
|
||||
private String primaryPortName;
|
||||
|
||||
private Metadata metadata = new Metadata();
|
||||
|
||||
private int order = DiscoveryClient.DEFAULT_ORDER;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getServiceName() {
|
||||
return this.serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public Set<Integer> getKnownSecurePorts() {
|
||||
return this.knownSecurePorts;
|
||||
}
|
||||
|
||||
public void setKnownSecurePorts(Set<Integer> knownSecurePorts) {
|
||||
this.knownSecurePorts = knownSecurePorts;
|
||||
}
|
||||
|
||||
public Map<String, String> getServiceLabels() {
|
||||
return this.serviceLabels;
|
||||
}
|
||||
|
||||
public void setServiceLabels(Map<String, String> serviceLabels) {
|
||||
this.serviceLabels = serviceLabels;
|
||||
}
|
||||
|
||||
public String getPrimaryPortName() {
|
||||
return primaryPortName;
|
||||
}
|
||||
|
||||
public void setPrimaryPortName(String primaryPortName) {
|
||||
this.primaryPortName = primaryPortName;
|
||||
}
|
||||
|
||||
public Metadata getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Metadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public boolean isAllNamespaces() {
|
||||
return allNamespaces;
|
||||
}
|
||||
|
||||
public void setAllNamespaces(boolean allNamespaces) {
|
||||
this.allNamespaces = allNamespaces;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
boolean isWaitCacheReady() {
|
||||
return waitCacheReady;
|
||||
}
|
||||
|
||||
void setWaitCacheReady(boolean waitCacheReady) {
|
||||
this.waitCacheReady = waitCacheReady;
|
||||
}
|
||||
|
||||
long getCacheLoadingTimeoutSeconds() {
|
||||
return cacheLoadingTimeoutSeconds;
|
||||
}
|
||||
|
||||
void setCacheLoadingTimeoutSeconds(long cacheLoadingTimeoutSeconds) {
|
||||
this.cacheLoadingTimeoutSeconds = cacheLoadingTimeoutSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("enabled", this.enabled).append("serviceName", this.serviceName)
|
||||
.append("filter", this.filter).append("knownSecurePorts", this.knownSecurePorts)
|
||||
.append("serviceLabels", this.serviceLabels).append("metadata", this.metadata).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata properties.
|
||||
*/
|
||||
public class Metadata {
|
||||
|
||||
/**
|
||||
* When set, the Kubernetes labels of the services will be included as metadata of
|
||||
* the returned ServiceInstance.
|
||||
*/
|
||||
private boolean addLabels = true;
|
||||
|
||||
/**
|
||||
* When addLabels is set, then this will be used as a prefix to the key names in
|
||||
* the metadata map.
|
||||
*/
|
||||
private String labelsPrefix;
|
||||
|
||||
/**
|
||||
* When set, the Kubernetes annotations of the services will be included as
|
||||
* metadata of the returned ServiceInstance.
|
||||
*/
|
||||
private boolean addAnnotations = true;
|
||||
|
||||
/**
|
||||
* When addAnnotations is set, then this will be used as a prefix to the key names
|
||||
* in the metadata map.
|
||||
*/
|
||||
private String annotationsPrefix;
|
||||
|
||||
/**
|
||||
* When set, any named Kubernetes service ports will be included as metadata of
|
||||
* the returned ServiceInstance.
|
||||
*/
|
||||
private boolean addPorts = true;
|
||||
|
||||
/**
|
||||
* When addPorts is set, then this will be used as a prefix to the key names in
|
||||
* the metadata map.
|
||||
*/
|
||||
private String portsPrefix = "port.";
|
||||
|
||||
public boolean isAddLabels() {
|
||||
return this.addLabels;
|
||||
}
|
||||
|
||||
public void setAddLabels(boolean addLabels) {
|
||||
this.addLabels = addLabels;
|
||||
}
|
||||
|
||||
public String getLabelsPrefix() {
|
||||
return this.labelsPrefix;
|
||||
}
|
||||
|
||||
public void setLabelsPrefix(String labelsPrefix) {
|
||||
this.labelsPrefix = labelsPrefix;
|
||||
}
|
||||
|
||||
public boolean isAddAnnotations() {
|
||||
return this.addAnnotations;
|
||||
}
|
||||
|
||||
public void setAddAnnotations(boolean addAnnotations) {
|
||||
this.addAnnotations = addAnnotations;
|
||||
}
|
||||
|
||||
public String getAnnotationsPrefix() {
|
||||
return this.annotationsPrefix;
|
||||
}
|
||||
|
||||
public void setAnnotationsPrefix(String annotationsPrefix) {
|
||||
this.annotationsPrefix = annotationsPrefix;
|
||||
}
|
||||
|
||||
public boolean isAddPorts() {
|
||||
return this.addPorts;
|
||||
}
|
||||
|
||||
public void setAddPorts(boolean addPorts) {
|
||||
this.addPorts = addPorts;
|
||||
}
|
||||
|
||||
public String getPortsPrefix() {
|
||||
return this.portsPrefix;
|
||||
}
|
||||
|
||||
public void setPortsPrefix(String portsPrefix) {
|
||||
this.portsPrefix = portsPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("addLabels", this.addLabels)
|
||||
.append("labelsPrefix", this.labelsPrefix).append("addAnnotations", this.addAnnotations)
|
||||
.append("annotationsPrefix", this.annotationsPrefix).append("addPorts", this.addPorts)
|
||||
.append("portsPrefix", this.portsPrefix).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class KubernetesInformerDiscoveryClient implements DiscoveryClient, InitializingBean {
|
||||
@@ -140,17 +142,18 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient, Initi
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.sharedInformerFactory.startAllRegisteredInformers();
|
||||
if (!Wait.poll(Duration.ofSeconds(1), Duration
|
||||
.ofSeconds(this.properties.getCacheLoadingTimeoutSeconds()), () -> {
|
||||
log.info("Waiting for the cache of informers to be fully loaded..");
|
||||
return this.informersReadyFunc.get();
|
||||
})) {
|
||||
if (!Wait.poll(Duration.ofSeconds(1), Duration.ofSeconds(this.properties.getCacheLoadingTimeoutSeconds()),
|
||||
() -> {
|
||||
log.info("Waiting for the cache of informers to be fully loaded..");
|
||||
return this.informersReadyFunc.get();
|
||||
})) {
|
||||
if (this.properties.isWaitCacheReady()) {
|
||||
throw new IllegalStateException(
|
||||
"Timeout waiting for informers cache to be ready, is the kubernetes service up?");
|
||||
"Timeout waiting for informers cache to be ready, is the kubernetes service up?");
|
||||
}
|
||||
else {
|
||||
log.warn("Timeout waiting for informers cache to be ready, ignoring the failure because waitForInformerCacheReady property is false");
|
||||
log.warn(
|
||||
"Timeout waiting for informers cache to be ready, ignoring the failure because waitForInformerCacheReady property is false");
|
||||
}
|
||||
}
|
||||
log.info("Cache fully loaded (total " + serviceLister.list().size()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.kubernetes.client.discovery.KubernetesReactiveDiscoveryClientAutoConfiguration
|
||||
org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientAutoConfiguration
|
||||
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.discovery;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -24,16 +27,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5",
|
||||
"spring.cloud.kubernetes.discovery.waitCacheReady=false"
|
||||
})
|
||||
public class KubernetesReactiveDiscoveryClientAutoConfigurationTests {
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5",
|
||||
"spring.cloud.kubernetes.discovery.waitCacheReady=false" })
|
||||
public class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DiscoveryClient discoveryClient;
|
||||
@@ -50,6 +55,14 @@ public class KubernetesReactiveDiscoveryClientAutoConfigurationTests {
|
||||
@SpringBootApplication
|
||||
protected static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public ApiClient apiClient() {
|
||||
ApiClient apiClient = mock(ApiClient.class);
|
||||
when(apiClient.getJSON()).thenReturn(new JSON());
|
||||
when(apiClient.getHttpClient()).thenReturn(new OkHttpClient.Builder().build());
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,9 @@ package org.springframework.cloud.kubernetes.client.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.JSON;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -42,10 +45,11 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
|
||||
@Import({ KubernetesClientAutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.class })
|
||||
@Import({ KubernetesClientAutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class })
|
||||
public class KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
@@ -78,19 +82,27 @@ public class KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests {
|
||||
TestPropertyValues.of(env).applyTo(parent);
|
||||
parent.register(UtilAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
EnvironmentKnobbler.class, KubernetesCommonsAutoConfiguration.class,
|
||||
KubernetesClientAutoConfiguration.class, KubernetesReactiveDiscoveryClientAutoConfiguration.class,
|
||||
KubernetesClientAutoConfiguration.class, KubernetesDiscoveryClientAutoConfiguration.class,
|
||||
DiscoveryClientConfigServiceBootstrapConfiguration.class, ConfigClientProperties.class);
|
||||
parent.refresh();
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setParent(parent);
|
||||
this.context.register(PropertyPlaceholderAutoConfiguration.class, KubernetesCommonsAutoConfiguration.class,
|
||||
KubernetesReactiveDiscoveryClientAutoConfiguration.class);
|
||||
KubernetesDiscoveryClientAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class EnvironmentKnobbler {
|
||||
|
||||
@Bean
|
||||
public ApiClient apiClient() {
|
||||
ApiClient apiClient = mock(ApiClient.class);
|
||||
when(apiClient.getJSON()).thenReturn(new JSON());
|
||||
when(apiClient.getHttpClient()).thenReturn(new OkHttpClient.Builder().build());
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KubernetesInformerDiscoveryClient kubernetesInformerDiscoveryClient() {
|
||||
KubernetesInformerDiscoveryClient client = mock(KubernetesInformerDiscoveryClient.class);
|
||||
|
||||
@@ -34,6 +34,9 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -70,8 +73,8 @@ public class KubernetesInformerDiscoveryClientTests {
|
||||
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("",
|
||||
sharedInformerFactory, serviceLister, null, null, null, kubernetesDiscoveryProperties);
|
||||
|
||||
assertThat(discoveryClient.getServices().toArray())
|
||||
.containsOnly(testService1.getMetadata().getName(), testService2.getMetadata().getName());
|
||||
assertThat(discoveryClient.getServices().toArray()).containsOnly(testService1.getMetadata().getName(),
|
||||
testService2.getMetadata().getName());
|
||||
|
||||
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
|
||||
}
|
||||
@@ -85,8 +88,7 @@ public class KubernetesInformerDiscoveryClientTests {
|
||||
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
|
||||
sharedInformerFactory, serviceLister, null, null, null, kubernetesDiscoveryProperties);
|
||||
|
||||
assertThat(discoveryClient.getServices().toArray())
|
||||
.containsOnly(testService1.getMetadata().getName());
|
||||
assertThat(discoveryClient.getServices().toArray()).containsOnly(testService1.getMetadata().getName());
|
||||
|
||||
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
|
||||
}
|
||||
@@ -99,10 +101,10 @@ public class KubernetesInformerDiscoveryClientTests {
|
||||
when(kubernetesDiscoveryProperties.isAllNamespaces()).thenReturn(true);
|
||||
|
||||
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("",
|
||||
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
|
||||
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
|
||||
|
||||
assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(
|
||||
new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
|
||||
assertThat(discoveryClient.getInstances("test-svc-1"))
|
||||
.containsOnly(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
|
||||
|
||||
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
|
||||
}
|
||||
@@ -115,10 +117,10 @@ public class KubernetesInformerDiscoveryClientTests {
|
||||
when(kubernetesDiscoveryProperties.isAllNamespaces()).thenReturn(false);
|
||||
|
||||
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient("namespace1",
|
||||
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
|
||||
sharedInformerFactory, serviceLister, endpointsLister, null, null, kubernetesDiscoveryProperties);
|
||||
|
||||
assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(
|
||||
new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
|
||||
assertThat(discoveryClient.getInstances("test-svc-1"))
|
||||
.containsOnly(new KubernetesServiceInstance("", "test-svc-1", "2.2.2.2", 8080, new HashMap<>(), false));
|
||||
verify(kubernetesDiscoveryProperties, times(1)).isAllNamespaces();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class KubernetesServiceInstanceTests {
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.commons.discovery;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -23,14 +23,10 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
/**
|
||||
* Kubernetes discovery properties.
|
||||
*
|
||||
* @author Ioannis Canellos
|
||||
*/
|
||||
import static org.springframework.cloud.client.discovery.DiscoveryClient.DEFAULT_ORDER;
|
||||
|
||||
@ConfigurationProperties("spring.cloud.kubernetes.discovery")
|
||||
public class KubernetesDiscoveryProperties {
|
||||
|
||||
@@ -44,6 +40,17 @@ public class KubernetesDiscoveryProperties {
|
||||
/** If discovering all namespaces. */
|
||||
private boolean allNamespaces = false;
|
||||
|
||||
/*
|
||||
* If wait for the discovery cache (service and endpoints) to be fully loaded,
|
||||
* otherwise aborts the application on starting.
|
||||
*/
|
||||
private boolean waitCacheReady = true;
|
||||
|
||||
/**
|
||||
* Timeout for initializing discovery cache, will abort the application if exceeded.
|
||||
**/
|
||||
private long cacheLoadingTimeoutSeconds = 60;
|
||||
|
||||
/**
|
||||
* SpEL expression to filter services AFTER they have been retrieved from the
|
||||
* Kubernetes API server.
|
||||
@@ -72,7 +79,7 @@ public class KubernetesDiscoveryProperties {
|
||||
|
||||
private Metadata metadata = new Metadata();
|
||||
|
||||
private int order = DiscoveryClient.DEFAULT_ORDER;
|
||||
private int order = DEFAULT_ORDER;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
@@ -146,6 +153,22 @@ public class KubernetesDiscoveryProperties {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public boolean isWaitCacheReady() {
|
||||
return waitCacheReady;
|
||||
}
|
||||
|
||||
public void setWaitCacheReady(boolean waitCacheReady) {
|
||||
this.waitCacheReady = waitCacheReady;
|
||||
}
|
||||
|
||||
public long getCacheLoadingTimeoutSeconds() {
|
||||
return cacheLoadingTimeoutSeconds;
|
||||
}
|
||||
|
||||
public void setCacheLoadingTimeoutSeconds(long cacheLoadingTimeoutSeconds) {
|
||||
this.cacheLoadingTimeoutSeconds = cacheLoadingTimeoutSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("enabled", this.enabled).append("serviceName", this.serviceName)
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.discovery;
|
||||
package org.springframework.cloud.kubernetes.commons.discovery;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
@@ -26,9 +26,9 @@ import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8ConfigMapPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8SecretsPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@@ -29,8 +29,8 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8ConfigMapPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.core.env.AbstractEnvironment;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@@ -27,8 +27,8 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8SecretsPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.core.env.AbstractEnvironment;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@@ -40,9 +40,9 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8ConfigMapPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@@ -40,9 +40,9 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.Fabric8SecretsPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClient;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@@ -94,7 +94,13 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-client-discovery</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 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.discovery;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
|
||||
/**
|
||||
* Kubernetes {@link ServiceInstance}.
|
||||
*
|
||||
* @author Ioannis Canellos
|
||||
*/
|
||||
public class KubernetesServiceInstance implements ServiceInstance {
|
||||
|
||||
/**
|
||||
* Key of the namespace metadata.
|
||||
*/
|
||||
public static final String NAMESPACE_METADATA_KEY = "k8s_namespace";
|
||||
|
||||
private static final String HTTP_PREFIX = "http";
|
||||
|
||||
private static final String HTTPS_PREFIX = "https";
|
||||
|
||||
private static final String DSL = "//";
|
||||
|
||||
private static final String COLON = ":";
|
||||
|
||||
private final String instanceId;
|
||||
|
||||
private final String serviceId;
|
||||
|
||||
private final String host;
|
||||
|
||||
private final int port;
|
||||
|
||||
private final URI uri;
|
||||
|
||||
private final Boolean secure;
|
||||
|
||||
private final Map<String, String> metadata;
|
||||
|
||||
/**
|
||||
* @param instanceId the id of the instance.
|
||||
* @param serviceId the id of the service.
|
||||
* @param host the address where the service instance can be found.
|
||||
* @param port the port on which the service is running.
|
||||
* @param metadata a map containing metadata.
|
||||
* @param secure indicates whether or not the connection needs to be secure.
|
||||
*/
|
||||
public KubernetesServiceInstance(String instanceId, String serviceId, String host, int port,
|
||||
Map<String, String> metadata, Boolean secure) {
|
||||
this.instanceId = instanceId;
|
||||
this.serviceId = serviceId;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.metadata = metadata;
|
||||
this.secure = secure;
|
||||
this.uri = createUri(secure ? HTTPS_PREFIX : HTTP_PREFIX, host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstanceId() {
|
||||
return this.instanceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
return this.serviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return this.secure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return isSecure() ? HTTPS_PREFIX : HTTP_PREFIX;
|
||||
}
|
||||
|
||||
private URI createUri(String scheme, String host, int port) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(scheme).append(COLON).append(DSL).append(host).append(COLON).append(port);
|
||||
return URI.create(sb.toString());
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return this.metadata != null ? this.metadata.get(NAMESPACE_METADATA_KEY) : null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.kubernetes.discovery.KubernetesCatalogWatchAutoConfiguration, \
|
||||
org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration, \
|
||||
org.springframework.cloud.kubernetes.discovery.reactive.KubernetesReactiveDiscoveryClientAutoConfiguration
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
<name>Spring Cloud Kubernetes :: Discovery</name>
|
||||
|
||||
<dependencies>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -24,6 +24,8 @@ import java.util.Set;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
|
||||
/**
|
||||
* TODO break up into delegates if the implementation get's more complicated
|
||||
* <p>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -34,6 +34,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
||||
@@ -41,7 +43,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
import static org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance.NAMESPACE_METADATA_KEY;
|
||||
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance.NAMESPACE_METADATA_KEY;
|
||||
|
||||
/**
|
||||
* Kubeneretes implementation of {@link DiscoveryClient}.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
@@ -26,9 +26,10 @@ import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.registry.KubernetesRegistration;
|
||||
import org.springframework.cloud.kubernetes.registry.KubernetesServiceRegistry;
|
||||
import org.springframework.cloud.kubernetes.fabric8.registry.KubernetesRegistration;
|
||||
import org.springframework.cloud.kubernetes.fabric8.registry.KubernetesServiceRegistry;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery.reactive;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery.reactive;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -22,9 +22,9 @@ import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesClientServicesFunction;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClient;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery.reactive;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery.reactive;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
@@ -31,10 +31,10 @@ import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIn
|
||||
import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator;
|
||||
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.discovery.ConditionalOnKubernetesDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesClientServicesFunction;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.ConditionalOnKubernetesDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.registry;
|
||||
package org.springframework.cloud.kubernetes.fabric8.registry;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.registry;
|
||||
package org.springframework.cloud.kubernetes.fabric8.registry;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -26,7 +26,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
|
||||
/**
|
||||
* Kubernetes implementation of a {@link Registration}.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.registry;
|
||||
package org.springframework.cloud.kubernetes.fabric8.registry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -0,0 +1,6 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesCatalogWatchAutoConfiguration, \
|
||||
org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration, \
|
||||
org.springframework.cloud.kubernetes.fabric8.discovery.reactive.KubernetesReactiveDiscoveryClientAutoConfiguration
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientConfigClientBootstrapConfiguration
|
||||
@@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DefaultIsServicePortSecureResolverTest {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.junit.After;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -40,6 +40,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.junit.After;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -49,6 +49,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -33,6 +33,8 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -37,6 +37,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -22,6 +22,8 @@ import io.fabric8.kubernetes.api.model.EndpointAddress;
|
||||
import io.fabric8.kubernetes.api.model.EndpointPort;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class KubernetesServiceInstanceTests {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery.reactive;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery.reactive;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator;
|
||||
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesDiscoveryClientAutoConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery.reactive;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery.reactive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -37,10 +37,8 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.discovery.support.KubernetesExtension;
|
||||
import org.springframework.cloud.kubernetes.discovery.support.KubernetesExtension.Client;
|
||||
import org.springframework.cloud.kubernetes.discovery.support.KubernetesExtension.Server;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.support.KubernetesExtension;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -52,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class KubernetesReactiveDiscoveryClientTests {
|
||||
|
||||
@BeforeEach
|
||||
public void setup(@Client KubernetesClient kubernetesClient) {
|
||||
public void setup(@KubernetesExtension.Client KubernetesClient kubernetesClient) {
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY,
|
||||
kubernetesClient.getConfiguration().getMasterUrl());
|
||||
@@ -63,7 +61,7 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyDefaults(@Client KubernetesClient kubernetesClient) {
|
||||
public void verifyDefaults(@KubernetesExtension.Client KubernetesClient kubernetesClient) {
|
||||
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
|
||||
ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(kubernetesClient, properties,
|
||||
KubernetesClient::services);
|
||||
@@ -72,8 +70,8 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFluxOfServices(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnFluxOfServices(@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("s1")
|
||||
.withLabels(new HashMap<String, String>() {
|
||||
@@ -98,8 +96,9 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound(
|
||||
@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().build()).once();
|
||||
|
||||
@@ -111,8 +110,9 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyFluxForNonExistingService(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnEmptyFluxForNonExistingService(
|
||||
@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get()
|
||||
.withPath("/api/v1/namespaces/test/endpoints?fieldSelector=metadata.name%3Dnonexistent-service")
|
||||
.andReturn(200, new EndpointsBuilder().build()).once();
|
||||
@@ -125,8 +125,9 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyFluxWhenServiceHasNoSubsets(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnEmptyFluxWhenServiceHasNoSubsets(
|
||||
@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service")
|
||||
.withLabels(new HashMap<String, String>() {
|
||||
@@ -148,7 +149,8 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFlux(@Client KubernetesClient kubernetesClient, @Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnFlux(@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
ServiceList services = new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service")
|
||||
.withNamespace("test").withLabels(new HashMap<String, String>() {
|
||||
{
|
||||
@@ -187,8 +189,8 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFluxWithPrefixedMetadata(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnFluxWithPrefixedMetadata(@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service")
|
||||
.withLabels(new HashMap<String, String>() {
|
||||
@@ -233,7 +235,8 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
|
||||
@Test
|
||||
public void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet(
|
||||
@Client KubernetesClient kubernetesClient, @Server KubernetesServer kubernetesServer) {
|
||||
@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service")
|
||||
.withLabels(new HashMap<String, String>() {
|
||||
@@ -276,8 +279,9 @@ class KubernetesReactiveDiscoveryClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFluxOfServicesAcrossAllNamespaces(@Client KubernetesClient kubernetesClient,
|
||||
@Server KubernetesServer kubernetesServer) {
|
||||
public void shouldReturnFluxOfServicesAcrossAllNamespaces(
|
||||
@KubernetesExtension.Client KubernetesClient kubernetesClient,
|
||||
@KubernetesExtension.Server KubernetesServer kubernetesServer) {
|
||||
kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
|
||||
.andReturn(200, new ServiceListBuilder().addNewItem().withNewMetadata().withName("existing-service")
|
||||
.withLabels(new HashMap<String, String>() {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.discovery.support;
|
||||
package org.springframework.cloud.kubernetes.fabric8.discovery.support;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -24,7 +24,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -9,22 +9,23 @@ items:
|
||||
app: integration-test
|
||||
name: spring-cloud-kubernetes-serviceaccount
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
labels:
|
||||
app: spring-cloud-kubernetes-core-k8s-client-it
|
||||
name: spring-cloud-kubernetes-core-k8s-client-it:view
|
||||
roleRef:
|
||||
kind: Role
|
||||
kind: ClusterRole
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
name: namespace-reader
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: spring-cloud-kubernetes-serviceaccount
|
||||
namespace: default
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
namespace: default
|
||||
# namespace: default
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- apiGroups: ["", "extensions", "apps"]
|
||||
|
||||
@@ -105,9 +105,9 @@ public class ActuatorEndpointIT {
|
||||
k8SUtils = new K8SUtils(api, appsApi);
|
||||
|
||||
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||
.withRegistryUrl(KIND_REPO_URL).build();
|
||||
.withRegistryUrl(KIND_REPO_URL).build();
|
||||
DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost())
|
||||
.sslConfig(config.getSSLConfig()).build();
|
||||
.sslConfig(config.getSSLConfig()).build();
|
||||
|
||||
DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient);
|
||||
dockerClient.tagImageCmd(LOCAL_IMAGE, KIND_IMAGE, IMAGE_TAG).exec();
|
||||
@@ -127,19 +127,19 @@ public class ActuatorEndpointIT {
|
||||
|
||||
private static V1Deployment getCoreK8sClientItDeployment() throws Exception {
|
||||
V1Deployment deployment = (V1Deployment) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-deployment.yaml");
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-deployment.yaml");
|
||||
return deployment;
|
||||
}
|
||||
|
||||
private static V1Service getCoreK8sClientItService() throws Exception {
|
||||
V1Service service = (V1Service) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-service.yaml");
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-service.yaml");
|
||||
return service;
|
||||
}
|
||||
|
||||
private static NetworkingV1beta1Ingress getCoreK8sClientItIngress() throws Exception {
|
||||
NetworkingV1beta1Ingress ingress = (NetworkingV1beta1Ingress) k8SUtils
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-ingress.yaml");
|
||||
.readYamlFromClasspath("spring-cloud-kubernetes-core-k8s-client-it-ingress.yaml");
|
||||
return ingress;
|
||||
}
|
||||
|
||||
@@ -163,13 +163,14 @@ public class ActuatorEndpointIT {
|
||||
}
|
||||
});
|
||||
|
||||
//Sometimes the NGINX ingress takes a bit to catch up and realize the service is available and we get a 503, we just need to wait a bit
|
||||
// Sometimes the NGINX ingress takes a bit to catch up and realize the service is
|
||||
// available and we get a 503, we just need to wait a bit
|
||||
await().timeout(Duration.ofSeconds(60))
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/health", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/health", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
|
||||
Map<String, Object> health = rest.getForObject("http://localhost:80/core-k8s-client-it/actuator/health",
|
||||
Map.class);
|
||||
Map.class);
|
||||
Map<String, Object> components = (Map) health.get("components");
|
||||
assertThat(components.containsKey("kubernetes")).isTrue();
|
||||
Map<String, Object> kubernetes = (Map) components.get("kubernetes");
|
||||
@@ -189,7 +190,6 @@ public class ActuatorEndpointIT {
|
||||
public void testInfo() {
|
||||
RestTemplate rest = new RestTemplateBuilder().build();
|
||||
|
||||
|
||||
rest.setErrorHandler(new ResponseErrorHandler() {
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
|
||||
@@ -206,10 +206,11 @@ public class ActuatorEndpointIT {
|
||||
}
|
||||
});
|
||||
|
||||
//Sometimes the NGINX ingress takes a bit to catch up and realize the service is available and we get a 503, we just need to wait a bit
|
||||
// Sometimes the NGINX ingress takes a bit to catch up and realize the service is
|
||||
// available and we get a 503, we just need to wait a bit
|
||||
await().timeout(Duration.ofSeconds(60))
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/info", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
.until(() -> rest.getForEntity("http://localhost:80/core-k8s-client-it/actuator/info", String.class)
|
||||
.getStatusCode().is2xxSuccessful());
|
||||
|
||||
Map<String, Object> info = rest.getForObject("http://localhost:80/core-k8s-client-it/actuator/info", Map.class);
|
||||
Map<String, Object> kubernetes = (Map) info.get("kubernetes");
|
||||
@@ -225,7 +226,7 @@ public class ActuatorEndpointIT {
|
||||
@AfterClass
|
||||
public static void after() throws Exception {
|
||||
appsApi.deleteCollectionNamespacedDeployment(NAMESPACE, null, null, null,
|
||||
"metadata.name=" + K8S_CONFIG_CLIENT_IT_NAME, null, null, null, null, null, null, null, null);
|
||||
"metadata.name=" + K8S_CONFIG_CLIENT_IT_NAME, null, null, null, null, null, null, null, null);
|
||||
api.deleteNamespacedService(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, NAMESPACE, null, null, null, null, null, null);
|
||||
networkingApi.deleteNamespacedIngress("it-ingress", NAMESPACE, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.cloud.kubernetes.loadbalancer;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.cloud.kubernetes.loadbalancer;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ import io.fabric8.kubernetes.api.model.ServicePort;
|
||||
import io.fabric8.kubernetes.client.utils.Utils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
/**
|
||||
* Class for mapping Kubernetes Service object into {@link KubernetesServiceInstance}.
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -29,8 +29,8 @@ import io.fabric8.kubernetes.api.model.ServicePortBuilder;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
|
||||
class KubernetesServiceInstanceMapperTests {
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-client-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-client-discovery</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
|
||||
<artifactId>spring-cloud-kubernetes-fabric8-discovery</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user