some polishing (#789)

This commit is contained in:
erabii
2021-05-18 16:58:21 -04:00
committed by GitHub
parent 6a5c2d924a
commit a14bf182a6
2 changed files with 19 additions and 9 deletions

View File

@@ -19,7 +19,10 @@ package org.springframework.cloud.kubernetes.client;
import java.util.Collections;
import java.util.Map;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodSpec;
import io.kubernetes.client.openapi.models.V1PodStatus;
import org.springframework.cloud.kubernetes.commons.AbstractKubernetesHealthIndicator;
import org.springframework.cloud.kubernetes.commons.PodUtils;
@@ -42,13 +45,20 @@ public class KubernetesClientHealthIndicator extends AbstractKubernetesHealthInd
if (current != null) {
Map<String, Object> details = CollectionUtils.newHashMap(8);
details.put(INSIDE, true);
details.put(NAMESPACE, current.getMetadata().getNamespace());
details.put(POD_NAME, current.getMetadata().getName());
details.put(LABELS, current.getMetadata().getLabels());
details.put(POD_IP, current.getStatus().getPodIP());
details.put(HOST_IP, current.getStatus().getHostIP());
details.put(SERVICE_ACCOUNT, current.getSpec().getServiceAccountName());
details.put(NODE_NAME, current.getSpec().getNodeName());
V1ObjectMeta meta = current.getMetadata();
details.put(NAMESPACE, meta.getNamespace());
details.put(POD_NAME, meta.getName());
details.put(LABELS, meta.getLabels());
V1PodStatus status = current.getStatus();
details.put(POD_IP, status.getPodIP());
details.put(HOST_IP, status.getHostIP());
V1PodSpec spec = current.getSpec();
details.put(SERVICE_ACCOUNT, spec.getServiceAccountName());
details.put(NODE_NAME, spec.getNodeName());
return details;
}
else {

View File

@@ -59,7 +59,7 @@ class KubernetesClientHealthIndicatorTests {
KubernetesClientHealthIndicator healthIndicator = new KubernetesClientHealthIndicator(utils);
Map<String, Object> details = healthIndicator.getDetails();
assertThat(details.containsKey(INSIDE)).isTrue();
assertThat(details.size()).isEqualTo(1);
assertThat(details.get(INSIDE)).isEqualTo(false);
}
@@ -70,7 +70,7 @@ class KubernetesClientHealthIndicatorTests {
KubernetesClientHealthIndicator healthIndicator = new KubernetesClientHealthIndicator(utils);
Map<String, Object> details = healthIndicator.getDetails();
assertThat(details.containsKey(INSIDE)).isTrue();
assertThat(details.size()).isEqualTo(8);
assertThat(details.get(INSIDE)).isEqualTo(true);
assertThat(details.get(HOST_IP)).isEqualTo(STUB_HOST_IP);