Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 committed Apr 5, 2024
2 parents 8291b41 + 14c9780 commit 705f78b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
3 changes: 2 additions & 1 deletion docs/antora-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
antora:
extensions:
- '@springio/antora-extensions/partial-build-extension'
# atlas-extension must be before latest-version-extension so latest versions are applied to imported versions
- '@antora/atlas-extension'
- require: '@springio/antora-extensions/latest-version-extension'
- require: '@springio/antora-extensions/inject-collector-cache-config-extension'
- '@antora/collector-extension'
- '@antora/atlas-extension'
- require: '@springio/antora-extensions/root-component-extension'
root_component_name: 'cloud-kubernetes'
- '@springio/antora-extensions/static-page-extension'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import io.kubernetes.client.openapi.models.V1Service;
import io.kubernetes.client.openapi.models.V1ServicePort;
import io.kubernetes.client.openapi.models.V1ServiceSpec;

import org.apache.commons.logging.LogFactory;

import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
import org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
Expand All @@ -48,7 +48,7 @@
public class KubernetesClientServiceInstanceMapper implements KubernetesServiceInstanceMapper<V1Service> {

private static final LogAccessor LOG = new LogAccessor(
LogFactory.getLog(KubernetesClientServiceInstanceMapper.class));
LogFactory.getLog(KubernetesClientServiceInstanceMapper.class));

