minor things to clean-up (#748)
This commit is contained in:
@@ -19,7 +19,10 @@ package org.springframework.cloud.kubernetes.fabric8;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.PodSpec;
|
||||
import io.fabric8.kubernetes.api.model.PodStatus;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.cloud.kubernetes.commons.AbstractKubernetesHealthIndicator;
|
||||
@@ -46,13 +49,20 @@ public class Fabric8HealthIndicator extends AbstractKubernetesHealthIndicator {
|
||||
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());
|
||||
|
||||
ObjectMeta metadata = current.getMetadata();
|
||||
details.put(NAMESPACE, metadata.getNamespace());
|
||||
details.put(POD_NAME, metadata.getName());
|
||||
details.put(LABELS, metadata.getLabels());
|
||||
|
||||
PodStatus status = current.getStatus();
|
||||
details.put(POD_IP, status.getPodIP());
|
||||
details.put(HOST_IP, status.getHostIP());
|
||||
|
||||
PodSpec spec = current.getSpec();
|
||||
details.put(SERVICE_ACCOUNT, spec.getServiceAccountName());
|
||||
details.put(NODE_NAME, spec.getNodeName());
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ package org.springframework.cloud.kubernetes.fabric8;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.PodSpec;
|
||||
import io.fabric8.kubernetes.api.model.PodStatus;
|
||||
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.cloud.kubernetes.commons.AbstractKubernetesInfoContributor;
|
||||
@@ -46,12 +49,19 @@ public class Fabric8InfoContributor extends AbstractKubernetesInfoContributor {
|
||||
if (current != null) {
|
||||
Map<String, Object> details = CollectionUtils.newHashMap(7);
|
||||
details.put(INSIDE, true);
|
||||
details.put(NAMESPACE, current.getMetadata().getNamespace());
|
||||
details.put(POD_NAME, current.getMetadata().getName());
|
||||
details.put(POD_IP, current.getStatus().getPodIP());
|
||||
details.put(SERVICE_ACCOUNT, current.getSpec().getServiceAccountName());
|
||||
details.put(NODE_NAME, current.getSpec().getNodeName());
|
||||
details.put(HOST_IP, current.getStatus().getHostIP());
|
||||
|
||||
ObjectMeta metadata = current.getMetadata();
|
||||
details.put(NAMESPACE, metadata.getNamespace());
|
||||
details.put(POD_NAME, metadata.getName());
|
||||
|
||||
PodStatus status = current.getStatus();
|
||||
details.put(POD_IP, status.getPodIP());
|
||||
details.put(HOST_IP, status.getHostIP());
|
||||
|
||||
PodSpec spec = current.getSpec();
|
||||
details.put(SERVICE_ACCOUNT, spec.getServiceAccountName());
|
||||
details.put(NODE_NAME, spec.getNodeName());
|
||||
|
||||
return details;
|
||||
}
|
||||
return Collections.singletonMap(INSIDE, false);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.kubernetes.commons.EnvReader;
|
||||
import org.springframework.cloud.kubernetes.commons.LazilyInstantiate;
|
||||
import org.springframework.cloud.kubernetes.commons.PodUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility class to work with pods.
|
||||
@@ -91,11 +92,11 @@ public class Fabric8PodUtils implements PodUtils<Pod> {
|
||||
}
|
||||
|
||||
private boolean isServiceHostEnvVarPresent() {
|
||||
return this.serviceHost != null && !this.serviceHost.isEmpty();
|
||||
return StringUtils.hasLength(serviceHost);
|
||||
}
|
||||
|
||||
private boolean isHostNameEnvVarPresent() {
|
||||
return this.hostName != null && !this.hostName.isEmpty();
|
||||
return StringUtils.hasLength(hostName);
|
||||
}
|
||||
|
||||
private boolean isServiceAccountFound() {
|
||||
|
||||
@@ -24,13 +24,11 @@ import org.springframework.core.env.Environment;
|
||||
|
||||
public class Fabric8ProfileEnvironmentPostProcessor extends AbstractKubernetesProfileEnvironmentPostProcessor {
|
||||
|
||||
protected static final String KUBERNETES_SERVICE_ENV_VAR = "KUBERNETES_SERVICE_HOST";
|
||||
|
||||
@Override
|
||||
protected boolean isInsideKubernetes(Environment environment) {
|
||||
try (DefaultKubernetesClient client = new DefaultKubernetesClient()) {
|
||||
final Fabric8PodUtils podUtils = new Fabric8PodUtils(client);
|
||||
return environment.containsProperty(KUBERNETES_SERVICE_ENV_VAR) || podUtils.isInsideKubernetes();
|
||||
Fabric8PodUtils podUtils = new Fabric8PodUtils(client);
|
||||
return environment.containsProperty(Fabric8PodUtils.KUBERNETES_SERVICE_HOST) || podUtils.isInsideKubernetes();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user