Przeglądaj źródła

Broken: Working over revision section for expanded job

jnfrati 4 lat temu
rodzic
commit
6f5141d805

+ 78 - 29
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedJobChart.tsx

@@ -6,7 +6,7 @@ import backArrow from "assets/back_arrow.png";
 import _ from "lodash";
 import _ from "lodash";
 import loading from "assets/loading.gif";
 import loading from "assets/loading.gif";
 
 
-import { ChartType, ClusterType, StorageType } from "shared/types";
+import { ChartType, ClusterType } from "shared/types";
 import { Context } from "shared/Context";
 import { Context } from "shared/Context";
 import api from "shared/api";
 import api from "shared/api";
 
 
@@ -23,8 +23,8 @@ import Modal from "main/home/modals/Modal";
 import UpgradeChartModal from "main/home/modals/UpgradeChartModal";
 import UpgradeChartModal from "main/home/modals/UpgradeChartModal";
 import { pushFiltered } from "../../../../shared/routing";
 import { pushFiltered } from "../../../../shared/routing";
 import { RouteComponentProps, withRouter } from "react-router";
 import { RouteComponentProps, withRouter } from "react-router";
-import Banner from "components/Banner";
 import KeyValueArray from "components/form-components/KeyValueArray";
 import KeyValueArray from "components/form-components/KeyValueArray";
+import RevisionSection from "./RevisionSection";
 
 
 type PropsType = WithAuthProps &
 type PropsType = WithAuthProps &
   RouteComponentProps & {
   RouteComponentProps & {
@@ -53,6 +53,7 @@ type StateType = {
   upgradeVersion: string;
   upgradeVersion: string;
   expandedJobRun: any;
   expandedJobRun: any;
   pods: any;
   pods: any;
+  forceRefreshRevisions: boolean;
 };
 };
 
 
 class ExpandedJobChart extends Component<PropsType, StateType> {
 class ExpandedJobChart extends Component<PropsType, StateType> {
@@ -75,6 +76,7 @@ class ExpandedJobChart extends Component<PropsType, StateType> {
 
 
     expandedJobRun: null as any,
     expandedJobRun: null as any,
     pods: null as any,
     pods: null as any,
+    forceRefreshRevisions: false,
   };
   };
 
 
   getPods = (job: any, callback?: () => void) => {
   getPods = (job: any, callback?: () => void) => {
@@ -486,6 +488,50 @@ class ExpandedJobChart extends Component<PropsType, StateType> {
     });
     });
   };
   };
 
 
