/*
 * Copyright 2013-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.kubernetes;

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

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;

/**
 * Kubernetes implementation of {@link AbstractHealthIndicator}.
 *
 * @author Ioannis Canellos
 */
public class KubernetesHealthIndicator extends AbstractHealthIndicator {

	private PodUtils utils;

	public KubernetesHealthIndicator(PodUtils utils) {
		this.utils = utils;
	}

	@Override
	protected void doHealthCheck(Health.Builder builder) throws Exception {
		try {
			Pod current = this.utils.currentPod().get();
			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())
						.withDetail("nodeName", current.getSpec().getNodeName())
						.withDetail("hostIp", current.getStatus().getHostIP());
			}
			else {
				builder.up().withDetail("inside", false);
			}
		}
		catch (Exception e) {
			builder.down(e);
		}
	}

}

@@ -936,16 +936,41 @@
 anellos%0A
+ * @author Edd%C3%BA Mel%C3%A9ndez%0A
  */%0Apubl
@@ -1753,16 +1753,79 @@
 ostIP())
+%0A%09%09%09%09%09%09.withDetail(%22labels%22, current.getMetadata().getLabels())
 ;%0A%09%09%09%7D%0A%09

Add labels to the health endpoint (#518)