Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void testServiceWithUnsetPortNames() {
assertThat(discoveryClient.getInstances("test-svc-1").toArray())
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 80,
Map.of("port.<unset>", "80", "k8s_namespace", "namespace1", "type", "ClusterIP"), false,
"namespace1", null));
"namespace1", null, Map.of()));
}

@Test
Expand Down Expand Up @@ -161,7 +161,7 @@ void testDiscoveryInstancesWithServiceLabels() {
new DefaultKubernetesServiceInstance(
null, "test-svc-3", "2.2.2.2", 8080, Map.of("spring", "true", "port.<unset>", "8080", "k8s",
"true", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null));
false, "namespace1", null, Map.of()));
}

@Test
Expand Down Expand Up @@ -214,7 +214,7 @@ void testDiscoveryGetInstanceAllNamespaceShouldWork() {
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("port.<unset>", "8080", "k8s_namespace", "namespace1", "type", "ClusterIP"), false,
"namespace1", null));
"namespace1", null, Map.of()));
}

@Test
Expand All @@ -229,7 +229,7 @@ void testDiscoveryGetInstanceOneNamespaceShouldWork() {
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("port.<unset>", "8080", "k8s_namespace", "namespace1", "type", "ClusterIP"), false,
"namespace1", null));
"namespace1", null, Map.of()));
}

@Test
Expand Down Expand Up @@ -260,7 +260,7 @@ void testDiscoveryGetInstanceWithNotReadyAddressesIncludedShouldWork() {
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("port.<unset>", "8080", "k8s_namespace", "namespace1", "type", "ClusterIP"), false,
"namespace1", null));
"namespace1", null, Map.of()));
}

@Test
Expand All @@ -286,7 +286,7 @@ void instanceWithoutPortsWillNotBeSkipped() {

assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 0,
Map.of("k8s_namespace", "namespace1", "type", "ClusterIP"), false, "namespace1", null));
Map.of("k8s_namespace", "namespace1", "type", "ClusterIP"), false, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -298,10 +298,10 @@ void instanceWithMultiplePortsAndPrimaryPortNameConfiguredWithLabelShouldWork()
List.of(SHARED_INFORMER_FACTORY), List.of(serviceLister), List.of(endpointsLister), null, null,
NOT_ALL_NAMESPACES, CORE_V1_API, x -> true);

assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new DefaultKubernetesServiceInstance(
null, "test-svc-1", "1.1.1.1", 443, Map.of("port.http", "80", "primary-port-name", "https",
"port.https", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
true, "namespace1", null));
assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new DefaultKubernetesServiceInstance(null,
"test-svc-1", "1.1.1.1", 443, Map.of("port.http", "80", "primary-port-name", "https", "port.https",
"443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
true, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -314,11 +314,10 @@ void instanceWithMultiplePortsAndMisconfiguredPrimaryPortNameInLabelShouldReturn
List.of(SHARED_INFORMER_FACTORY), List.of(serviceLister), List.of(endpointsLister), null, null,
NOT_ALL_NAMESPACES, CORE_V1_API, x -> true);

assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(
null, "test-svc-1", "1.1.1.1", 80, Map.of("port.tcp1", "80", "primary-port-name", "oops",
"port.tcp2", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null));
assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(new DefaultKubernetesServiceInstance(
null, "test-svc-1", "1.1.1.1", 80, Map.of("port.tcp1", "80", "primary-port-name", "oops", "port.tcp2",
"443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -333,7 +332,7 @@ void instanceWithMultiplePortsAndGenericPrimaryPortNameConfiguredShouldWork() {
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 443,
Map.of("port.http", "80", "port.https", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
true, "namespace1", null));
true, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -349,7 +348,7 @@ void instanceWithMultiplePortsAndMisconfiguredGenericPrimaryPortNameShouldReturn
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 80,
Map.of("port.tcp1", "80", "port.tcp2", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null));
false, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -364,7 +363,7 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedShouldFallBackTo
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 443,
Map.of("port.http", "80", "port.https", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
true, "namespace1", null));
true, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -379,7 +378,7 @@ void instanceWithMultiplePortsAndWithoutPrimaryPortNameSpecifiedOrHttpsPortShoul
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 80,
Map.of("port.http", "80", "port.tcp", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null));
false, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -395,7 +394,7 @@ void instanceWithMultiplePortsAndWithoutAnyConfigurationShouldPickTheFirstPort()
assertThat(discoveryClient.getInstances("test-svc-1"))
.containsOnly(new DefaultKubernetesServiceInstance(null, "test-svc-1", "1.1.1.1", 80,
Map.of("port.tcp1", "80", "port.tcp2", "443", "k8s_namespace", "namespace1", "type", "ClusterIP"),
false, "namespace1", null));
false, "namespace1", null, Map.of()));
}

