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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to leave this on. I sometimes see a deprecation and don't really know where it comes from

<arg>-Xlint:deprecation</arg>
</compilerArgs>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.springframework.cloud.kubernetes.client.default_api;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.Collections;

import io.kubernetes.client.openapi.ApiClient;
Expand Down Expand Up @@ -53,7 +53,7 @@ void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
assertThat(apiClient).isNotNull();
Request.Builder builder = new Request.Builder();
apiClient.processHeaderParams(Collections.emptyMap(), builder);
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
assertThat(builder.url(URI.create("http://example.com").toURL()).build().headers().get("User-Agent"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

java-20 deprecated the constructor we are using here

.isEqualTo("Spring-Cloud-Kubernetes-Application");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.springframework.cloud.kubernetes.client.default_api;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.Collections;

import io.kubernetes.client.openapi.ApiClient;
Expand Down Expand Up @@ -57,7 +57,7 @@ void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
assertThat(apiClient).isNotNull();
Request.Builder builder = new Request.Builder();
apiClient.processHeaderParams(Collections.emptyMap(), builder);
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
assertThat(builder.url(URI.create("http://example.com").toURL()).build().headers().get("User-Agent"))
.isEqualTo("non-default");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import io.kubernetes.client.informer.cache.Cache;
import io.kubernetes.client.informer.cache.Lister;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.CoreV1EndpointPort;
import io.kubernetes.client.openapi.models.CoreV1EndpointPortBuilder;
Expand All @@ -34,6 +35,7 @@
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -50,14 +52,14 @@
*/
class KubernetesClientDiscoveryClientFilterMetadataTest {

private static final CoreV1Api CORE_V1_API = Mockito.mock(CoreV1Api.class);

private static final SharedInformerFactoryStub STUB = new SharedInformerFactoryStub();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

STUB does not have a default constructor anymore (to get away from a deprecation), so this code needs a bit of refactor


private static final SharedInformerStub<V1Service> SERVICE_SHARED_INFORMER_STUB = new SharedInformerStub<>();

private static final SharedInformerStub<V1Endpoints> ENDPOINTS_SHARED_INFORMER_STUB = new SharedInformerStub<>();

private static CoreV1Api coreV1Api;

private static SharedInformerFactoryStub sharedInformerFactoryStub;

private Cache<V1Service> servicesCache;

private Lister<V1Service> servicesLister;
Expand All @@ -66,6 +68,15 @@ class KubernetesClientDiscoveryClientFilterMetadataTest {

private Lister<V1Endpoints> endpointsLister;

@BeforeAll
static void beforeAll() {
coreV1Api = Mockito.mock(CoreV1Api.class);
ApiClient apiClient = Mockito.mock(ApiClient.class);
Mockito.when(coreV1Api.getApiClient()).thenReturn(apiClient);

sharedInformerFactoryStub = new SharedInformerFactoryStub(apiClient);
}

@BeforeEach
void beforeEach() {
servicesCache = new Cache<>();
Expand All @@ -85,8 +96,9 @@ void testAllExtraMetadataDisabled() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "lab"), Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));

Expand All @@ -105,8 +117,9 @@ void testLabelsEnabled() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));

Expand All @@ -126,8 +139,9 @@ void testLabelsEnabledWithPrefix() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "v1", "l2", "v2"), Map.of("l1", "lab"), Map.of(80, "http", 5555, ""));

Expand All @@ -147,8 +161,9 @@ void testAnnotationsEnabled() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));

Expand All @@ -168,8 +183,9 @@ void testAnnotationsEnabledWithPrefix() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));

Expand All @@ -189,8 +205,9 @@ void testPortsEnabled() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "test", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));

Expand All @@ -210,8 +227,9 @@ void testPortsEnabledWithPrefix() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "v1"), Map.of("a1", "v1", "a2", "v2"), Map.of(80, "http", 5555, ""));

Expand All @@ -231,8 +249,9 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() {
false, null, Set.of(), Map.of(), null, metadata, 0, true, false, null);

KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

setup(serviceId, "ns", Map.of("l1", "la1"), Map.of("a1", "an1", "a2", "an2"), Map.of(80, "http", 5555, ""));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import io.kubernetes.client.informer.cache.Cache;
import io.kubernetes.client.informer.cache.Lister;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.CoreV1EndpointPortBuilder;
import io.kubernetes.client.openapi.models.V1EndpointAddressBuilder;
Expand All @@ -34,6 +35,7 @@
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -46,15 +48,15 @@
*/
class KubernetesClientDiscoveryClientServiceWithoutPortNameTests {

private static final CoreV1Api CORE_V1_API = Mockito.mock(CoreV1Api.class);
private static final SharedInformerStub<V1Service> SERVICE_SHARED_INFORMER_STUB = new SharedInformerStub<>();

private static final String NAMESPACE = "spring-k8s";
private static final SharedInformerStub<V1Endpoints> ENDPOINTS_SHARED_INFORMER_STUB = new SharedInformerStub<>();

private static final SharedInformerFactoryStub STUB = new SharedInformerFactoryStub();
private static CoreV1Api coreV1Api;

private static final SharedInformerStub<V1Service> SERVICE_SHARED_INFORMER_STUB = new SharedInformerStub<>();
private static SharedInformerFactoryStub sharedInformerFactoryStub;

private static final SharedInformerStub<V1Endpoints> ENDPOINTS_SHARED_INFORMER_STUB = new SharedInformerStub<>();
private static final String NAMESPACE = "spring-k8s";

private Cache<V1Service> servicesCache;

Expand All @@ -64,6 +66,15 @@ class KubernetesClientDiscoveryClientServiceWithoutPortNameTests {

private Lister<V1Endpoints> endpointsLister;

@BeforeAll
static void beforeAll() {
coreV1Api = Mockito.mock(CoreV1Api.class);
ApiClient apiClient = Mockito.mock(ApiClient.class);
Mockito.when(coreV1Api.getApiClient()).thenReturn(apiClient);

sharedInformerFactoryStub = new SharedInformerFactoryStub(apiClient);
}

@BeforeEach
void beforeEach() {
servicesCache = new Cache<>();
Expand Down Expand Up @@ -95,8 +106,9 @@ void testDiscoveryWithoutAServicePortName() {
true, 60, false, null, Set.of(), Map.of(), null, KubernetesDiscoveryProperties.Metadata.DEFAULT, 0,
true, false, null);
KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient(
List.of(STUB), List.of(servicesLister), List.of(endpointsLister), List.of(SERVICE_SHARED_INFORMER_STUB),
List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, CORE_V1_API, x -> true);
List.of(sharedInformerFactoryStub), List.of(servicesLister), List.of(endpointsLister),
List.of(SERVICE_SHARED_INFORMER_STUB), List.of(ENDPOINTS_SHARED_INFORMER_STUB), properties, coreV1Api,
x -> true);

List<ServiceInstance> serviceInstances = discoveryClient.getInstances("no-port-name-service");
Assertions.assertThat(serviceInstances.size()).isEqualTo(1);
Expand Down
Loading
Loading