All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.actuate.kubernetes.KubernetesInfoContributor Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.actuate.kubernetes;

import java.util.HashMap;
import java.util.Map;

import io.fabric8.kubernetes.api.model.Pod;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.info.Info.Builder;
import org.zodic.kubernetes.base.support.PodOperations;
import org.springframework.boot.actuate.info.InfoContributor;

public class KubernetesInfoContributor implements InfoContributor {

    private static final Logger LOG = LoggerFactory.getLogger(KubernetesInfoContributor.class);

    private PodOperations podOperations;

    public KubernetesInfoContributor(PodOperations podOperations) {
        this.podOperations = podOperations;
    }

    @Override
    public void contribute(Builder builder) {
        try {
            Pod current = this.podOperations.currentPod().get();
            Map details = new HashMap<>();
            if (current != null) {
                details.put("inside", true);
                details.put("namespace", current.getMetadata().getNamespace());
                details.put("podName", current.getMetadata().getName());
                details.put("podIp", current.getStatus().getPodIP());
                details.put("serviceAccount", current.getSpec().getServiceAccountName());
                details.put("nodeName", current.getSpec().getNodeName());
                details.put("hostIp", current.getStatus().getHostIP());
            } else {
                details.put("inside", false);
            }
            builder.withDetail("kubernetes", details);
        } catch (Exception e) {
            LOG.warn("Failed to get pod details", e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy