Просмотр исходного кода

show pod status when job is still running or pending

Alexander Belanger 3 лет назад
Родитель
Сommit
f6474b4f5a

+ 61 - 2
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/ExpandedJobRun.tsx

@@ -16,6 +16,8 @@ import Logs from "../status/Logs";
 import { useRouting } from "shared/routing";
 import LogsSection from "../logs-section/LogsSection";
 import EventsTab from "../events/EventsTab";
+import { getPodStatus } from "../deploy-status-section/util";
+import { capitalize } from "shared/string_utils";
 
 const readableDate = (s: string) => {
   let ts = new Date(s);
@@ -50,15 +52,70 @@ const getLatestPod = (pods: any[]) => {
     .shift();
 };
 
-const renderStatus = (job: any, time: string) => {
+export const isRunning = (deleting: boolean, job: any, pod: any) => {
+  if (deleting) {
+    return false;
+  }
+
   if (job.status?.succeeded >= 1) {
-    return <Status color="#38a88a">Succeeded {time}</Status>;
+    return false;
+  }
+
+  if (job.status?.conditions) {
+    if (job.status?.conditions[0]?.reason == "DeadlineExceeded") {
+      return false;
+    }
+  }
+
+  if (job.status?.failed >= 1) {
+    return false;
+  }
+
+  if (job.status?.active >= 1) {
+    // determine the status from the pod
+    return pod ? pod.status.startTime : false;
+  }
+
+  return true;
+};
+
+export const renderStatus = (
+  deleting: boolean,
+  job: any,
+  pod: any,
+  time?: string
+) => {
+  if (deleting) {
+    return <Status color="#cc3d42">Deleting</Status>;
+  }
+
+  if (job.status?.succeeded >= 1) {
+    if (time) {
+      return <Status color="#38a88a">Succeeded at {readableDate(time)}</Status>;
+    }
+
+    return <Status color="#38a88a">Succeeded</Status>;
+  }
+
+  if (job.status?.conditions) {
+    if (job.status?.conditions[0]?.reason == "DeadlineExceeded") {
+      return <Status color="#cc3d42">Timed Out</Status>;
+    }
   }
 
   if (job.status?.failed >= 1) {
     return <Status color="#cc3d42">Failed</Status>;
   }
 
+  if (job.status?.active >= 1) {
+    // determine the status from the pod
+    return pod ? (
+      <Status color="#ffffff11">{capitalize(getPodStatus(pod?.status))}</Status>
+    ) : (
+      <Status color="#ffffff11">Running</Status>
+    );
+  }
+
   return <Status color="#ffffff11">Running</Status>;
 };
 
@@ -256,7 +313,9 @@ const ExpandedJobRun = ({
         <InfoWrapper>
           <LastDeployed>
             {renderStatus(
+              false,
               run,
+              pods[0],
               run.status.completionTime
                 ? readableDate(run.status.completionTime)
                 : ""

+ 27 - 26
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/JobResource.tsx

@@ -12,6 +12,8 @@ import DynamicLink from "components/DynamicLink";
 import { readableDate } from "shared/string_utils";
 import CommandLineIcon from "assets/command-line-icon";
 import ConnectToJobInstructionsModal from "./ConnectToJobInstructionsModal";
+import { getPodStatus } from "../deploy-status-section/util";
+import { isRunning, renderStatus } from "./ExpandedJobRun";
 
 type PropsType = {
   job: any;
@@ -40,6 +42,18 @@ export default class JobResource extends Component<PropsType, StateType> {
     showConnectionModal: false,
   };
 
+  componentDidMount() {
+    if (this.props.job?.status.active >= 1) {
+      this.getPods(() => {});
+    }
+  }
+
+  componentDidUpdate(prevProps: PropsType, prevState: StateType) {
+    if (this.state.pods.length == 0 && this.props.job?.status.active >= 1) {
+      this.getPods(() => {});
+    }
+  }
+
   expandJob = (event: MouseEvent) => {
     if (event) {
       event.stopPropagation();
@@ -244,37 +258,20 @@ export default class JobResource extends Component<PropsType, StateType> {
     return "Running";
   };
 
-  renderStatus = () => {
-    if (this.props.deleting) {
-      return <Status color="#cc3d42">Deleting</Status>;
-    }
-
-    if (this.props.job.status?.succeeded >= 1) {
-      return <Status color="#38a88a">Succeeded</Status>;
-    }
-
-    if (this.props.job.status?.failed >= 1) {
-      return <Status color="#cc3d42">Failed</Status>;
-    }
-
-    return <Status color="#ffffff11">Running</Status>;
-  };
-
   renderStopButton = () => {
     if (this.props.readOnly) {
       return null;
     }
 
-    if (!this.props.job.status?.succeeded && !this.props.job.status?.failed) {
-      // look for a sidecar container
-      if (this.props.job?.spec?.template?.spec?.containers.length == 2) {
-        return (
-          <i className="material-icons" onClick={this.stopJob}>
-            stop
-          </i>
-        );
-      }
+    if (isRunning(this.props.deleting, this.props.job, this.state.pods[0])) {
+      return (
+        <i className="material-icons" onClick={this.stopJob}>
+          stop
+        </i>
+      );
     }
+
+    return null;
   };
 
   getImageTag = () => {
@@ -346,7 +343,11 @@ export default class JobResource extends Component<PropsType, StateType> {
                 <CommandString>{commandString}</CommandString>
               </Flex>
 
-              {this.renderStatus()}
+              {renderStatus(
+                this.props.deleting,
+                this.props.job,
+                this.state.pods[0]
+              )}
               <MaterialIconTray disabled={false}>
                 {this.renderStopButton()}
                 {!this.props.readOnly && (