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

support chart upgrades for application charts

Alexander Belanger 5 лет назад
Родитель
Сommit
a616dc32ef

+ 1 - 1
dashboard/package.json

@@ -29,7 +29,7 @@
     "d3-array": "^2.11.0",
     "d3-time-format": "^3.0.0",
     "dotenv": "^8.2.0",
-    "highlight.run": "^1.4.3",
+    "highlight.run": "^1.4.5",
     "ini": ">=1.3.6",
     "js-base64": "^3.6.0",
     "js-yaml": "^3.14.0",

+ 2 - 2
dashboard/src/components/ConfirmOverlay.tsx

@@ -4,8 +4,8 @@ import styled from "styled-components";
 type PropsType = {
   message: string;
   show: boolean;
-  onYes: () => void;
-  onNo: () => void;
+  onYes: React.MouseEventHandler;
+  onNo: React.MouseEventHandler;
 };
 
 type StateType = {};

+ 4 - 2
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -286,7 +286,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
       });
   };
 
-  handleUpgradeVersion = (version: string) => {
+  handleUpgradeVersion = (version: string, cb: () => void) => {
     let { currentProject, currentCluster, setCurrentError } = this.context;
 
     // convert current values to yaml
@@ -324,10 +324,12 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
           chart: this.state.currentChart.name,
           values: valuesYaml,
         });
