github.com/argoproj/argo-cd@v1.8.7/ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx (about)

     1  import {LogsViewer} from 'argo-ui';
     2  import * as React from 'react';
     3  
     4  import * as models from '../../../shared/models';
     5  import {services} from '../../../shared/services';
     6  
     7  export const PodsLogsViewer = (props: {applicationName: string; pod: models.ResourceNode & any; containerIndex: number}) => {
     8      const containers = (props.pod.spec.initContainers || []).concat(props.pod.spec.containers || []);
     9      const container = containers[props.containerIndex];
    10      if (!container) {
    11          return <div>Pod does not have container with index {props.containerIndex}</div>;
    12      }
    13      const containerStatuses = ((props.pod.status && props.pod.status.containerStatuses) || []).concat((props.pod.status && props.pod.status.initContainerStatuses) || []);
    14      const containerStatus = containerStatuses.find((status: any) => status.name === container.name);
    15      const isRunning = !!(containerStatus && containerStatus.state && containerStatus && containerStatus.state.running);
    16      return (
    17          <div style={{height: '100%'}}>
    18              <LogsViewer
    19                  source={{
    20                      key: `${props.pod.metadata.name}:${container.name}`,
    21                      loadLogs: () =>
    22                          services.applications
    23                              .getContainerLogs(props.applicationName, props.pod.metadata.namespace, props.pod.metadata.name, container.name)
    24                              .map(item => item.content + '\n'),
    25                      shouldRepeat: () => isRunning
    26                  }}
    27              />
    28          </div>
    29      );
    30  };