@Override public String getContainerIp(String containerName) { Pod pod = client.pods().withName(containerName).get(); if (pod != null) { String podIP = pod.getStatus().getPodIP(); logger.debug(String.format("Pod %s, IP -> %s", containerName, podIP)); return podIP; } else { return null; } }
@Override public void contribute(Builder builder) { try { Pod current = utils.currentPod().get(); Map<String, Object> 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); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = 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); } } }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { try { Pod current = 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); } } }
@Override public Set<String> discoverMembers() { LOGGER.debug("CELLAR KUBERNETES: query pods with labeled with [{}={}]", kubernetesPodLabelKey, kubernetesPodLabelValue); Set<String> members = new HashSet<String>(); try { PodList podList = kubernetesClient.pods().list(); for (Pod pod : podList.getItems()) { String value = pod.getMetadata().getLabels().get(kubernetesPodLabelKey); if (value != null && !value.isEmpty() && value.equals(kubernetesPodLabelValue)) { members.add(pod.getStatus().getPodIP()); } } } catch (Exception e) { LOGGER.error("CELLAR KUBERNETES: can't get pods", e); } return members; }
private Node getNodeFromPod(Pod pod) { Map<String,String> labels = pod.getMetadata().getLabels(); PodStatus status = pod.getStatus(); Node node = new Node(labels.remove(Protocol.HOST_NAME),status.getPodIP()); node.getProperties().putAll(labels); return node; }
@Override public Boolean call() { PodList result = client.pods().inNamespace(namespace).withLabels(metadata).list(); return result.getItems().size() >= 1 && result.getItems().get(0).getStatus().getPodIP() != null; }
@Override public Boolean call() { Pod result = client.pods().inNamespace(namespace).withName(name).get(); return result != null && result.getStatus().getPodIP() != null; }
/*** * Returns pod ip * @param namespace * @param podName * @return string ip */ public String getPodIp(String namespace, String podName) { return client.pods().inNamespace(namespace).withName(podName).get().getStatus().getPodIP(); }
private SimpleDiscoveryNode getSimpleDiscoveryNode(Pod pod) { Map<String, Object> properties = pod.getAdditionalProperties(); String ip = pod.getStatus().getPodIP(); if (ip != null) { InetAddress inetAddress = extractAddress(ip); int port = getServicePort(properties); getLogger().info("Resolved node: " +"port: " + port + " inetAddress: " + inetAddress.toString() + " ip:" + ip + " properties: " + properties); Address address = new Address(inetAddress, port); return new SimpleDiscoveryNode(address, properties); } else { return null; } }
long getQueueMessageCount(String queue, String clusterId) throws Exception { long totalMessageCount = 0; for (Pod broker : kubernetes.listBrokers(clusterId)) { if (Readiness.isPodReady(broker)) { try (SyncRequestClient brokerClient = brokerClientFactory.connectBrokerManagementClient(broker.getStatus().getPodIP(), 5673)) { Artemis artemis = new Artemis(brokerClient); totalMessageCount += artemis.getQueueMessageCount(queue); } } } return totalMessageCount; } }
public Pod(io.fabric8.kubernetes.api.model.Pod pod) { this.name = pod.getMetadata().getName(); if (pod.getMetadata().getAnnotations() != null) { this.annotations.putAll(pod.getMetadata().getAnnotations()); } this.kind = pod.getKind(); this.host = pod.getStatus().getPodIP(); this.phase = pod.getStatus().getPhase(); this.ready = getReadyCondition(pod.getStatus().getConditions()); this.portMap = getPortMap(pod.getSpec().getContainers()); }
public PodStatusBuilder( PodStatusFluent<?> fluent , PodStatus instance ){ this.fluent = fluent; fluent.withConditions(instance.getConditions()); fluent.withContainerStatuses(instance.getContainerStatuses()); fluent.withHostIP(instance.getHostIP()); fluent.withMessage(instance.getMessage()); fluent.withPhase(instance.getPhase()); fluent.withPodIP(instance.getPodIP()); fluent.withStartTime(instance.getStartTime()); } public PodStatusBuilder( PodStatus instance ){
public PodStatusBuilder( PodStatusFluent<?> fluent , PodStatus instance ){ this.fluent = fluent; fluent.withCondition(instance.getCondition()); fluent.withContainerStatuses(instance.getContainerStatuses()); fluent.withHostIP(instance.getHostIP()); fluent.withMessage(instance.getMessage()); fluent.withPhase(instance.getPhase()); fluent.withPodIP(instance.getPodIP()); fluent.withStartTime(instance.getStartTime()); } public PodStatusBuilder( PodStatus instance ){
public PodStatusBuilder( PodStatus instance ){ this.fluent = this; this.withConditions(instance.getConditions()); this.withContainerStatuses(instance.getContainerStatuses()); this.withHostIP(instance.getHostIP()); this.withMessage(instance.getMessage()); this.withPhase(instance.getPhase()); this.withPodIP(instance.getPodIP()); this.withStartTime(instance.getStartTime()); }
public PodStatusBuilder( PodStatus instance ){ this.fluent = this; this.withCondition(instance.getCondition()); this.withContainerStatuses(instance.getContainerStatuses()); this.withHostIP(instance.getHostIP()); this.withMessage(instance.getMessage()); this.withPhase(instance.getPhase()); this.withPodIP(instance.getPodIP()); this.withStartTime(instance.getStartTime()); }
public PodStatusFluentImpl(PodStatus instance){ this.withConditions(instance.getConditions()); this.withContainerStatuses(instance.getContainerStatuses()); this.withHostIP(instance.getHostIP()); this.withMessage(instance.getMessage()); this.withPhase(instance.getPhase()); this.withPodIP(instance.getPodIP()); this.withReason(instance.getReason()); this.withStartTime(instance.getStartTime()); }
public PodStatusBuilder(PodStatus instance,Boolean validationEnabled){ this.fluent = this; this.withConditions(instance.getConditions()); this.withContainerStatuses(instance.getContainerStatuses()); this.withHostIP(instance.getHostIP()); this.withMessage(instance.getMessage()); this.withPhase(instance.getPhase()); this.withPodIP(instance.getPodIP()); this.withReason(instance.getReason()); this.withStartTime(instance.getStartTime()); this.validationEnabled = validationEnabled; }
public PodStatusBuilder(PodStatusFluent<?> fluent,PodStatus instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withConditions(instance.getConditions()); fluent.withContainerStatuses(instance.getContainerStatuses()); fluent.withHostIP(instance.getHostIP()); fluent.withMessage(instance.getMessage()); fluent.withPhase(instance.getPhase()); fluent.withPodIP(instance.getPodIP()); fluent.withReason(instance.getReason()); fluent.withStartTime(instance.getStartTime()); this.validationEnabled = validationEnabled; } public PodStatusBuilder(PodStatus instance){