-
Notifications
You must be signed in to change notification settings - Fork 87
/
PreflightResultPage.jsx
315 lines (287 loc) · 10.8 KB
/
PreflightResultPage.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import React, { Component } from "react";
import { Link } from "react-router-dom";
import { graphql, compose, withApollo } from "react-apollo";
import { Helmet } from "react-helmet";
import { withRouter } from "react-router-dom";
import Modal from "react-modal";
import { getKotsPreflightResult, getLatestKotsPreflightResult } from "@src/queries/AppsQueries";
import Loader from "./shared/Loader";
import PreflightRenderer from "./PreflightRenderer";
import { getPreflightResultState, Utilities } from "../utilities/utilities";
import "../scss/components/PreflightCheckPage.scss";
import PreflightResultErrors from "./PreflightResultErrors";
import has from "lodash/has";
import size from "lodash/size";
class PreflightResultPage extends Component {
state = {
showSkipModal: false,
showWarningModal: false,
};
async componentWillUnmount() {
if (has(this.props.data, "stopPolling")) {
this.props.data.stopPolling();
}
if (this.props.fromLicenseFlow && this.props.refetchListApps) {
await this.props.refetchListApps();
}
}
deployKotsDownstream = async (force = false) => {
try {
const { data, history, match } = this.props;
const preflightResultData = data.getKotsPreflightResult || data.getLatestKotsPreflightResult;
const preflightResults = JSON.parse(preflightResultData?.result);
const preflightState = getPreflightResultState(preflightResults);
if (preflightState !== "pass") {
if (!force) {
this.showWarningModal();
return;
}
const sequence = match.params.sequence ? parseInt(match.params.sequence, 10) : 0;
await this.deployKotsVersion(preflightResultData.appSlug, sequence);
}
history.push(`/app/${preflightResultData.appSlug}/version-history`);
} catch (error) {
console.log(error);
}
}
deployKotsVersion = async (appSlug, sequence) => {
try {
await fetch(`${window.env.API_ENDPOINT}/app/${appSlug}/sequence/${sequence}/deploy`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "POST",
});
} catch(err) {
console.log(err);
}
}
showSkipModal = () => {
this.setState({
showSkipModal: true
})
}
hideSkipModal = () => {
this.setState({
showSkipModal: false
});
}
showWarningModal = () => {
this.setState({
showWarningModal: true
})
}
hideWarningModal = () => {
this.setState({
showWarningModal: false
});
}
ignorePermissionErrors = () => {
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;
const appSlug = preflightResultData.appSlug;
fetch(`${window.env.API_ENDPOINT}/app/${appSlug}/sequence/${sequence}/preflight/ignore-rbac`, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": Utilities.getToken(),
},
method: "POST",
})
.then(async (res) => {
this.props.data.refetch();
})
.catch((err) => {
console.log(err);
});
}
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;
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(),
},
method: "POST",
})
.then((res) => {
if (res.status === 200) {
this.props.data?.refetch();
}
})
.catch((err) => {
console.log(err);
});
}
renderErrors = (errors) => {
this.props.data?.startPolling(2000);
const valueFromAPI = errors.map(error => {
return error.error;
}).join("\n");
return (
<PreflightResultErrors
valueFromAPI={valueFromAPI}
ignorePermissionErrors={this.ignorePermissionErrors}
logo={this.props.logo}
preflightResultData={this.props.data.getKotsPreflightResult || this.props.data.getLatestKotsPreflightResult}
/>
);
}
render() {
const { data } = this.props;
const { showSkipModal, showWarningModal } = this.state;
const isLoading = data.loading;
const preflightResultData = isLoading
? null
: data.getKotsPreflightResult || data.getLatestKotsPreflightResult;
const stopPolling = !!preflightResultData?.result;
let preflightJSON = {};
if (stopPolling) {
data.stopPolling();
if (showSkipModal) {
this.hideSkipModal();
}
preflightJSON = JSON.parse(preflightResultData?.result);
}
const hasResult = size(preflightJSON.results) > 0;
const hasErrors = size(preflightJSON.errors) > 0;
const preflightState = getPreflightResultState(preflightJSON);
return (
<div className="flex-column flex1 container">
<Helmet>
<title>{`${this.props.appName ? `${this.props.appName} Admin Console` : "Admin Console"}`}</title>
</Helmet>
<div className="flex1 flex u-overflow--auto">
<div className="PreflightChecks--wrapper flex1 flex-column u-paddingTop--30">
{this.props.history.location.pathname.includes("version-history") &&
<div className="u-fontWeight--bold u-color--royalBlue u-cursor--pointer" onClick={() => this.props.history.goBack()}>
<span className="icon clickable backArrow-icon u-marginRight--10" style={{ verticalAlign: "0" }} />
Back
</div>}
<div className="u-minWidth--full u-marginTop--20 flex-column flex1">
<p className="u-fontSize--header u-color--tuna u-fontWeight--bold">
Preflight checks
</p>
<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 && (
<div className="flex-column justifyContent--center alignItems--center flex1 u-minWidth--full">
<Loader size="60" />
</div>
)}
{hasErrors && this.renderErrors(preflightJSON?.errors)}
{stopPolling && !hasErrors &&
<div className="flex-column">
<PreflightRenderer
className="u-marginTop--20"
results={preflightResultData.result}
/>
</div>
}
</div>
</div>
</div>
{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"
onClick={stopPolling ? () => this.deployKotsDownstream(false) : this.showSkipModal}
>
{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
isOpen={showSkipModal}
onRequestClose={this.hideSkipModal}
shouldReturnFocusAfterClose={false}
contentLabel="Skip preflight checks"
ariaHideApp={false}
className="Modal"
>
<div className="Modal-body">
<p className="u-fontSize--normal u-color--dustyGray u-lineHeight--normal u-marginBottom--20">Skipping preflight checks will not cancel them. They will continue to run in the background. Do you want to continue to the {preflightResultData?.appSlug} dashboard? </p>
<div className="u-marginTop--10 flex justifyContent--flexEnd">
<button type="button" className="btn secondary" onClick={this.hideSkipModal}>Close</button>
<Link to={`/app/${preflightResultData?.appSlug}`}>
<button type="button" className="btn blue primary u-marginLeft--10">Go to Dashboard</button>
</Link>
</div>
</div>
</Modal>
<Modal
isOpen={showWarningModal}
onRequestClose={this.hideWarningModal}
shouldReturnFocusAfterClose={false}
contentLabel="Preflight shows some issues"
ariaHideApp={false}
className="Modal"
>
<div className="Modal-body">
<p className="u-fontSize--normal u-color--dustyGray u-lineHeight--normal u-marginBottom--20">Preflight is showing some issues, are you sure you want to continue?</p>
<div className="u-marginTop--10 flex justifyContent--flexEnd">
<button type="button" className="btn secondary" onClick={this.hideWarningModal}>Close</button>
<button type="button" className="btn blue primary u-marginLeft--10" onClick={() => this.deployKotsDownstream(true)}>
Deploy and continue
</button>
</div>
</div>
</Modal>
</div>
);
}
}
export default compose(
withApollo,
withRouter,
graphql(getKotsPreflightResult, {
skip: props => {
const { match } = props;
return !match.params.downstreamSlug;
},
options: props => {
const { match } = props;
return {
pollInterval: 2000,
variables: {
appSlug: match.params.slug,
clusterSlug: match.params.downstreamSlug,
sequence: match.params.sequence
},
fetchPolicy: "no-cache"
};
}
}),
graphql(getLatestKotsPreflightResult, {
skip: props => {
const { match } = props;
return !!match.params.downstreamSlug;
},
options: () => {
return {
pollInterval: 2000,
fetchPolicy: "no-cache"
}
}
}),
)(PreflightResultPage);