@Test
Expand All @@ -410,10 +409,10 @@ void getInstancesShouldReturnInstancesWithTheSameServiceIdFromNamespaces() {
assertThat(discoveryClient.getInstances("test-svc-1")).containsOnly(
new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("port.<unset>", "8080", "k8s_namespace", "namespace1", "type", "ClusterIP"), false,
"namespace1", null),
"namespace1", null, Map.of()),
new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("port.<unset>", "8080", "k8s_namespace", "namespace2", "type", "ClusterIP"), false,
"namespace2", null));
"namespace2", null, Map.of()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void testDiscoveryGetInstanceAllNamespaceShouldWork() {
StepVerifier.create(discoveryClient.getInstances("test-svc-1"))
.expectNext(new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("type", "ClusterIP", "port.<unset>", "8080", "k8s_namespace", "namespace1"), false,
"namespace1", null))
"namespace1", null, Map.of()))
.expectComplete()
.verify();

Expand All @@ -159,7 +159,7 @@ void testDiscoveryGetInstanceOneNamespaceShouldWork() {
StepVerifier.create(discoveryClient.getInstances("test-svc-1"))
.expectNext(new DefaultKubernetesServiceInstance(null, "test-svc-1", "2.2.2.2", 8080,
Map.of("type", "ClusterIP", "port.<unset>", "8080", "k8s_namespace", "namespace1"), false,
"namespace1", null))
"namespace1", null, Map.of()))
.expectComplete()
.verify();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public KubernetesServiceInstance map(V1Service service) {
boolean secure = secure(port, service);

return new DefaultKubernetesServiceInstance(metadata.getUid(), metadata.getName(), host, port.getPort(),
serviceMetadata(service), secure);
serviceMetadata(service), secure, null, null, Map.of());
}

private Map<String, String> serviceMetadata(V1Service service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void singlePortNonSecure() {
Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true", "k8s_namespace",
"default", "type", "V1Service");
DefaultKubernetesServiceInstance result = new DefaultKubernetesServiceInstance("0", "database",
"database.default.svc.cluster.local", 80, metadata, false);
"database.default.svc.cluster.local", 80, metadata, false, null, null, Map.of());
assertThat(serviceInstance).isEqualTo(result);
}

Expand All @@ -79,7 +79,7 @@ void singlePortSecure() {
Map<String, String> metadata = Map.of("org.springframework.cloud", "true", "beta", "true", "secured", "true",
"k8s_namespace", "default", "type", "V1Service");
DefaultKubernetesServiceInstance result = new DefaultKubernetesServiceInstance("0", "database",
"database.default.svc.cluster.local", 80, metadata, true);
"database.default.svc.cluster.local", 80, metadata, true, null, null, Map.of());
assertThat(serviceInstance).isEqualTo(result);
}

Expand All @@ -100,7 +100,7 @@ void multiplePortsSecure() {
"default", "type", "V1Service");
KubernetesServiceInstance serviceInstance = mapper.map(service);
DefaultKubernetesServiceInstance result = new DefaultKubernetesServiceInstance("0", "database",
"database.default.svc.cluster.local", 443, metadata, true);
"database.default.svc.cluster.local", 443, metadata, true, null, null, Map.of());
assertThat(serviceInstance).isEqualTo(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void singleNamespaceTest(CapturedOutput output) {
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);
"service-a.default.svc.cluster.local", 80, metadata, false, null, null, Map.of());
List<ServiceInstance> services = new ArrayList<>();
services.add(serviceA);