+  // getChartStatus = () => {
+  //   const { currentChart } = this.state;
+
+  //   const getAvailability = (kind: string, c: any) => {
+  //     switch (kind?.toLowerCase()) {
+  //       case "deployment":
+  //       case "replicaset":
+  //         return c.status.availableReplicas == c.status.replicas;
+  //       case "statefulset":
+  //         return c.status.readyReplicas == c.status.replicas;
+  //       case "daemonset":
+  //         return c.status.numberAvailable == c.status.desiredNumberScheduled;
+  //     }
+  //   };
+
+  //   const chartStatus = currentChart.info.status;
+
+  //   if (chartStatus === "deployed") {
+  //     for (var uid in controllers) {
+  //       let value = controllers[uid];
+  //       let available = getAvailability(value.metadata.kind, value);
+  //       let progressing = true;
+
+  //       controllers[uid]?.status?.conditions?.forEach((condition: any) => {
+  //         if (
+  //           condition.type == "Progressing" &&
+  //           condition.status == "False" &&
+  //           condition.reason == "ProgressDeadlineExceeded"
+  //         ) {
+  //           progressing = false;
+  //         }
+  //       });
+
+  //       if (!available && progressing) {
+  //         return "loading";
+  //       } else if (!available && !progressing) {
+  //         return "failed";
+  //       }
+  //     }
+  //     return "deployed";
+  //   }
+  //   return chartStatus;
+  // };
+
   renderTabContents = (currentTab: string, submitValues?: any) => {
   renderTabContents = (currentTab: string, submitValues?: any) => {
     switch (currentTab) {
     switch (currentTab) {
       case "jobs":
       case "jobs":
@@ -517,6 +563,16 @@ class ExpandedJobChart extends Component<PropsType, StateType> {
               isAuthorized={this.props.isAuthorized}
               isAuthorized={this.props.isAuthorized}
               saveValuesStatus={this.state.saveValuesStatus}
               saveValuesStatus={this.state.saveValuesStatus}
               expandJob={(job: any) => this.setJobRun(job)}
               expandJob={(job: any) => this.setJobRun(job)}
+              isDeployedFromGithub={
+                !!this.state.currentChart?.git_action_config?.git_repo
+              }
+              repositoryUrl={
+                this.state.currentChart?.git_action_config?.git_repo
+              }
+              currentChartVersion={Number(this.state.currentChart.version)}
+              latestChartVersion={Number(
+                this.state.currentChart.latest_version
+              )}
             />
             />
           </TabWrapper>
           </TabWrapper>
         );
         );
@@ -693,9 +749,6 @@ class ExpandedJobChart extends Component<PropsType, StateType> {
     let { closeChart } = this.props;
     let { closeChart } = this.props;
     let { currentChart } = this.state;
     let { currentChart } = this.state;
     let chart = currentChart;
     let chart = currentChart;
-    const displayUpdateButton =
-      chart.latest_version &&
-      chart.latest_version !== chart.chart.metadata.version;
     return (
     return (
       <>
       <>
         {this.state.upgradeVersion && (
         {this.state.upgradeVersion && (
@@ -741,30 +794,26 @@ class ExpandedJobChart extends Component<PropsType, StateType> {
                 {" " + this.readableDate(chart.info.last_deployed)}
                 {" " + this.readableDate(chart.info.last_deployed)}
               </LastDeployed>
               </LastDeployed>
             </InfoWrapper>
             </InfoWrapper>
-            {displayUpdateButton && (
-              <>
-                <Br />
-                <Banner>
-                  A template update is available.
-                  <Link
-                    onClick={(e) => {
-                      e.stopPropagation();
-                      this.setState({
-                        upgradeVersion: currentChart.latest_version,
-                      });
-                    }}
-                  >
-                    View upgrade notes
-                  </Link>
-                </Banner>
-                <Br />
-                <Br />
-                <Br />
-                <Br />
-                <Br />
-                <Br />
-              </>
-            )}
+            <RevisionSection
+              chart={this.state.currentChart}
+              refreshChart={() => this.getChartData(this.state.currentChart, 0)}
+              setRevision={() => {}}
+              forceRefreshRevisions={false}
+              refreshRevisionsOff={() => {}}
+              status={""}
+              shouldUpdate={
+                this.state.currentChart.latest_version &&
+                this.state.currentChart.latest_version !==
+                  this.state.currentChart.chart.metadata.version
+              }
+              latestVersion={this.state.currentChart.latest_version}
+              upgradeVersion={() => {
+                this.handleUpgradeVersion(this.state.upgradeVersion, () => {
+                  this.setState({ loading: false });
+                });
+                this.setState({ upgradeVersion: "", loading: true });
+              }}
+            />
           </HeaderWrapper>
           </HeaderWrapper>
 
 
           {this.state.deleting ? (
           {this.state.deleting ? (

+ 15 - 5
dashboard/src/main/home/cluster-dashboard/expanded-chart/RevisionSection.tsx

@@ -13,8 +13,6 @@ import Modal from "main/home/modals/Modal";
 import UpgradeChartModal from "main/home/modals/UpgradeChartModal";
 import UpgradeChartModal from "main/home/modals/UpgradeChartModal";
 
 
 type PropsType = WithAuthProps & {
 type PropsType = WithAuthProps & {
-  showRevisions: boolean;
-  toggleShowRevisions: () => void;
   chart: ChartType;
   chart: ChartType;
   refreshChart: () => void;
   refreshChart: () => void;
   setRevision: (x: ChartType, isCurrent?: boolean) => void;
   setRevision: (x: ChartType, isCurrent?: boolean) => void;
@@ -24,6 +22,8 @@ type PropsType = WithAuthProps & {
   shouldUpdate: boolean;
   shouldUpdate: boolean;
   upgradeVersion: (version: string, cb: () => void) => void;
   upgradeVersion: (version: string, cb: () => void) => void;
   latestVersion: string;
   latestVersion: string;
+  showRevisions?: boolean;
+  toggleShowRevisions?: () => void;
 };
 };
 
 
 type StateType = {
 type StateType = {
@@ -32,6 +32,7 @@ type StateType = {
   upgradeVersion: string;
   upgradeVersion: string;
   loading: boolean;
   loading: boolean;
   maxVersion: number;
   maxVersion: number;
+  expandRevisions: boolean;
 };
 };
 
 
 // TODO: handle refresh when new revision is generated from an old revision
 // TODO: handle refresh when new revision is generated from an old revision
@@ -42,6 +43,7 @@ class RevisionSection extends Component<PropsType, StateType> {
     upgradeVersion: "",
     upgradeVersion: "",
     loading: false,
     loading: false,
     maxVersion: 0, // Track most recent version even when previewing old revisions
     maxVersion: 0, // Track most recent version even when previewing old revisions
+    expandRevisions: false,
   };
   };
 
 
   refreshHistory = () => {
   refreshHistory = () => {
@@ -272,7 +274,7 @@ class RevisionSection extends Component<PropsType, StateType> {
   };
   };
 
 
   renderExpanded = () => {
   renderExpanded = () => {
-    if (this.props.showRevisions) {
+    if (this.state.expandRevisions) {
       return (
       return (
         <TableWrapper>
         <TableWrapper>
           <RevisionsTable>
           <RevisionsTable>
@@ -333,7 +335,15 @@ class RevisionSection extends Component<PropsType, StateType> {
         <RevisionHeader
         <RevisionHeader
           showRevisions={this.props.showRevisions}
           showRevisions={this.props.showRevisions}
           isCurrent={isCurrent}
           isCurrent={isCurrent}
-          onClick={this.props.toggleShowRevisions}
+          onClick={() => {
+            if (typeof this.props.toggleShowRevisions === "function") {
+              this.props.toggleShowRevisions();
+            }
+            this.setState((prev) => ({
+              ...prev,
+              expandRevisions: !prev.expandRevisions,
+            }));
+          }}
         >
         >
           <RevisionPreview>
           <RevisionPreview>
             {isCurrent
             {isCurrent
@@ -363,7 +373,7 @@ class RevisionSection extends Component<PropsType, StateType> {
 
 
   render() {
   render() {
     return (
     return (
-      <StyledRevisionSection showRevisions={this.props.showRevisions}>
+      <StyledRevisionSection showRevisions={this.state.expandRevisions}>
         {this.renderContents()}
         {this.renderContents()}
         <ConfirmOverlay
         <ConfirmOverlay
           show={this.state.rollbackRevision && true}
           show={this.state.rollbackRevision && true}

+ 8 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/JobList.tsx

@@ -11,6 +11,10 @@ type PropsType = WithAuthProps & {
   jobs: any[];
   jobs: any[];
   setJobs: (job: any) => void;
   setJobs: (job: any) => void;
   expandJob: any;
   expandJob: any;
+  currentChartVersion: number;
+  latestChartVersion: number;
+  isDeployedFromGithub: boolean;
+  repositoryUrl?: string;
 };
 };
 
 
 type StateType = {
 type StateType = {
@@ -62,6 +66,10 @@ class JobList extends Component<PropsType, StateType> {
                     "delete",
                     "delete",
                   ])
                   ])
                 }
                 }
+                isDeployedFromGithub={this.props.isDeployedFromGithub}
+                repositoryUrl={this.props.repositoryUrl}
+                currentChartVersion={this.props.currentChartVersion}
+                latestChartVersion={this.props.latestChartVersion}
               />
               />
             );
             );
           })}
           })}

+ 75 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/JobResource.tsx

@@ -8,6 +8,7 @@ import Logs from "../status/Logs";
 import plus from "assets/plus.svg";
 import plus from "assets/plus.svg";
 import closeRounded from "assets/close-rounded.png";
 import closeRounded from "assets/close-rounded.png";
 import KeyValueArray from "components/form-components/KeyValueArray";
 import KeyValueArray from "components/form-components/KeyValueArray";
+import DynamicLink from "components/DynamicLink";
 
 
 type PropsType = {
 type PropsType = {
   job: any;
   job: any;
@@ -15,6 +16,10 @@ type PropsType = {
   deleting: boolean;
   deleting: boolean;
   readOnly?: boolean;
   readOnly?: boolean;
   expandJob: any;
   expandJob: any;
+  currentChartVersion: number;
+  latestChartVersion: number;
+  isDeployedFromGithub: boolean;
+  repositoryUrl?: string;
 };
 };
 
 
 type StateType = {
 type StateType = {
@@ -261,6 +266,40 @@ export default class JobResource extends Component<PropsType, StateType> {
     }
     }
   };
   };
 
 
+  getImageTag = () => {
+    const container = this.props.job?.spec?.template?.spec?.containers[0];
+    const tag = container?.image?.split(":")[1];
+
+    if (!tag) {
+      return "unknown";
+    }
+
+    if (this.props.isDeployedFromGithub && tag !== "latest") {
+      return (
+        <DynamicLink
+          to={`https://github.com/${this.props.repositoryUrl}/commit/${tag}`}
+          onClick={(e) => e.preventDefault()}
+          target="_blank"
+        ></DynamicLink>
+      );
+    }
+
+    return tag;
+  };
+
+  getRevisionNumber = () => {
+    const revision = this.props.job?.metadata?.labels["helm.sh/revision"];
+    let status: RevisionContainerProps["status"] = "current";
+    if (this.props.currentChartVersion > revision) {
+      status = "outdated";
+    }
+    return (
+      <RevisionContainer status={status}>
+        Revision No - {revision || "unknown"}
+      </RevisionContainer>
+    );
+  };
+
   render() {
   render() {
     let icon =
     let icon =
       "https://user-images.githubusercontent.com/65516095/111258413-4e2c3800-85f3-11eb-8a6a-88e03460f8fe.png";
       "https://user-images.githubusercontent.com/65516095/111258413-4e2c3800-85f3-11eb-8a6a-88e03460f8fe.png";
@@ -278,12 +317,23 @@ export default class JobResource extends Component<PropsType, StateType> {
                 <Label>
                 <Label>
                   Started at{" "}
                   Started at{" "}
                   {this.readableDate(this.props.job.status?.startTime)}
                   {this.readableDate(this.props.job.status?.startTime)}
+                  <Dot>•</Dot>
+                  <span>
+                    {this.props.isDeployedFromGithub
+                      ? "Commit: "
+                      : "Image tag:"}{" "}
+                    {this.getImageTag()}
+                  </span>
                 </Label>
                 </Label>
                 <Subtitle>{this.getSubtitle()}</Subtitle>
                 <Subtitle>{this.getSubtitle()}</Subtitle>
               </Description>
               </Description>
             </Flex>
             </Flex>
             <EndWrapper>
             <EndWrapper>
-              <CommandString>{commandString}</CommandString>
+              <Flex>
+                {this.getRevisionNumber()}
+                <CommandString>{commandString}</CommandString>
+              </Flex>
+
               {this.renderStatus()}
               {this.renderStatus()}
               <MaterialIconTray disabled={false}>
               <MaterialIconTray disabled={false}>
                 {this.renderStopButton()}
                 {this.renderStopButton()}
@@ -316,6 +366,26 @@ export default class JobResource extends Component<PropsType, StateType> {
 
 
 JobResource.contextType = Context;
 JobResource.contextType = Context;
 
 
+type RevisionContainerProps = {
+  status: "outdated" | "current";
+};
+
+const RevisionContainer = styled.span<RevisionContainerProps>`
+  margin-right: 15px;
+  ${({ status }) => {
+    if (status === "outdated") {
+      return "color: rgb(245, 203, 66);";
+    }
+    return "";
+  }}
+`;
+
+const Dot = styled.div`
+  margin-right: 9px;
+  margin-left: 9px;
+  color: #ffffff88;
+`;
+
 const Row = styled.div`
 const Row = styled.div`
   margin-top: 20px;
   margin-top: 20px;
 `;
 `;
@@ -464,6 +534,10 @@ const Label = styled.div`
   color: #ffffff;
   color: #ffffff;
   font-size: 13px;
   font-size: 13px;
   font-weight: 500;
   font-weight: 500;
+  display: flex;
+  > span {
+    color: #ffffff88;
+  }
 `;
 `;
 
 
 const Subtitle = styled.div`
 const Subtitle = styled.div`

+ 8 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/jobs/TempJobList.tsx

@@ -12,6 +12,10 @@ interface Props {
   jobs: any;
   jobs: any;
   handleSaveValues: any;
   handleSaveValues: any;
   expandJob: any;
   expandJob: any;
+  currentChartVersion: number;
+  latestChartVersion: number;
+  isDeployedFromGithub: boolean;
+  repositoryUrl?: string;
 }
 }
 
 
 /**
 /**
@@ -50,6 +54,10 @@ const TempJobList: React.FC<Props> = (props) => {
         jobs={props.jobs}
         jobs={props.jobs}
         setJobs={props.setJobs}
         setJobs={props.setJobs}
         expandJob={props.expandJob}
         expandJob={props.expandJob}
+        isDeployedFromGithub={props.isDeployedFromGithub}
+        repositoryUrl={props.repositoryUrl}
+        currentChartVersion={props.currentChartVersion}
+        latestChartVersion={props.latestChartVersion}
       />
       />
     </>
     </>
   );
   );

+ 0 - 3
dashboard/src/main/home/modals/UpgradeChartModal.tsx

@@ -84,9 +84,6 @@ ${note.note}
   render() {
   render() {
     return (
     return (
       <StyledUpgradeChartModal>
       <StyledUpgradeChartModal>
-        <CloseButton onClick={this.props.closeModal}>
-          <CloseButtonImg src={close} />
-        </CloseButton>
         {this.renderContent()}
         {this.renderContent()}
         <SaveButton
         <SaveButton
           disabled={false}
           disabled={false}