public PodContainerStatus getPodStatus()

in karavan-app/src/main/java/org/apache/camel/karavan/kubernetes/PodEventHandler.java [106:168]


    public PodContainerStatus getPodStatus(Pod pod) {
        String appName = pod.getMetadata().getLabels().get("app");
        String projectId = pod.getMetadata().getLabels().get(LABEL_PROJECT_ID);
        String camel = pod.getMetadata().getLabels().get(LABEL_KUBERNETES_RUNTIME);
        String runtime = pod.getMetadata().getLabels().get(LABEL_CAMEL_RUNTIME);
        String type = pod.getMetadata().getLabels().get(LABEL_TYPE);
        String commit = pod.getMetadata().getAnnotations().get(ANNOTATION_COMMIT);
        if (appName != null) {
            Deployment deployment = kubernetesStatusService.getDeployment(appName);
             projectId = deployment.getMetadata().getName();
             camel = deployment.getMetadata().getLabels().get(LABEL_KUBERNETES_RUNTIME);
             runtime = deployment.getMetadata().getLabels().get(LABEL_CAMEL_RUNTIME);
             type = deployment.getMetadata().getLabels().get(LABEL_TYPE);
             commit = deployment.getMetadata().getAnnotations().get(ANNOTATION_COMMIT);
        }
        ContainerType containerType = type != null ? ContainerType.valueOf(type) : ContainerType.unknown;
        try {
            boolean ready = pod.getStatus().getConditions().stream().anyMatch(c -> c.getType().equals("Ready") && c.getStatus().equals("True"));
            boolean running = Objects.equals(pod.getStatus().getPhase(), "Running");
            boolean failed = Objects.equals(pod.getStatus().getPhase(), "Failed");
            boolean succeeded = Objects.equals(pod.getStatus().getPhase(), "Succeeded");
            String creationTimestamp = pod.getMetadata().getCreationTimestamp();

            ResourceRequirements defaultRR = kubernetesStatusService.getResourceRequirements(DEFAULT_CONTAINER_RESOURCES);
            ResourceRequirements resourceRequirements = pod.getSpec().getContainers().stream().findFirst()
                    .orElse(new ContainerBuilder().withResources(defaultRR).build()).getResources();

            String requestMemory = resourceRequirements.getRequests().getOrDefault("memory", new Quantity()).toString();
            String requestCpu = resourceRequirements.getRequests().getOrDefault("cpu", new Quantity()).toString();
            String limitMemory = resourceRequirements.getLimits().getOrDefault("memory", new Quantity()).toString();
            String limitCpu = resourceRequirements.getLimits().getOrDefault("cpu", new Quantity()).toString();
            PodContainerStatus status = new PodContainerStatus(
                    pod.getMetadata().getName(),
                    List.of(PodContainerStatus.Command.delete),
                    projectId,
                    kubernetesStatusService.getEnvironment(),
                    containerType,
                    requestMemory + " / " + limitMemory,
                    requestCpu + " / " + limitCpu,
                    creationTimestamp);
            status.setLabels(pod.getMetadata().getLabels());
            status.setImage(pod.getSpec().getContainers().get(0).getImage());
            status.setCommit(commit);
            status.setContainerId(pod.getMetadata().getName());
            status.setPhase(pod.getStatus().getPhase());
            status.setPodIP(pod.getStatus().getPodIP());
            status.setCamelRuntime(runtime != null ? runtime : (camel != null ? CamelRuntime.CAMEL_MAIN.getValue() : ""));
            if (running) {
                status.setState(PodContainerStatus.State.running.name());
            } else if (failed) {
                status.setState(PodContainerStatus.State.dead.name());
            } else if (succeeded) {
                status.setState(PodContainerStatus.State.exited.name());
            } else {
                status.setState(PodContainerStatus.State.created.name());
            }
            return status;
        } catch (Exception ex) {
            ex.printStackTrace();
            LOGGER.error(ex.getMessage(), ex.getCause());
            return null;
        }
    }