Expand Down Expand Up @@ -218,9 +218,10 @@ void allNamespacesTest(CapturedOutput output) {
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);
"service-a", "service-a.default.svc.cluster.local", 80, metadata, false, null, null, Map.of());
DefaultKubernetesServiceInstance serviceATestNamespace = new DefaultKubernetesServiceInstance("1", "service-a",
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false);
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false,
null, null, Map.of());
List<ServiceInstance> services = new ArrayList<>();
services.add(serviceADefaultNamespace);
services.add(serviceATestNamespace);
Expand Down Expand Up @@ -263,9 +264,10 @@ void selectiveNamespacesTest(CapturedOutput output) {
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);
"service-a", "service-a.default.svc.cluster.local", 80, metadata, false, null, null, Map.of());
DefaultKubernetesServiceInstance serviceATestNamespace = new DefaultKubernetesServiceInstance("1", "service-a",
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false);
"service-a.test.svc.cluster.local", 80, Map.of("k8s_namespace", "test", "type", "V1Service"), false,
null, null, Map.of());
List<ServiceInstance> services = new ArrayList<>();
services.add(serviceADefaultNamespace);
services.add(serviceATestNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ public record DefaultKubernetesServiceInstance(String instanceId, String service
Map<String, String> metadata, boolean secure, String namespace, String cluster,
Map<String, Map<String, String>> podMetadata) implements KubernetesServiceInstance {

/**
* @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 the connection needs to be secure.
*/
public DefaultKubernetesServiceInstance(String instanceId, String serviceId, String host, int port,
Copy link
Contributor Author

@wind57 wind57 Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropping these two constructors that were added only not to break compatibility, the rest is just tests changes

Map<String, String> metadata, boolean secure) {
this(instanceId, serviceId, host, port, metadata, secure, null, null, Map.of());
}

public DefaultKubernetesServiceInstance(String instanceId, String serviceId, String host, int port,
Map<String, String> metadata, boolean secure, String namespace, String cluster) {
this(instanceId, serviceId, host, port, metadata, secure, namespace, cluster, Map.of());
}

@Override
public String getInstanceId() {
return this.instanceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KubernetesServiceInstanceTests {
@Test
void testFirstConstructor() {
DefaultKubernetesServiceInstance instance = new DefaultKubernetesServiceInstance("instanceId", "serviceId",
"host", 8080, Map.of("k8s_namespace", "spring-k8s"), true);
"host", 8080, Map.of("k8s_namespace", "spring-k8s"), true, null, null, Map.of());

assertThat(instance.getInstanceId()).isEqualTo("instanceId");
assertThat(instance.getServiceId()).isEqualTo("serviceId");
Expand All @@ -50,7 +50,7 @@ void testFirstConstructor() {
@Test
void testSecondConstructor() {
DefaultKubernetesServiceInstance instance = new DefaultKubernetesServiceInstance("instanceId", "serviceId",
"host", 8080, Map.of("a", "b"), true, "spring-k8s", "cluster");
"host", 8080, Map.of("a", "b"), true, "spring-k8s", "cluster", Map.of());

assertThat(instance.getInstanceId()).isEqualTo("instanceId");
assertThat(instance.getServiceId()).isEqualTo("serviceId");
Expand Down Expand Up @@ -97,7 +97,7 @@ void schemeIsHttps() {

private DefaultKubernetesServiceInstance assertServiceInstance(boolean secure) {
DefaultKubernetesServiceInstance instance = new DefaultKubernetesServiceInstance("123", "myservice", "1.2.3.4",
8080, Collections.emptyMap(), secure);
8080, Collections.emptyMap(), secure, null, null, Map.of());

assertThat(instance.getInstanceId()).isEqualTo("123");
assertThat(instance.getServiceId()).isEqualTo("myservice");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ threadPoolTaskExecutor, new HttpRefreshTrigger(reactiveDiscoveryClient,
fooEndpointPort.setPort(port);
List<ServiceInstance> instances = new ArrayList<>();
DefaultKubernetesServiceInstance fooServiceInstance = new DefaultKubernetesServiceInstance("foo", "foo",
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false);
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false, null, null, Map.of());
instances.add(fooServiceInstance);
return instances;
}
Expand All @@ -240,7 +240,7 @@ private void stubReactiveCall() {

List<ServiceInstance> instances = new ArrayList<>();
DefaultKubernetesServiceInstance fooServiceInstance = new DefaultKubernetesServiceInstance("foo", "foo",
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false, null, null, Map.of());
instances.add(fooServiceInstance);
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void triggerSecretRefreshWithAnnotationActuatorPath(String endpoint, RefreshStra
fooEndpointPort.setPort(WIRE_MOCK_SERVER.port());
List<ServiceInstance> instances = new ArrayList<>();
DefaultKubernetesServiceInstance fooServiceInstance = new DefaultKubernetesServiceInstance("foo", "foo",
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false);
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false, null, null, Map.of());
instances.add(fooServiceInstance);
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
V1Secret secret = new V1Secret();
Expand All @@ -227,7 +227,7 @@ private void stubReactiveCall() {
fooEndpointPort.setPort(WIRE_MOCK_SERVER.port());
List<ServiceInstance> instances = new ArrayList<>();
DefaultKubernetesServiceInstance fooServiceInstance = new DefaultKubernetesServiceInstance("foo", "foo",
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false, null, null, Map.of());
instances.add(fooServiceInstance);
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@
class DiscoveryServerControllerTests {

private static final DefaultKubernetesServiceInstance SERVICE_A_INSTANCE_1 = new DefaultKubernetesServiceInstance(
"serviceAInstance1", "serviceAInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace1", null);
"serviceAInstance1", "serviceAInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace1", null, Map.of());

private static final DefaultKubernetesServiceInstance SERVICE_A_INSTANCE_2 = new DefaultKubernetesServiceInstance(
"serviceAInstance2", "serviceAInstance2", "2.2.2.2", 8080, Map.of(), false, "namespace1", null);
"serviceAInstance2", "serviceAInstance2", "2.2.2.2", 8080, Map.of(), false, "namespace1", null, Map.of());

private static final DefaultKubernetesServiceInstance SERVICE_A_INSTANCE_3 = new DefaultKubernetesServiceInstance(
"serviceAInstance3", "serviceAInstance3", "2.2.2.2", 8080, Map.of(), false, "namespace2", null);
"serviceAInstance3", "serviceAInstance3", "2.2.2.2", 8080, Map.of(), false, "namespace2", null, Map.of());

private static final DefaultKubernetesServiceInstance SERVICE_B_INSTANCE_1 = new DefaultKubernetesServiceInstance(
"serviceBInstance1", "serviceBInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace1", null);
"serviceBInstance1", "serviceBInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace1", null, Map.of());

private static final DefaultKubernetesServiceInstance SERVICE_C_INSTANCE_1 = new DefaultKubernetesServiceInstance(
"serviceCInstance1", "serviceCInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace2", null);
"serviceCInstance1", "serviceCInstance1", "2.2.2.2", 8080, Map.of(), false, "namespace2", null, Map.of());

private static Service serviceA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ void apps() {
TEST_SERVICE_A.getMetadata().getName(),
TEST_ENDPOINTS_A.getSubsets().get(0).getAddresses().get(0).getIp(),
TEST_ENDPOINTS_A.getSubsets().get(0).getPorts().get(0).getPort(), metadataA, false,
TEST_SERVICE_A.getMetadata().getNamespace(), null);
TEST_SERVICE_A.getMetadata().getNamespace(), null, Map.of());

DefaultKubernetesServiceInstance kubernetesServiceInstance2 = new DefaultKubernetesServiceInstance(
TEST_ENDPOINTS_B.getSubsets().get(0).getAddresses().get(0).getTargetRef().getUid(),
TEST_SERVICE_B.getMetadata().getName(),
TEST_ENDPOINTS_B.getSubsets().get(0).getAddresses().get(0).getIp(),
TEST_ENDPOINTS_B.getSubsets().get(0).getPorts().get(0).getPort(), metadataB, false,
TEST_SERVICE_B.getMetadata().getNamespace(), null);
TEST_SERVICE_B.getMetadata().getNamespace(), null, Map.of());

webTestClient.get()
.uri("/apps")
Expand Down
Loading
Loading