private static final String PORT_NAME_PROPERTY = "'spring.cloud.kubernetes.loadbalancer.portName'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,38 @@ void singlePortNameMatchesProperty(CapturedOutput output) {
V1Service service = createService("database", "default", annotations, labels, servicePorts);
KubernetesServiceInstance serviceInstance = mapper.map(service);
Assertions.assertNotNull(serviceInstance);
Assertions.assertTrue(output.getOut().contains("single ServicePort found, " +
"will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
Assertions.assertTrue(output.getOut().contains("single ServicePort found, "
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
}

@Test
void singlePortNameDoesNotMatchProperty(CapturedOutput output) {
KubernetesLoadBalancerProperties loadBalancerProperties = new KubernetesLoadBalancerProperties();
loadBalancerProperties.setPortName("http-api");
KubernetesClientServiceInstanceMapper mapper = new KubernetesClientServiceInstanceMapper(loadBalancerProperties,
KubernetesDiscoveryProperties.DEFAULT);
KubernetesDiscoveryProperties.DEFAULT);

Map<String, String> annotations = Map.of("org.springframework.cloud", "true");
Map<String, String> labels = Map.of("beta", "true");
List<V1ServicePort> servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build());
V1Service service = createService("database", "default", annotations, labels, servicePorts);
KubernetesServiceInstance serviceInstance = mapper.map(service);
Assertions.assertNotNull(serviceInstance);
Assertions.assertTrue(output.getOut().contains("single ServicePort found, " +
"will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
Assertions.assertTrue(output.getOut().contains("single ServicePort found, "
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
}

@Test
void multiplePortsNameMatchesProperty(CapturedOutput output) {
KubernetesLoadBalancerProperties loadBalancerProperties = new KubernetesLoadBalancerProperties();
loadBalancerProperties.setPortName("http");
KubernetesClientServiceInstanceMapper mapper = new KubernetesClientServiceInstanceMapper(loadBalancerProperties,
KubernetesDiscoveryProperties.DEFAULT);
KubernetesDiscoveryProperties.DEFAULT);

Map<String, String> annotations = Map.of("org.springframework.cloud", "true");
Map<String, String> labels = Map.of("beta", "true");
List<V1ServicePort> servicePorts = List.of(
new V1ServicePortBuilder().withName("http").withPort(80).build(),
new V1ServicePortBuilder().withName("https").withPort(443).build()
);
List<V1ServicePort> servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build(),
new V1ServicePortBuilder().withName("https").withPort(443).build());
V1Service service = createService("database", "default", annotations, labels, servicePorts);
KubernetesServiceInstance serviceInstance = mapper.map(service);
Assertions.assertNotNull(serviceInstance);
Expand All @@ -180,14 +178,12 @@ void multiplePortsNameDoesNotMatchProperty(CapturedOutput output) {
KubernetesLoadBalancerProperties loadBalancerProperties = new KubernetesLoadBalancerProperties();
loadBalancerProperties.setPortName("http");
KubernetesClientServiceInstanceMapper mapper = new KubernetesClientServiceInstanceMapper(loadBalancerProperties,
KubernetesDiscoveryProperties.DEFAULT);
KubernetesDiscoveryProperties.DEFAULT);

Map<String, String> annotations = Map.of("org.springframework.cloud", "true");
Map<String, String> labels = Map.of("beta", "true");
List<V1ServicePort> servicePorts = List.of(
new V1ServicePortBuilder().withName("http-api").withPort(80).build(),
new V1ServicePortBuilder().withName("https").withPort(443).build()
);
List<V1ServicePort> servicePorts = List.of(new V1ServicePortBuilder().withName("http-api").withPort(80).build(),
new V1ServicePortBuilder().withName("https").withPort(443).build());
V1Service service = createService("database", "default", annotations, labels, servicePorts);
KubernetesServiceInstance serviceInstance = mapper.map(service);
Assertions.assertNotNull(serviceInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ class KubernetesClientServicesListSupplierTests {
private static final V1Service SERVICE_A_DEFAULT_NAMESPACE = new V1ServiceBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("service-a").withNamespace("default").withUid("0")
.addToLabels("beta", "true").addToAnnotations("org.springframework.cloud", "true").build())
.withSpec(new V1ServiceSpecBuilder()
.withSpec(new V1ServiceSpecBuilder().withType("V1Service")
.addToPorts(new V1ServicePortBuilder().withPort(80).withName("http").build()).build())
.build();

private static final V1Service SERVICE_A_TEST_NAMESPACE = new V1ServiceBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("service-a").withNamespace("test").withUid("1").build())
.withSpec(new V1ServiceSpecBuilder()
.addToPorts(new V1ServicePortBuilder().withPort(80).withName("http").build(),
new V1ServicePortBuilder().withPort(443).withName("https").build())
.build())
.withSpec(
new V1ServiceSpecBuilder().withType("V1Service")
.addToPorts(new V1ServicePortBuilder().withPort(80).withName("http").build(),
new V1ServicePortBuilder().withPort(443).withName("https").build())
.build())
.build();

private static final V1ServiceList SINGLE_NAMESPACE_SERVICES = new V1ServiceList()
Expand Down Expand Up @@ -142,7 +143,8 @@ void singleNamespaceTest(CapturedOutput output) {

Flux<List<ServiceInstance>> instances = listSupplier.get();

Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true");
Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true", "k8s_namespace",
"default", "type", "V1Service");
DefaultKubernetesServiceInstance serviceA = new DefaultKubernetesServiceInstance("0", "service-a",
"service-a.default.svc.cluster.local", 80, metadata, false);
List<ServiceInstance> services = new ArrayList<>();
Expand Down Expand Up @@ -209,11 +211,12 @@ void allNamespacesTest(CapturedOutput output) {

Flux<List<ServiceInstance>> instances = listSupplier.get();

Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true");
Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true", "k8s_namespace",
"default", "type", "V1Service");
DefaultKubernetesServiceInstance serviceADefaultNamespace = new DefaultKubernetesServiceInstance("0",
"service-a", "service-a.default.svc.cluster.local", 80, metadata, false);
DefaultKubernetesServiceInstance serviceATestNamespace = new DefaultKubernetesServiceInstance("1", "service-a",
"service-a.test.svc.cluster.local", 80, Map.of(), false);
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false);
List<ServiceInstance> services = new ArrayList<>();
services.add(serviceADefaultNamespace);
services.add(serviceATestNamespace);
Expand Down Expand Up @@ -253,11 +256,12 @@ void selectiveNamespacesTest(CapturedOutput output) {

Flux<List<ServiceInstance>> instances = listSupplier.get();

Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true");
Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true", "k8s_namespace",
"default", "type", "V1Service");
DefaultKubernetesServiceInstance serviceADefaultNamespace = new DefaultKubernetesServiceInstance("0",
"service-a", "service-a.default.svc.cluster.local", 80, metadata, false);
DefaultKubernetesServiceInstance serviceATestNamespace = new DefaultKubernetesServiceInstance("1", "service-a",
"service-a.test.svc.cluster.local", 80, Map.of(), false);
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false);
List<ServiceInstance> services = new ArrayList<>();
services.add(serviceADefaultNamespace);
services.add(serviceATestNamespace);
Expand Down

0 comments on commit 705f78b

Please sign in to comment.