Skip to content

Commit

Permalink
ability to rerun preflight checks (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Jul 15, 2020
1 parent 5407de9 commit 7f621f7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
2 changes: 1 addition & 1 deletion kotsadm/pkg/apiserver/server.go
Expand Up @@ -93,7 +93,7 @@ func Start() {
// Implemented handlers
r.Path("/api/v1/license/platform").Methods("OPTIONS", "POST").HandlerFunc(handlers.ExchangePlatformLicense)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/preflight/ignore-rbac").Methods("OPTIONS", "POST").HandlerFunc(handlers.IgnorePreflightRBACErrors)
r.Path("/api/v1/app/{appSlug}/preflight/run").Methods("OPTIONS", "POST").HandlerFunc(handlers.StartPreflightChecks)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/preflight/run").Methods("OPTIONS", "POST").HandlerFunc(handlers.StartPreflightChecks)
r.Path("/api/v1/upload").Methods("PUT").HandlerFunc(handlers.UploadExistingApp)
r.Path("/api/v1/download").Methods("GET").HandlerFunc(handlers.DownloadApp)
r.Path("/api/v1/app/{appSlug}/sequence/{sequence}/renderedcontents").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetAppRenderedContents)
Expand Down
15 changes: 14 additions & 1 deletion kotsadm/pkg/handlers/preflight.go
Expand Up @@ -82,6 +82,13 @@ func StartPreflightChecks(w http.ResponseWriter, r *http.Request) {
}

appSlug := mux.Vars(r)["appSlug"]
sequenceStr := mux.Vars(r)["sequence"]
sequence, err := strconv.Atoi(sequenceStr)
if err != nil {
logger.Error(err)
w.WriteHeader(400)
return
}

foundApp, err := app.GetFromSlug(appSlug)
if err != nil {
Expand All @@ -90,7 +97,13 @@ func StartPreflightChecks(w http.ResponseWriter, r *http.Request) {
return
}

archiveDir, err := version.GetAppVersionArchive(foundApp.ID, foundApp.CurrentSequence)
if err := preflight.ResetPreflightResult(foundApp.ID, int64(sequence)); err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}

archiveDir, err := version.GetAppVersionArchive(foundApp.ID, int64(sequence))
if err != nil {
logger.Error(err)
w.WriteHeader(500)
Expand Down
10 changes: 10 additions & 0 deletions kotsadm/pkg/preflight/preflight.go
Expand Up @@ -87,6 +87,16 @@ func Run(appID string, sequence int64, archiveDir string) error {
return nil
}

func ResetPreflightResult(appID string, sequence int64) error {
db := persistence.MustGetPGSession()
query := `update app_downstream_version set preflight_result=null, preflight_result_created_at=null where app_id = $1 and parent_sequence = $2`
_, err := db.Exec(query, appID, sequence)
if err != nil {
return errors.Wrap(err, "failed to exec")
}
return nil
}

// this is a copy from registry. so many import cycles to unwind here, todo
func getRegistrySettingsForApp(appID string) (*registrytypes.RegistrySettings, error) {
db := persistence.MustGetPGSession()
Expand Down
59 changes: 37 additions & 22 deletions kotsadm/web/src/components/PreflightResultPage.jsx
Expand Up @@ -10,7 +10,6 @@ import Loader from "./shared/Loader";
import PreflightRenderer from "./PreflightRenderer";
import { getPreflightResultState, Utilities } from "../utilities/utilities";
import "../scss/components/PreflightCheckPage.scss";
import { retryPreflights } from "../mutations/AppsMutations";
import PreflightResultErrors from "./PreflightResultErrors";
import has from "lodash/has";
import size from "lodash/size";
Expand Down Expand Up @@ -98,19 +97,27 @@ class PreflightResultPage extends Component {
});
}

retryResults= () => {
rerunPreflights = () => {
const preflightResultData = this.props.data.getKotsPreflightResult || this.props.data.getLatestKotsPreflightResult;
const sequence = this.props.match.params.sequence ? parseInt(this.props.match.params.sequence, 10) : 0;
this.props.client.mutate({
mutation: retryPreflights,
variables: {
appSlug: preflightResultData.appSlug,
clusterSlug: preflightResultData.clusterSlug,
sequence: sequence,

const appSlug = preflightResultData.appSlug;
fetch(`${window.env.API_ENDPOINT}/app/${appSlug}/sequence/${sequence}/preflight/run`, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": Utilities.getToken(),
},
}).then(() => {
this.props.data.refetch();
});
method: "POST",
})
.then((res) => {
if (res.status === 200) {
this.props.data?.refetch();
}
})
.catch((err) => {
console.log(err);
});
}

renderErrors = (errors) => {
Expand All @@ -124,7 +131,6 @@ class PreflightResultPage extends Component {
<PreflightResultErrors
valueFromAPI={valueFromAPI}
ignorePermissionErrors={this.ignorePermissionErrors}
retryResults={this.retryResults}
logo={this.props.logo}
preflightResultData={this.props.data.getKotsPreflightResult || this.props.data.getLatestKotsPreflightResult}
/>
Expand Down Expand Up @@ -172,7 +178,7 @@ class PreflightResultPage extends Component {
<p className="u-fontWeight--medium u-lineHeight--more u-marginTop--5 u-marginBottom--10">
Preflight checks validate that your cluster will meet the minimum requirements. If your cluster does not meet the requirements you can still proceed, but understand that things might not work properly.
</p>
{(!stopPolling) && (
{!stopPolling && (
<div className="flex-column justifyContent--center alignItems--center flex1 u-minWidth--full">
<Loader size="60" />
</div>
Expand All @@ -190,21 +196,30 @@ class PreflightResultPage extends Component {
</div>
</div>

{this.props.fromLicenseFlow &&
<div className="flex-auto flex justifyContent--flexEnd">
{(hasResult || stopPolling) && preflightState !== "pass" &&
<Link to={`/app/${preflightResultData?.appSlug}`}>
<button type="button" className="btn secondary u-marginRight--10">Cancel</button>
</Link>
{this.props.fromLicenseFlow ?
<div className="flex-auto flex justifyContent--flexEnd u-marginBottom--15">
{stopPolling && hasResult && preflightState !== "pass" &&
<div className="flex">
<Link to={`/app/${preflightResultData?.appSlug}`}>
<button type="button" className="btn secondary u-marginRight--10">Cancel</button>
</Link>
<button type="button" className="btn secondary blue u-marginRight--10" onClick={this.rerunPreflights}>Re-run</button>
</div>
}
<button
type="button"
className="btn primary blue u-marginBottom--15"
onClick={(hasResult || stopPolling) ? () => this.deployKotsDownstream(false) : this.showSkipModal}
className="btn primary blue"
onClick={stopPolling ? () => this.deployKotsDownstream(false) : this.showSkipModal}
>
{(hasResult || stopPolling) ? "Continue" : "Skip"}
{stopPolling ? "Continue" : "Skip"}
</button>
</div>
: stopPolling ?
<div className="flex-auto flex justifyContent--flexEnd u-marginBottom--15">
<button type="button" className="btn primary blue" onClick={this.rerunPreflights}>Re-run</button>
</div>
:
null
}

<Modal
Expand Down

0 comments on commit 7f621f7

Please sign in to comment.