Skip to content

Commit 2106050

Browse files
committed
2 parents f23671a + c0b7e4d commit 2106050

File tree

26 files changed

+266
-226
lines changed

26 files changed

+266
-226
lines changed

spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private V1Pod internalGetPod() {
104104
if (isServiceHostEnvVarPresent() && isHostNameEnvVarPresent() && isServiceAccountFound()) {
105105
LOG.debug("reading pod in namespace : " + namespace);
106106
// The hostname of your pod is typically also its name.
107-
return client.readNamespacedPod(hostName, namespace, null);
107+
return client.readNamespacedPod(hostName, namespace).execute();
108108
}
109109
}
110110
catch (Throwable t) {

spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/ActuatorEnabledFailFastExceptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void afterEach() {
6969
void test() throws ApiException {
7070
Health health = healthIndicator.health(true);
7171
Assertions.assertThat(Status.DOWN).isSameAs(health.getStatus());
72-
Mockito.verify(coreV1Api).readNamespacedPod("host", "my-namespace", null);
72+
Mockito.verify(coreV1Api).readNamespacedPod("host", "my-namespace");
7373
}
7474

7575
private static void mocks() {
@@ -103,7 +103,7 @@ KubernetesClientPodUtils kubernetesPodUtils() throws ApiException {
103103

104104
mocks();
105105

106-
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace", null))
106+
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace"))
107107
.thenThrow(new RuntimeException("just because"));
108108

109109
return new KubernetesClientPodUtils(coreV1Api, "my-namespace", FAIL_FAST);

spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/ActuatorEnabledNoFailFastExceptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void afterEach() {
7272
void test() throws ApiException {
7373
Health health = healthIndicator.health(true);
7474
Assertions.assertThat(Status.UP).isSameAs(health.getStatus());
75-
Mockito.verify(coreV1Api).readNamespacedPod("host", "my-namespace", null);
75+
Mockito.verify(coreV1Api).readNamespacedPod("host", "my-namespace");
7676
}
7777

7878
private static void mocks() {
@@ -106,7 +106,7 @@ KubernetesClientPodUtils kubernetesPodUtils() throws ApiException {
106106

107107
mocks();
108108

109-
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace", null))
109+
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace"))
110110
.thenThrow(new RuntimeException("just because"));
111111

112112
return new KubernetesClientPodUtils(coreV1Api, "my-namespace", FAIL_FAST);

spring-cloud-kubernetes-client-autoconfig/src/test/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtilsTests.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737
import static org.assertj.core.api.Assertions.assertThatThrownBy;
38+
import static org.mockito.Mockito.mock;
39+
import static org.mockito.Mockito.when;
3840

3941
/**
4042
* @author wind57
@@ -55,15 +57,15 @@ class KubernetesClientPodUtilsTests {
5557

5658
private static final V1Pod POD = new V1Pod();
5759

58-
private final CoreV1Api client = Mockito.mock(CoreV1Api.class);
60+
private final CoreV1Api client = mock(CoreV1Api.class);
5961

60-
private final Path tokenPath = Mockito.mock(Path.class);
62+
private final Path tokenPath = mock(Path.class);
6163

62-
private final File tokenFile = Mockito.mock(File.class);
64+
private final File tokenFile = mock(File.class);
6365

64-
private final Path certPath = Mockito.mock(Path.class);
66+
private final Path certPath = mock(Path.class);
6567

66-
private final File certFile = Mockito.mock(File.class);
68+
private final File certFile = mock(File.class);
6769

6870
private MockedStatic<EnvReader> envReader;
6971

@@ -156,19 +158,21 @@ private void mockHostname(String name) {
156158
}
157159

158160
private void mockTokenPath(boolean result) {
159-
Mockito.when(tokenPath.toFile()).thenReturn(tokenFile);
160-
Mockito.when(tokenFile.exists()).thenReturn(result);
161+
when(tokenPath.toFile()).thenReturn(tokenFile);
162+
when(tokenFile.exists()).thenReturn(result);
161163
paths.when(() -> Paths.get(SERVICE_ACCOUNT_TOKEN_PATH)).thenReturn(tokenPath);
162164
}
163165

164166
private void mockCertPath(boolean result) {
165-
Mockito.when(certPath.toFile()).thenReturn(certFile);
166-
Mockito.when(certFile.exists()).thenReturn(result);
167+
when(certPath.toFile()).thenReturn(certFile);
168+
when(certFile.exists()).thenReturn(result);
167169
paths.when(() -> Paths.get(SERVICE_ACCOUNT_CERT_PATH)).thenReturn(certPath);
168170
}
169171

170172
private void mockPodResult() throws ApiException {
171-
Mockito.when(client.readNamespacedPod(POD_HOSTNAME, "namespace", null)).thenReturn(POD);
173+
CoreV1Api.APIreadNamespacedPodRequest request = mock(CoreV1Api.APIreadNamespacedPodRequest.class);
174+
when(request.execute()).thenReturn(POD);
175+
when(client.readNamespacedPod(POD_HOSTNAME, "namespace")).thenReturn(request);
172176
}
173177

174178
}

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapsCache.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ static List<StrippedSourceContainer> byNamespace(CoreV1Api coreV1Api, String nam
5454
List<StrippedSourceContainer> result = CACHE.computeIfAbsent(namespace, x -> {
5555
try {
5656
b[0] = true;
57-
return strippedConfigMaps(coreV1Api
58-
.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null, null,
59-
null)
60-
.getItems());
57+
return strippedConfigMaps(coreV1Api.listNamespacedConfigMap(namespace).execute().getItems());
6158
}
6259
catch (ApiException apiException) {
6360
throw new RuntimeException(apiException.getResponseBody(), apiException);

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsCache.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ static List<StrippedSourceContainer> byNamespace(CoreV1Api coreV1Api, String nam
5757
List<StrippedSourceContainer> result = CACHE.computeIfAbsent(namespace, x -> {
5858
try {
5959
b[0] = true;
60-
return strippedSecrets(coreV1Api
61-
.listNamespacedSecret(namespace, null, null, null, null, null, null, null, null, null, null, null)
62-
.getItems());
60+
return strippedSecrets(coreV1Api.listNamespacedSecret(namespace).execute().getItems());
6361
}
6462
catch (ApiException apiException) {
6563
throw new RuntimeException(apiException.getResponseBody(), apiException);

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedConfigMapChangeDetector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ void inform() {
124124
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
125125
factories.add(factory);
126126
informer = factory
127-
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace,
128-
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
129-
params.timeoutSeconds, params.watch, null), V1ConfigMap.class, V1ConfigMapList.class);
127+
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMap(namespace)
128+
.timeoutSeconds(params.timeoutSeconds)
129+
.resourceVersion(params.resourceVersion)
130+
.watch(params.watch)
131+
.buildCall(null), V1ConfigMap.class, V1ConfigMapList.class);
130132

131133
LOG.debug(() -> "added configmap informer for namespace : " + namespace + " with filter : " + filter[0]);
132134

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ void inform() {
127127
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
128128
factories.add(factory);
129129
informer = factory
130-
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(namespace,
131-
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
132-
params.timeoutSeconds, params.watch, null), V1Secret.class, V1SecretList.class);
130+
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedSecret(namespace)
131+
.timeoutSeconds(params.timeoutSeconds)
132+
.resourceVersion(params.resourceVersion)
133+
.watch(params.watch)
134+
.buildCall(null), V1Secret.class, V1SecretList.class);
133135

134136
LOG.debug(() -> "added secret informer for namespace : " + namespace + " with filter : " + filter[0]);
135137

spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/K8sPodLabelsAndAnnotationsSupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public PodLabelsAndAnnotations apply(String podName) {
6565
V1ObjectMeta objectMeta;
6666

6767
try {
68-
objectMeta = Optional.ofNullable(coreV1Api.readNamespacedPod(podName, namespace, null).getMetadata())
68+
objectMeta = Optional.ofNullable(coreV1Api.readNamespacedPod(podName, namespace).execute().getMetadata())
6969
.orElse(new V1ObjectMetaBuilder().withLabels(Map.of()).withAnnotations(Map.of()).build());
7070
}
7171
catch (ApiException e) {

spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/catalog/KubernetesCatalogWatch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Function<KubernetesCatalogWatchContext, List<EndpointNameAndNamespace>> stateGen
101101
CustomObjectsApi customObjectsApi = new CustomObjectsApi(apiClient);
102102
try {
103103
List<V1APIResource> resources = customObjectsApi.getAPIResources(DISCOVERY_GROUP, DISCOVERY_VERSION)
104+
.execute()
104105
.getResources();
105106
boolean found = resources.stream().map(V1APIResource::getKind).anyMatch(ENDPOINT_SLICE::equals);
106107
if (!found) {

0 commit comments

Comments
 (0)