This commit is contained in:
piomin
2020-08-20 13:35:55 +02:00
parent d837efea6a
commit b76de6a69a
8 changed files with 23 additions and 39 deletions

View File

@@ -36,38 +36,28 @@ public class KubernetesServiceInstance implements ServiceInstance {
private static final String COLON = ":";
private String instanceId;
private final String instanceId;
private String serviceId;
private final String serviceId;
private String host;
private final String host;
private int port;
private final int port;
private URI uri;
private final URI uri;
private Boolean secure;
private final Boolean secure;
private Map<String, String> metadata;
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.
* @deprecated - use other constructor
*/
@Deprecated
public KubernetesServiceInstance(String serviceId, String host, int port,
Map<String, String> metadata, Boolean secure) {
this(null, serviceId, host, port, metadata, secure);
}
public KubernetesServiceInstance() {
}
public KubernetesServiceInstance(String instanceId, String serviceId, String host,
int port, Map<String, String> metadata, Boolean secure) {
this.instanceId = instanceId;

View File

@@ -36,7 +36,7 @@ import org.springframework.web.client.RestTemplate;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.cloud.kubernetes.discovery.all-namespaces=true" })
@RunWith(SpringRunner.class)
public class LoadBalancerAllNamespacesTest {
public class LoadBalancerAllNamespacesTests {
@Autowired
RestTemplate restTemplate;

View File

@@ -35,7 +35,7 @@ import org.springframework.web.client.RestTemplate;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
public class LoadBalancerTest {
public class LoadBalancerTests {
@Autowired
RestTemplate restTemplate;

View File

@@ -25,13 +25,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class KubernetesLoadBalancerProperties {
/**
* Ribbon enabled,default true.
* Load balancer enabled,default true.
*/
private Boolean enabled = true;
/**
* {@link KubernetesLoadBalancerMode} setting ribbon server list with ip of pod or
* service name. default value is POD.
* {@link KubernetesLoadBalancerMode} setting load balancer server list with ip of pod
* or service name. default value is POD.
*/
private KubernetesLoadBalancerMode mode = KubernetesLoadBalancerMode.POD;

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.kubernetes.loadbalancer;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -129,11 +128,4 @@ public class KubernetesServiceInstanceMapper {
properties.getClusterDomain());
}
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());
}
}

View File

@@ -35,13 +35,13 @@ import org.springframework.core.env.Environment;
*/
public class KubernetesServicesListSupplier implements ServiceInstanceListSupplier {
private Environment environment;
private final Environment environment;
private KubernetesClient kubernetesClient;
private final KubernetesClient kubernetesClient;
private KubernetesDiscoveryProperties discoveryProperties;
private final KubernetesDiscoveryProperties discoveryProperties;
private KubernetesServiceInstanceMapper mapper;
private final KubernetesServiceInstanceMapper mapper;
KubernetesServicesListSupplier(Environment environment,
KubernetesClient kubernetesClient, KubernetesServiceInstanceMapper mapper,

View File

@@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.cloud.kubernetes.discovery.KubernetesDiscoveryProperties;
import org.springframework.cloud.kubernetes.discovery.KubernetesServiceInstance;
public class KubernetesServiceInstanceMapperTest {
public class KubernetesServiceInstanceMapperTests {
@Test
public void testMapperSimple() {

View File

@@ -44,7 +44,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class KubernetesServiceListSupplierTest {
public class KubernetesServiceListSupplierTests {
@Mock
Environment environment;
@@ -71,7 +71,8 @@ public class KubernetesServiceListSupplierTest {
void testPositiveMatch() {
when(environment.getProperty("loadbalancer.client.name"))
.thenReturn("test-service");
when(mapper.map(any(Service.class))).thenReturn(new KubernetesServiceInstance());
when(mapper.map(any(Service.class)))
.thenReturn(new KubernetesServiceInstance("", "", "", 0, null, false));
when(this.client.getNamespace()).thenReturn("test");
when(this.client.services()).thenReturn(this.serviceOperation);
when(this.serviceOperation.inNamespace("test")).thenReturn(namespaceOperation);
@@ -89,7 +90,8 @@ public class KubernetesServiceListSupplierTest {
void testPositiveMatchAllNamespaces() {
when(environment.getProperty("loadbalancer.client.name"))
.thenReturn("test-service");
when(mapper.map(any(Service.class))).thenReturn(new KubernetesServiceInstance());
when(mapper.map(any(Service.class)))
.thenReturn(new KubernetesServiceInstance("", "", "", 0, null, false));
when(this.client.services()).thenReturn(this.serviceOperation);
when(this.serviceOperation.inAnyNamespace()).thenReturn(this.multiDeletable);
when(this.multiDeletable.withField("metadata.name", "test-service"))