#37: Document how to make the namespace available to the pod. Add warning to the logs if namespace is unknown. Expose namespace through the pod health indiciator.
This commit is contained in:
@@ -20,6 +20,8 @@ import io.fabric8.kubernetes.client.Config;
|
||||
import io.fabric8.kubernetes.client.ConfigBuilder;
|
||||
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -32,6 +34,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableConfigurationProperties(KubernetesClientProperties.class)
|
||||
public class KubernetesAutoConfiguration {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(KubernetesClientProperties.class);
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(Config.class)
|
||||
public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) {
|
||||
@@ -62,6 +66,9 @@ public class KubernetesAutoConfiguration {
|
||||
.withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts()))
|
||||
.build();
|
||||
|
||||
if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) {
|
||||
LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)");
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ public class KubernetesHealthIndicator extends AbstractHealthIndicator {
|
||||
if (current != null) {
|
||||
builder.up()
|
||||
.withDetail("inside", true)
|
||||
.withDetail("namespace", current.getMetadata().getNamespace())
|
||||
.withDetail("podName", current.getMetadata().getName())
|
||||
.withDetail("podIp", current.getStatus().getPodIP())
|
||||
.withDetail("serviceAccount", current.getSpec().getServiceAccountName())
|
||||
|
||||
Reference in New Issue
Block a user