Merge branch '3.0.x'

This commit is contained in:
Ryan Baxter
2023-08-20 14:25:12 -07:00
9 changed files with 131 additions and 67 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.cloud.kubernetes.commons.discovery;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
@@ -29,7 +28,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.keysWithPrefix;
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.EXTERNAL_NAME;
@@ -59,7 +57,7 @@ public final class DiscoveryClientUtils {
* - service type
* </pre>
*/
public static Map<String, String> serviceInstanceMetadata(Map<String, String> portsData,
public static Map<String, String> serviceInstanceMetadata(Map<String, Integer> portsData,
ServiceMetadata serviceMetadata, KubernetesDiscoveryProperties properties) {
Map<String, String> result = new HashMap<>();
KubernetesDiscoveryProperties.Metadata metadataProps = properties.metadata();
@@ -77,7 +75,10 @@ public final class DiscoveryClientUtils {
}
if (metadataProps.addPorts()) {
Map<String, String> portMetadata = keysWithPrefix(portsData, properties.metadata().portsPrefix());
Map<String, String> portsDataValueAsString = portsData.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, en -> Integer.toString(en.getValue())));
Map<String, String> portMetadata = keysWithPrefix(portsDataValueAsString,
properties.metadata().portsPrefix());
if (!portMetadata.isEmpty()) {
LOG.debug(() -> "Adding port metadata: " + portMetadata + " for serviceId : " + serviceMetadata.name());
}
@@ -89,16 +90,16 @@ public final class DiscoveryClientUtils {
return result;
}
public static ServicePortNameAndNumber endpointsPort(LinkedHashMap<String, Integer> endpointsPorts,
public static ServicePortNameAndNumber endpointsPort(Map<String, Integer> existingPorts,
ServiceMetadata serviceMetadata, KubernetesDiscoveryProperties properties) {
if (endpointsPorts.size() == 0) {
if (existingPorts.isEmpty()) {
LOG.debug(() -> "no ports found for service : " + serviceMetadata.name() + ", will return zero");
return new ServicePortNameAndNumber(0, "http");
}
if (endpointsPorts.size() == 1) {
Map.Entry<String, Integer> single = endpointsPorts.entrySet().iterator().next();
if (existingPorts.size() == 1) {
Map.Entry<String, Integer> single = existingPorts.entrySet().iterator().next();
LOG.debug(() -> "endpoint ports has a single entry, using port : " + single.getValue());
return new ServicePortNameAndNumber(single.getValue(), single.getKey());
}
@@ -108,10 +109,6 @@ public final class DiscoveryClientUtils {
Optional<ServicePortNameAndNumber> portData;
String primaryPortName = primaryPortName(properties, serviceMetadata.labels(), serviceMetadata.name());
Map<String, Integer> existingPorts = endpointsPorts.entrySet().stream()
.filter(entry -> StringUtils.hasText(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
portData = fromMap(existingPorts, primaryPortName, "found primary-port-name (with value: '"
+ primaryPortName + "') via properties or service labels to match port");
if (portData.isPresent()) {
@@ -129,7 +126,7 @@ public final class DiscoveryClientUtils {
}
logWarnings();
Map.Entry<String, Integer> first = endpointsPorts.entrySet().iterator().next();
Map.Entry<String, Integer> first = existingPorts.entrySet().iterator().next();
return new ServicePortNameAndNumber(first.getValue(), first.getKey());
}

View File

@@ -61,7 +61,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of();
Map<String, String> serviceAnnotations = Map.of();
Map<String, String> portsData = Map.of();
Map<String, Integer> portsData = Map.of();
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -93,7 +93,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "1");
Map<String, String> serviceAnnotations = Map.of("b", "2");
Map<String, String> portsData = Map.of("c", "3");
Map<String, Integer> portsData = Map.of("c", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -125,7 +125,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b");
Map<String, String> serviceAnnotations = Map.of("c", "2");
Map<String, String> portsData = Map.of("d", "3");
Map<String, Integer> portsData = Map.of("d", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -161,7 +161,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b", "c", "d");
Map<String, String> serviceAnnotations = Map.of("c", "2");
Map<String, String> portsData = Map.of("d", "3");
Map<String, Integer> portsData = Map.of("d", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -199,7 +199,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b");
Map<String, String> serviceAnnotations = Map.of("aa", "bb");
Map<String, String> portsData = Map.of("d", "3");
Map<String, Integer> portsData = Map.of("d", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -234,7 +234,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b");
Map<String, String> serviceAnnotations = Map.of("aa", "bb", "cc", "dd");
Map<String, String> portsData = Map.of("d", "3");
Map<String, Integer> portsData = Map.of("d", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -272,7 +272,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b", "c", "d");
Map<String, String> serviceAnnotations = Map.of("aa", "bb", "cc", "dd");
Map<String, String> portsData = Map.of("d", "3");
Map<String, Integer> portsData = Map.of("d", 3);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -314,7 +314,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b");
Map<String, String> serviceAnnotations = Map.of("aa", "bb", "cc", "dd");
Map<String, String> portsData = Map.of("https", "8080");
Map<String, Integer> portsData = Map.of("https", 8080);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -348,7 +348,7 @@ class DiscoveryClientUtilsTests {
Map<String, String> serviceLabels = Map.of("a", "b");
Map<String, String> serviceAnnotations = Map.of("aa", "bb", "cc", "dd");
Map<String, String> portsData = Map.of("http", "8081", "https", "8080");
Map<String, Integer> portsData = Map.of("http", 8081, "https", 8080);
KubernetesDiscoveryProperties.Metadata metadata = new KubernetesDiscoveryProperties.Metadata(addLabels,
labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix);
@@ -502,7 +502,7 @@ class DiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = KubernetesDiscoveryProperties.DEFAULT;
LinkedHashMap<String, Integer> endpointsPorts = new LinkedHashMap<>();
endpointsPorts.put(null, 8080);
endpointsPorts.put("not-null", 8080);
endpointsPorts.put("not-http-or-https", 8081);
Map<String, String> serviceLabels = Map.of();
@@ -511,7 +511,7 @@ class DiscoveryClientUtilsTests {
ServicePortNameAndNumber portData = endpointsPort(endpointsPorts, serviceMetadata, properties);
Assertions.assertEquals(portData.portNumber(), 8080);
Assertions.assertNull(portData.portName());
Assertions.assertEquals(portData.portName(), "not-null");
Assertions.assertTrue(output.getOut().contains(
"did not find a primary-port-name in neither properties nor service labels for service with ID : spring-k8s"));
Assertions.assertTrue(output.getOut()

View File

@@ -17,7 +17,6 @@
package org.springframework.cloud.kubernetes.fabric8.discovery;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -48,9 +47,9 @@ import org.springframework.cloud.kubernetes.commons.discovery.ServiceMetadata;
import org.springframework.cloud.kubernetes.fabric8.Fabric8Utils;
import org.springframework.core.log.LogAccessor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryConstants.UNSET_PORT_NAME;
import static org.springframework.util.StringUtils.hasText;
/**
* @author wind57
@@ -193,22 +192,14 @@ final class Fabric8KubernetesDiscoveryClientUtils {
return services;
}
static Map<String, String> portsData(List<EndpointSubset> endpointSubsets) {
/**
* a service is allowed to have a single port defined without a name.
*/
static Map<String, Integer> endpointSubsetsPortData(List<EndpointSubset> endpointSubsets) {
return endpointSubsets.stream().flatMap(endpointSubset -> endpointSubset.getPorts().stream())
.filter(port -> StringUtils.hasText(port.getName()))
.collect(Collectors.toMap(EndpointPort::getName, port -> Integer.toString(port.getPort())));
}
static LinkedHashMap<String, Integer> endpointSubsetPortsData(EndpointSubset endpointSubset) {
LinkedHashMap<String, Integer> result = new LinkedHashMap<>();
endpointSubset.getPorts().forEach(port -> {
// a service is allowed to not set a port name for a single entry.
// two ports without name can not be deployed, as this in an error
String portName = StringUtils.hasText(port.getName()) ? port.getName() : UNSET_PORT_NAME;
Integer portNumber = port.getPort();
result.put(portName, portNumber);
});
return result;
.collect(Collectors.toMap(
endpointPort -> hasText(endpointPort.getName()) ? endpointPort.getName() : UNSET_PORT_NAME,
EndpointPort::getPort));
}
static ServiceMetadata serviceMetadata(Service service) {

View File

@@ -17,7 +17,6 @@
package org.springframework.cloud.kubernetes.fabric8.discovery;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -48,9 +47,8 @@ import static org.springframework.cloud.kubernetes.commons.discovery.KubernetesD
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8InstanceIdHostPodNameSupplier.externalName;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8InstanceIdHostPodNameSupplier.nonExternalName;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.addresses;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSubsetPortsData;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSubsetsPortData;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpoints;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.portsData;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.serviceMetadata;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.services;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8PodLabelsAndAnnotationsSupplier.externalName;
@@ -163,13 +161,13 @@ public class KubernetesDiscoveryClient implements DiscoveryClient, EnvironmentAw
Service service = client.services().inNamespace(namespace).withName(serviceId).get();
ServiceMetadata serviceMetadata = serviceMetadata(service);
Map<String, String> portsData = portsData(subsets);
Map<String, Integer> portsData = endpointSubsetsPortData(subsets);
Map<String, String> serviceInstanceMetadata = serviceInstanceMetadata(portsData, serviceMetadata, properties);
for (EndpointSubset endpointSubset : subsets) {
LinkedHashMap<String, Integer> endpointsPortData = endpointSubsetPortsData(endpointSubset);
Map<String, Integer> endpointsPortData = endpointSubsetsPortData(List.of(endpointSubset));
ServicePortNameAndNumber portData = endpointsPort(endpointsPortData, serviceMetadata, properties);
List<EndpointAddress> addresses = addresses(endpointSubset, properties);

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2013-2023 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.fabric8.discovery;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.fabric8.kubernetes.api.model.EndpointAddressBuilder;
import io.fabric8.kubernetes.api.model.EndpointPortBuilder;
import io.fabric8.kubernetes.api.model.EndpointSubsetBuilder;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsBuilder;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
import io.fabric8.kubernetes.api.model.ServiceSpecBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
/**
* @author wind57
*/
@EnableKubernetesMockClient(crud = true, https = false)
class Fabric8KubernetesDiscoveryClientServiceWithoutPortNameTests {
private static final String NAMESPACE = "spring-k8s";
private static KubernetesClient mockClient;
@Test
void testDiscoveryWithoutAServicePortName() {
Service service = new ServiceBuilder()
.withSpec(new ServiceSpecBuilder().withPorts(new ServicePortBuilder().withPort(8080).build()).build())
.withMetadata(new ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.withSpec(new ServiceSpecBuilder().withType("ClusterIP").build()).build();
mockClient.services().inNamespace(NAMESPACE).resource(service).create();
Endpoints endpoints = new EndpointsBuilder()
.withSubsets(new EndpointSubsetBuilder().withPorts(new EndpointPortBuilder().withPort(8080).build())
.withAddresses(new EndpointAddressBuilder().withIp("127.0.0.1").build()).build())
.withMetadata(new ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.build();
mockClient.endpoints().inNamespace(NAMESPACE).resource(endpoints).create();
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(NAMESPACE),
true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0,
true);
KubernetesDiscoveryClient discoveryClient = new KubernetesDiscoveryClient(mockClient, properties, a -> null);
List<ServiceInstance> serviceInstances = discoveryClient.getInstances("no-port-name-service");
Assertions.assertEquals(serviceInstances.size(), 1);
Assertions.assertEquals(serviceInstances.get(0).getMetadata(),
Map.of("port.<unset>", "8080", "k8s_namespace", "spring-k8s", "type", "ClusterIP"));
}
}

View File

@@ -447,21 +447,20 @@ class Fabric8KubernetesDiscoveryClientTest {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint3");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).filteredOn(s -> 443 == s.getPort())
.hasSize(1);
.filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).hasSize(1);
}
@Test
void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameWithoutFallbackShouldLogWarning() {
Map<String, String> labels = Map.of();
Endpoints endPoint1 = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test")
Endpoints endPoint = new EndpointsBuilder().withNewMetadata().withName("endpoint4").withNamespace("test")
.withLabels(labels).endMetadata().addNewSubset().addNewAddress().withIp("ip1").withNewTargetRef()
.withUid("100").endTargetRef().endAddress().addNewPort("http", "https1", 443, "TCP")
.addNewPort("http", "https2", 8443, "TCP").addNewPort("http", "http1", 80, "TCP")
.addNewPort("http", "http2", 8080, "TCP").endSubset().build();
mockClient.endpoints().inNamespace("test").resource(endPoint1).create();
mockClient.endpoints().inNamespace("test").resource(endPoint).create();
Service service = new ServiceBuilder().withSpec(new ServiceSpecBuilder().withType("ExternalName").build())
.withNewMetadata().withName("endpoint4").withNamespace("test").withLabels(labels)
@@ -478,8 +477,7 @@ class Fabric8KubernetesDiscoveryClientTest {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint4");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).filteredOn(s -> 443 == s.getPort())
.hasSize(1);
.filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).hasSize(1);
}
@Test

View File

@@ -576,7 +576,8 @@ class Fabric8KubernetesDiscoveryClientTests {
Assertions.assertEquals(serviceInstance.getPort(), 8080);
Assertions.assertFalse(serviceInstance.isSecure());
Assertions.assertEquals(serviceInstance.getUri().toASCIIString(), "http://127.0.0.1:8080");
Assertions.assertEquals(serviceInstance.getMetadata(), Map.of("k8s_namespace", "a", "type", "ClusterIP"));
Assertions.assertEquals(serviceInstance.getMetadata(),
Map.of("k8s_namespace", "a", "type", "ClusterIP", "ports-prefix<unset>", "8080"));
Assertions.assertEquals(serviceInstance.podMetadata().get("labels"), Map.of("a", "b"));
Assertions.assertEquals(serviceInstance.podMetadata().get("annotations"), Map.of("c", "d"));
}

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.kubernetes.fabric8.discovery;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -37,7 +36,7 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
import org.springframework.mock.env.MockEnvironment;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSubsetPortsData;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.endpointSubsetsPortData;
import static org.springframework.cloud.kubernetes.fabric8.discovery.Fabric8KubernetesDiscoveryClientUtils.services;
/**
@@ -293,9 +292,10 @@ class Fabric8KubernetesDiscoveryClientUtilsTests {
new EndpointSubsetBuilder()
.withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build());
Map<String, String> portsData = Fabric8KubernetesDiscoveryClientUtils.portsData(endpointSubsets);
Assertions.assertEquals(portsData.size(), 1);
Assertions.assertEquals(portsData.get("https"), "8080");
Map<String, Integer> portsData = Fabric8KubernetesDiscoveryClientUtils.endpointSubsetsPortData(endpointSubsets);
Assertions.assertEquals(portsData.size(), 2);
Assertions.assertEquals(portsData.get("https"), 8080);
Assertions.assertEquals(portsData.get("<unset>"), 8081);
}
@Test
@@ -306,16 +306,16 @@ class Fabric8KubernetesDiscoveryClientUtilsTests {
new EndpointSubsetBuilder()
.withPorts(new EndpointPortBuilder().withPort(8080).withName("https").build()).build());
Map<String, String> portsData = Fabric8KubernetesDiscoveryClientUtils.portsData(endpointSubsets);
Map<String, Integer> portsData = Fabric8KubernetesDiscoveryClientUtils.endpointSubsetsPortData(endpointSubsets);
Assertions.assertEquals(portsData.size(), 2);
Assertions.assertEquals(portsData.get("https"), "8080");
Assertions.assertEquals(portsData.get("http"), "8081");
Assertions.assertEquals(portsData.get("https"), 8080);
Assertions.assertEquals(portsData.get("http"), 8081);
}
@Test
void endpointSubsetPortsDataWithoutPorts() {
EndpointSubset endpointSubset = new EndpointSubsetBuilder().build();
LinkedHashMap<String, Integer> result = endpointSubsetPortsData(endpointSubset);
Map<String, Integer> result = endpointSubsetsPortData(List.of(endpointSubset));
Assertions.assertEquals(result.size(), 0);
}
@@ -324,7 +324,7 @@ class Fabric8KubernetesDiscoveryClientUtilsTests {
void endpointSubsetPortsDataSinglePort() {
EndpointSubset endpointSubset = new EndpointSubsetBuilder()
.withPorts(new EndpointPortBuilder().withName("name").withPort(80).build()).build();
LinkedHashMap<String, Integer> result = endpointSubsetPortsData(endpointSubset);
Map<String, Integer> result = endpointSubsetsPortData(List.of(endpointSubset));
Assertions.assertEquals(result.size(), 1);
Assertions.assertEquals(result.get("name"), 80);
@@ -334,7 +334,7 @@ class Fabric8KubernetesDiscoveryClientUtilsTests {
void endpointSubsetPortsDataSinglePortNoName() {
EndpointSubset endpointSubset = new EndpointSubsetBuilder()
.withPorts(new EndpointPortBuilder().withPort(80).build()).build();
LinkedHashMap<String, Integer> result = endpointSubsetPortsData(endpointSubset);
Map<String, Integer> result = endpointSubsetsPortData(List.of(endpointSubset));
Assertions.assertEquals(result.size(), 1);
Assertions.assertEquals(result.get("<unset>"), 80);

View File

@@ -193,7 +193,7 @@ class KubernetesDiscoveryClientFilterMetadataTest {
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
assertThat(instances).hasSize(1);
assertThat(instances.get(0).getMetadata()).containsOnly(entry("http", "80"), entry("k8s_namespace", "test"),
entry("type", "ClusterIP"));
entry("<unset>", "5555"), entry("type", "ClusterIP"));
}
@Test
@@ -213,7 +213,7 @@ class KubernetesDiscoveryClientFilterMetadataTest {
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
assertThat(instances).hasSize(1);
assertThat(instances.get(0).getMetadata()).containsOnly(entry("p_http", "80"), entry("k8s_namespace", "ns"),
entry("type", "ClusterIP"));
entry("p_<unset>", "5555"), entry("type", "ClusterIP"));
}
@Test
@@ -233,7 +233,8 @@ class KubernetesDiscoveryClientFilterMetadataTest {
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
assertThat(instances).hasSize(1);
assertThat(instances.get(0).getMetadata()).containsOnly(entry("a_a1", "an1"), entry("a_a2", "an2"),
entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns"), entry("type", "ClusterIP"));
entry("l_l1", "la1"), entry("p_http", "80"), entry("k8s_namespace", "ns"), entry("type", "ClusterIP"),
entry("p_<unset>", "5555"));
}
private void setupServiceWithLabelsAndAnnotationsAndPorts(String serviceId, String namespace,