+
+        cb && cb()
       })
       .catch((err) => {
         console.log(err);
-        this.setState({ saveValuesStatus: "error" });
+        this.setState({ saveValuesStatus: "error", loading: false });
         window.analytics.track("Failed to Upgrade Chart", {
           chart: this.state.currentChart.name,
           values: valuesYaml,

+ 31 - 12
dashboard/src/main/home/cluster-dashboard/expanded-chart/RevisionSection.tsx

@@ -18,7 +18,7 @@ type PropsType = {
   refreshRevisionsOff: () => void;
   status: string;
   shouldUpdate: boolean;
-  upgradeVersion: (version: string) => void;
+  upgradeVersion: (version: string, cb : () => void) => void;
   latestVersion: string;
 };
 
@@ -222,11 +222,13 @@ export default class RevisionSection extends Component<PropsType, StateType> {
           isCurrent={isCurrent}
           onClick={this.props.toggleShowRevisions}
         >
-          {isCurrent
-            ? `Current Revision`
-            : `Previewing Revision (Not Deployed)`}{" "}
-          - <Revision>No. {this.props.chart.version}</Revision>
-          <i className="material-icons">arrow_drop_down</i>
+          <RevisionPreview>
+            {isCurrent
+              ? `Current Revision`
+              : `Previewing Revision (Not Deployed)`}{" "}
+            - <Revision>No. {this.props.chart.version}</Revision>
+            <i className="material-icons">arrow_drop_down</i>
+          </RevisionPreview>
           {
             this.props.shouldUpdate && <div><RevisionUpdateMessage
               onClick={(e) => {
@@ -240,8 +242,18 @@ export default class RevisionSection extends Component<PropsType, StateType> {
             <ConfirmOverlay
               show={!!this.state.upgradeVersion}
               message={`Are you sure you want to upgrade to version ${this.state.upgradeVersion}?`}
-              onYes={() => this.props.upgradeVersion(this.state.upgradeVersion)}
-              onNo={() => this.setState({ upgradeVersion: "" })}
+              onYes={(e) => {
+                e.stopPropagation()
+
+                this.props.upgradeVersion(this.state.upgradeVersion, () => {
+                  this.setState({ loading: false })
+                })
+                this.setState({ upgradeVersion: "", loading: true })
+              }}
+              onNo={(e) => {
+                e.stopPropagation()
+                this.setState({ upgradeVersion: "" })
+              }}
             /></div>
           }
         </RevisionHeader>
@@ -365,6 +377,7 @@ const RevisionHeader = styled.div`
   color: ${(props: { showRevisions: boolean; isCurrent: boolean }) =>
     props.isCurrent ? "#ffffff66" : "#f5cb42"};
   display: flex;
+  justify-content: space-between;
   align-items: center;
   height: 40px;
   font-size: 13px;
@@ -375,12 +388,12 @@ const RevisionHeader = styled.div`
     props.showRevisions ? "#ffffff11" : ""};
   :hover {
     background: #ffffff18;
-    > i {
+    > div > i {
       background: #ffffff22;
     }
   }
 
-  > i {
+  > div > i {
     margin-left: 12px;
     font-size: 20px;
     cursor: pointer;
@@ -413,14 +426,19 @@ const StyledRevisionSection = styled.div`
   }
 `;
 
+const RevisionPreview = styled.div`
+  display: flex;
+  max-width: 200px; 
+  align-items: center;
+`
+
 const RevisionUpdateMessage = styled.div`
-  position: absolute; 
-  right: 40px; 
   color: white;
   display: flex;
   align-items: center;
   padding: 4px 10px; 
   border-radius: 5px; 
+  margin-right: 10px; 
 
   :hover {
     border: 1px solid white;
@@ -432,5 +450,6 @@ const RevisionUpdateMessage = styled.div`
     font-size: 20px;
     cursor: pointer;
     border-radius: 20px;
+    transform: none;
   }
 `

+ 1 - 1
dashboard/src/main/home/launch/expanded-template/ExpandedTemplate.tsx

@@ -46,7 +46,7 @@ export default class ExpandedTemplate extends Component<PropsType, StateType> {
     let params =
       this.props.currentTab == "docker"
         ? { repo_url: process.env.APPLICATION_CHART_REPO_URL }
-        : {};
+        : { repo_url: process.env.ADDON_CHART_REPO_URL };
 
     api
       .getTemplateInfo("<token>", params, {

+ 59 - 56
server/api/deploy_handler.go

@@ -214,63 +214,66 @@ func (app *App) HandleUninstallTemplate(w http.ResponseWriter, r *http.Request)
 		}
 
 		release, err := app.Repo.Release.ReadRelease(uint(clusterID), name, resp.Release.Namespace)
-		gitAction := release.GitActionConfig
-
-		if release != nil && gitAction.ID != 0 {
-			// parse env into build env
-			cEnv := &ContainerEnvConfig{}
-			rawValues, err := yaml.Marshal(resp.Release.Config)
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"could not get values of previous revision"},
-				}, w)
-			}
-
-			yaml.Unmarshal(rawValues, cEnv)
-
-			gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"github repo integration not found"},
-				}, w)
-			}
-
-			repoSplit := strings.Split(gitAction.GitRepo, "/")
-
-			projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
-
-			if err != nil || projID == 0 {
-				app.handleErrorFormDecoding(err, ErrProjectDecode, w)
-				return
-			}
-
-			gaRunner := &actions.GithubActions{
-				GitIntegration: gr,
-				GitRepoName:    repoSplit[1],
-				GitRepoOwner:   repoSplit[0],
-				Repo:           *app.Repo,
-				GithubConf:     app.GithubProjectConf,
-				WebhookToken:   release.WebhookToken,
-				ProjectID:      uint(projID),
-				ReleaseName:    name,
-				GitBranch:      gitAction.GitBranch,
-				DockerFilePath: gitAction.DockerfilePath,
-				FolderPath:     gitAction.FolderPath,
-				ImageRepoURL:   gitAction.ImageRepoURI,
-				BuildEnv:       cEnv.Container.Env.Normal,
-			}
-
-			err = gaRunner.Cleanup()
 
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"could not remove github action"},
-				}, w)
+		if release != nil {
+			gitAction := release.GitActionConfig
+
+			if gitAction.ID != 0 {
+				// parse env into build env
+				cEnv := &ContainerEnvConfig{}
+				rawValues, err := yaml.Marshal(resp.Release.Config)
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"could not get values of previous revision"},
+					}, w)
+				}
+
+				yaml.Unmarshal(rawValues, cEnv)
+
+				gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"github repo integration not found"},
+					}, w)
+				}
+
+				repoSplit := strings.Split(gitAction.GitRepo, "/")
+
+				projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
+
+				if err != nil || projID == 0 {
+					app.handleErrorFormDecoding(err, ErrProjectDecode, w)
+					return
+				}
+
+				gaRunner := &actions.GithubActions{
+					GitIntegration: gr,
+					GitRepoName:    repoSplit[1],
+					GitRepoOwner:   repoSplit[0],
+					Repo:           *app.Repo,
+					GithubConf:     app.GithubProjectConf,
+					WebhookToken:   release.WebhookToken,
+					ProjectID:      uint(projID),
+					ReleaseName:    name,
+					GitBranch:      gitAction.GitBranch,
+					DockerFilePath: gitAction.DockerfilePath,
+					FolderPath:     gitAction.FolderPath,
+					ImageRepoURL:   gitAction.ImageRepoURI,
+					BuildEnv:       cEnv.Container.Env.Normal,
+				}
+
+				err = gaRunner.Cleanup()
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"could not remove github action"},
+					}, w)
+				}
 			}
 		}
 	}

+ 103 - 97
server/api/release_handler.go

@@ -768,48 +768,51 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
 		}
 
 		release, err := app.Repo.Release.ReadRelease(uint(clusterID), name, rel.Namespace)
-		gitAction := release.GitActionConfig
 
-		if release != nil && gitAction.ID != 0 {
-			// parse env into build env
-			cEnv := &ContainerEnvConfig{}
-
-			yaml.Unmarshal([]byte(form.Values), cEnv)
-
-			gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"github repo integration not found"},
-				}, w)
-			}
-
-			repoSplit := strings.Split(gitAction.GitRepo, "/")
-
-			gaRunner := &actions.GithubActions{
-				GitIntegration: gr,
-				GitRepoName:    repoSplit[1],
-				GitRepoOwner:   repoSplit[0],
-				Repo:           *app.Repo,
-				GithubConf:     app.GithubProjectConf,
-				WebhookToken:   release.WebhookToken,
-				ProjectID:      uint(projID),
-				ReleaseName:    name,
-				GitBranch:      gitAction.GitBranch,
-				DockerFilePath: gitAction.DockerfilePath,
-				FolderPath:     gitAction.FolderPath,
-				ImageRepoURL:   gitAction.ImageRepoURI,
-				BuildEnv:       cEnv.Container.Env.Normal,
-			}
-
-			err = gaRunner.CreateEnvSecret()
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"could not update github secret"},
-				}, w)
+		if release != nil {
+			gitAction := release.GitActionConfig
+
+			if gitAction.ID != 0 {
+				// parse env into build env
+				cEnv := &ContainerEnvConfig{}
+
+				yaml.Unmarshal([]byte(form.Values), cEnv)
+
+				gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"github repo integration not found"},
+					}, w)
+				}
+
+				repoSplit := strings.Split(gitAction.GitRepo, "/")
+
+				gaRunner := &actions.GithubActions{
+					GitIntegration: gr,
+					GitRepoName:    repoSplit[1],
+					GitRepoOwner:   repoSplit[0],
+					Repo:           *app.Repo,
+					GithubConf:     app.GithubProjectConf,
+					WebhookToken:   release.WebhookToken,
+					ProjectID:      uint(projID),
+					ReleaseName:    name,
+					GitBranch:      gitAction.GitBranch,
+					DockerFilePath: gitAction.DockerfilePath,
+					FolderPath:     gitAction.FolderPath,
+					ImageRepoURL:   gitAction.ImageRepoURI,
+					BuildEnv:       cEnv.Container.Env.Normal,
+				}
+
+				err = gaRunner.CreateEnvSecret()
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"could not update github secret"},
+					}, w)
+				}
 			}
 		}
 	}
@@ -1013,63 +1016,66 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 		}
 
 		release, err := app.Repo.Release.ReadRelease(uint(clusterID), name, rel.Namespace)
-		gitAction := release.GitActionConfig
-
-		if release != nil && gitAction.ID != 0 {
-			// parse env into build env
-			cEnv := &ContainerEnvConfig{}
-			rawValues, err := yaml.Marshal(rel.Config)
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"could not get values of previous revision"},
-				}, w)
-			}
-
-			yaml.Unmarshal(rawValues, cEnv)
-
-			gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"github repo integration not found"},
-				}, w)
-			}
-
-			repoSplit := strings.Split(gitAction.GitRepo, "/")
-
-			projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
 
-			if err != nil || projID == 0 {
-				app.handleErrorFormDecoding(err, ErrProjectDecode, w)
-				return
-			}
-
-			gaRunner := &actions.GithubActions{
-				GitIntegration: gr,
-				GitRepoName:    repoSplit[1],
-				GitRepoOwner:   repoSplit[0],
-				Repo:           *app.Repo,
-				GithubConf:     app.GithubProjectConf,
-				WebhookToken:   release.WebhookToken,
-				ProjectID:      uint(projID),
-				ReleaseName:    name,
-				GitBranch:      gitAction.GitBranch,
-				DockerFilePath: gitAction.DockerfilePath,
-				FolderPath:     gitAction.FolderPath,
-				ImageRepoURL:   gitAction.ImageRepoURI,
-				BuildEnv:       cEnv.Container.Env.Normal,
-			}
-
-			err = gaRunner.CreateEnvSecret()
-
-			if err != nil {
-				app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-					Code:   ErrReleaseReadData,
-					Errors: []string{"could not update github secret"},
-				}, w)
+		if release != nil {
+			gitAction := release.GitActionConfig
+
+			if gitAction.ID != 0 {
+				// parse env into build env
+				cEnv := &ContainerEnvConfig{}
+				rawValues, err := yaml.Marshal(rel.Config)
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"could not get values of previous revision"},
+					}, w)
+				}
+
+				yaml.Unmarshal(rawValues, cEnv)
+
+				gr, err := app.Repo.GitRepo.ReadGitRepo(gitAction.GitRepoID)
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"github repo integration not found"},
+					}, w)
+				}
+
+				repoSplit := strings.Split(gitAction.GitRepo, "/")
+
+				projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
+
+				if err != nil || projID == 0 {
+					app.handleErrorFormDecoding(err, ErrProjectDecode, w)
+					return
+				}
+
+				gaRunner := &actions.GithubActions{
+					GitIntegration: gr,
+					GitRepoName:    repoSplit[1],
+					GitRepoOwner:   repoSplit[0],
+					Repo:           *app.Repo,
+					GithubConf:     app.GithubProjectConf,
+					WebhookToken:   release.WebhookToken,
+					ProjectID:      uint(projID),
+					ReleaseName:    name,
+					GitBranch:      gitAction.GitBranch,
+					DockerFilePath: gitAction.DockerfilePath,
+					FolderPath:     gitAction.FolderPath,
+					ImageRepoURL:   gitAction.ImageRepoURI,
+					BuildEnv:       cEnv.Container.Env.Normal,
+				}
+
+				err = gaRunner.CreateEnvSecret()
+
+				if err != nil {
+					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+						Code:   ErrReleaseReadData,
+						Errors: []string{"could not update github secret"},
+					}, w)
+				}
 			}
 		}
 	}