From 9fa8c74cb142dc30c588139828bb678a5aee8415 Mon Sep 17 00:00:00 2001 From: GraysonNull Date: Tue, 4 Aug 2020 16:21:46 -0500 Subject: [PATCH] Handle showing errors for bad kots release blocking diff creation for newer releases (#905) * support showing error when generating a diff was unsuccessful * Do not fail on license sync error on application updates (#899) * Do not fail on license sync error on appication updates * fixes * log error * fail on license sync * Diff renderedcontents handler return error response on failed kustomize build * handle unable to generate diff errors * update var name * update conditional Co-authored-by: emosbaugh --- .../src/components/apps/AppVersionHistory.jsx | 102 ++++++++++++------ .../watches/DownstreamWatchVersionDiff.jsx | 42 +++++++- .../components/apps/AppVersionHistory.scss | 2 +- kotsadm/web/src/scss/utilities/base.scss | 10 ++ 4 files changed, 119 insertions(+), 37 deletions(-) diff --git a/kotsadm/web/src/components/apps/AppVersionHistory.jsx b/kotsadm/web/src/components/apps/AppVersionHistory.jsx index b9f19e678b..4df847278d 100644 --- a/kotsadm/web/src/components/apps/AppVersionHistory.jsx +++ b/kotsadm/web/src/components/apps/AppVersionHistory.jsx @@ -62,7 +62,8 @@ class AppVersionHistory extends Component { displayShowDetailsModal: false, yamlErrorDetails: [], deployView: false, - selectedSequence: "" + selectedSequence: "", + releaseWithErr: {} } componentDidMount() { @@ -119,6 +120,13 @@ class AppVersionHistory extends Component { }); } + toggleDiffErrModal = (release) => { + this.setState({ + showDiffErrModal: !this.state.showDiffErrModal, + releaseWithErr: !this.state.showDiffErrModal ? release : {} + }) + } + getVersionDiffSummary = version => { if (!version.diffSummary || version.diffSummary === "") { return null; @@ -143,9 +151,9 @@ class AppVersionHistory extends Component { renderYamlErrors = (yamlErrorsDetails, version) => { return ( -
+
- {yamlErrorsDetails?.length} Invalid files + {yamlErrorsDetails?.length} Invalid file{yamlErrorsDetails?.length !== 1 ? "s" : ""} this.toggleShowDetailsModal(yamlErrorsDetails, version.sequence)}> See details
) @@ -155,35 +163,45 @@ class AppVersionHistory extends Component { const { app } = this.props; const downstream = app.downstreams?.length && app.downstreams[0]; const diffSummary = this.getVersionDiffSummary(version); + const hasDiffSummaryError = version.diffSummaryError && version.diffSummaryError.length > 0; - return ( -
- {diffSummary ? - (diffSummary.filesChanged > 0 ? -
{ - if (!downstream.gitops?.enabled) { - this.setState({ - showDiffOverlay: true, - firstSequence: version.parentSequence - 1, - secondSequence: version.parentSequence - }); - } - }} - > - {diffSummary.filesChanged} files changed - +{diffSummary.linesAdded} - -{diffSummary.linesRemoved} -
- : -
- No changes -
- ) - :  } + if (hasDiffSummaryError) { + return ( +
+ Cannot generate diff this.toggleDiffErrModal(version)}>Why?
- ); + ); + } else { + return ( +
+ {diffSummary ? + (diffSummary.filesChanged > 0 ? +
{ + if (!downstream.gitops?.enabled) { + this.setState({ + showDiffOverlay: true, + firstSequence: version.parentSequence - 1, + secondSequence: version.parentSequence + }); + } + }} + > + {diffSummary.filesChanged} files changed + +{diffSummary.linesAdded} + -{diffSummary.linesRemoved} +
+ : +
+ No changes +
+ ) + :  } +
+ ); + } + } renderVersionAction = (version, nothingToCommitDiff) => { @@ -448,10 +466,13 @@ class AppVersionHistory extends Component { }); } - hideDiffOverlay = () => { + hideDiffOverlay = (closeReleaseSelect) => { this.setState({ showDiffOverlay: false }); + if (closeReleaseSelect) { + this.onCloseReleasesToDiff(); + } } onSelectReleasesToDiff = () => { @@ -1193,6 +1214,25 @@ class AppVersionHistory extends Component {
+ + +
+

Unable to generate a file diff for release

+

The release with the Upstream {this.state.releaseWithErr.title}, Sequence {this.state.releaseWithErr.sequence} was unable to generate a files diff because the following error:

+
+ {this.state.releaseWithErr.diffSummaryError} +
+
+ +
+
+
{showUpdateCheckerModal && { + this.setState({ loadingFileTrees: true }); const url = `${window.env.API_ENDPOINT}/app/${this.props.slug}/sequence/${sequence}/renderedcontents`; fetch(url, { headers: { @@ -31,13 +36,25 @@ class DownstreamWatchVersionDiff extends React.Component { }) .then(res => res.json()) .then(async (files) => { + if (files.error) { + return this.setState({ + hasErrSettingDiff: true, + errSettingDiff: files.error, + loadingFileTrees: false, + failedSequence: sequence + }) + } if (isFirst) { - this.setState({firstApplicationTree: files}); + this.setState({ firstApplicationTree: files }); } else { - this.setState({secondApplicationTree: files}); + this.setState({ secondApplicationTree: files }); + } + if (this.state.firstApplicationTree.files && this.state.secondApplicationTree.files) { + this.setState({ loadingFileTrees: false }); } }) .catch((err) => { + this.setState({ loadingFileTrees: false }); throw err; }); } @@ -73,15 +90,15 @@ class DownstreamWatchVersionDiff extends React.Component { goBack = () => { if (this.props.onBackClick) { - this.props.onBackClick(); + this.props.onBackClick(true); } } render() { - const { firstApplicationTree, secondApplicationTree } = this.state; + const { firstApplicationTree, secondApplicationTree, loadingFileTrees, hasErrSettingDiff, errSettingDiff, failedSequence } = this.state; const { firstSequence, secondSequence } = this.props; - if (!firstApplicationTree.files || !secondApplicationTree.files) { + if (loadingFileTrees) { return (
@@ -89,6 +106,21 @@ class DownstreamWatchVersionDiff extends React.Component { ); } + if (hasErrSettingDiff) { + return ( +
+

Unable to generate a file diff for the selected releases

+

The release with the sequence {failedSequence} contains invalid YAML or config values and is unable to generate a diff. The full error is below.

+
+ {errSettingDiff} +
+
+ +
+
+ ) + } + const filesToInclude = []; for (const filename in firstApplicationTree.files) { if (firstApplicationTree.files[filename] === secondApplicationTree.files[filename]) { diff --git a/kotsadm/web/src/scss/components/apps/AppVersionHistory.scss b/kotsadm/web/src/scss/components/apps/AppVersionHistory.scss index bba1a05b50..1e47710327 100644 --- a/kotsadm/web/src/scss/components/apps/AppVersionHistory.scss +++ b/kotsadm/web/src/scss/components/apps/AppVersionHistory.scss @@ -234,7 +234,7 @@ $cell-width: 140px; .overlay { user-select: none; cursor: pointer; - a, button { + a, button, span { pointer-events: none; } } diff --git a/kotsadm/web/src/scss/utilities/base.scss b/kotsadm/web/src/scss/utilities/base.scss index 43fa1311d2..e0291c0eb1 100644 --- a/kotsadm/web/src/scss/utilities/base.scss +++ b/kotsadm/web/src/scss/utilities/base.scss @@ -204,6 +204,16 @@ code { padding: 10px; } +.error-block-wrapper { + background-color: #FBECEA; + border-radius: 4px; + padding: 15px; + margin: 0 auto; + font-size: 14px; + line-height: 1.4; + font-weight: 500; +} + .errors { display: inline-block; color: #FFFFFF;