Skip to content

Commit d20730a

Browse files
authored
fix(upgrade-service): allow no preflights and no config (#4942)
* fix(upgrade-service): allow no preflights and no config
1 parent 73a7dde commit d20730a

16 files changed

+817
-93
lines changed

pkg/upgradeservice/handlers/config.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/replicatedhq/kots/pkg/render"
2626
rendertypes "github.com/replicatedhq/kots/pkg/render/types"
2727
"github.com/replicatedhq/kots/pkg/template"
28-
upgradepreflight "github.com/replicatedhq/kots/pkg/upgradeservice/preflight"
2928
"github.com/replicatedhq/kots/pkg/util"
3029
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
3130
"github.com/replicatedhq/kotskinds/multitype"
@@ -379,13 +378,6 @@ func (h *Handler) SaveConfig(w http.ResponseWriter, r *http.Request) {
379378
}
380379
}
381380

382-
if err := upgradepreflight.Run(params); err != nil {
383-
response.Error = "failed to run preflights"
384-
logger.Error(errors.Wrap(err, response.Error))
385-
JSON(w, http.StatusInternalServerError, response)
386-
return
387-
}
388-
389381
response.Success = true
390382
JSON(w, http.StatusOK, response)
391383
}

web/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,20 @@
9494
"eslint-plugin-standard": "5.0.0",
9595
"eslint-webpack-plugin": "^4.2.0",
9696
"html-webpack-plugin": "^5.6.0",
97+
"intersection-observer": "^0.12.2",
9798
"jest": "^29.7.0",
9899
"jest-environment-jsdom": "^29.7.0",
100+
"jest-fixed-jsdom": "^0.0.4",
99101
"mini-css-extract-plugin": "^2.9.1",
102+
"msw": "^2.4.10",
100103
"object-assign": "^4.1.1",
101104
"os-browserify": "^0.3.0",
102105
"path": "^0.12.7",
103106
"postcss-loader": "^6.2.1",
104107
"prop-types": "^15.7.2",
105108
"sass": "^1.79.5",
106109
"sass-loader": "12.4.0",
110+
"slugify": "^1.6.6",
107111
"source-map-loader": "^5.0.0",
108112
"stream-browserify": "^3.0.0",
109113
"style-loader": "^3.3.4",
@@ -192,6 +196,14 @@
192196
"not dead"
193197
],
194198
"jest": {
199+
"setupFilesAfterEnv": [
200+
"<rootDir>/src/jest-setup.ts"
201+
],
202+
"testEnvironmentOptions": {
203+
"customExportConditions": [
204+
""
205+
]
206+
},
195207
"moduleNameMapper": {
196208
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
197209
"\\.(scss|css|less)$": "<rootDir>/__mocks__/styleMock.js",

web/src/components/upgrade_service/AppConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ export const AppConfig = ({
603603
);
604604
})}
605605
</div>
606-
<div className="ConfigArea--wrapper">
606+
<div data-testid="config-area" className="ConfigArea--wrapper">
607607
<div
608608
className={classNames("ConfigOuterWrapper card-bg u-padding--15")}
609609
>

web/src/components/upgrade_service/ConfirmAndDeploy.tsx

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,46 @@ interface PreflightResultResponse {
2626
showWarn: boolean;
2727
}
2828

29+
const BackButton = ({
30+
slug,
31+
hasPreflight,
32+
isConfigurable,
33+
}: {
34+
slug: string;
35+
hasPreflight: boolean;
36+
isConfigurable: boolean;
37+
}) => {
38+
const navigate = useNavigate();
39+
40+
if (hasPreflight) {
41+
return (
42+
<button
43+
className="btn secondary blue"
44+
onClick={() => navigate(`/upgrade-service/app/${slug}/preflight`)}
45+
>
46+
Back: Preflight checks
47+
</button>
48+
);
49+
}
50+
51+
return (
52+
<button
53+
className="btn secondary blue"
54+
onClick={() => navigate(`/upgrade-service/app/${slug}/config`)}
55+
disabled={!isConfigurable}
56+
>
57+
Back: Config
58+
</button>
59+
);
60+
};
61+
2962
const ConfirmAndDeploy = ({
3063
setCurrentStep,
64+
hasPreflight,
65+
isConfigurable,
3166
}: {
67+
isConfigurable: boolean;
68+
hasPreflight: boolean;
3269
setCurrentStep: (step: number) => void;
3370
}) => {
3471
useEffect(() => {
@@ -181,7 +218,10 @@ const ConfirmAndDeploy = ({
181218
return (
182219
<div className="flex-column flex1 container">
183220
<KotsPageTitle pageName="Confirm and Deploy" showAppSlug />
184-
<div className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]">
221+
<div
222+
data-testid="deploy-and-confirm-area"
223+
className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]"
224+
>
185225
{location.pathname.includes("version-history") && (
186226
<div className="u-fontWeight--bold link" onClick={() => navigate(-1)}>
187227
<Icon
@@ -212,7 +252,7 @@ const ConfirmAndDeploy = ({
212252
Confirm and Deploy
213253
</p>
214254

215-
{preflightCheck?.showPreflightCheckPending && (
255+
{hasPreflight && preflightCheck?.showPreflightCheckPending && (
216256
<div className="flex-column justifyContent--center alignItems--center flex1 u-minWidth--full">
217257
<PreflightsProgress
218258
pendingPreflightCheckName={
@@ -245,7 +285,7 @@ const ConfirmAndDeploy = ({
245285
</div>
246286
</div>
247287

248-
{preflightCheck?.showPreflightResults && (
288+
{hasPreflight && preflightCheck?.showPreflightResults && (
249289
<div className="tw-mt-6">
250290
<div className="flex flex1 tw-justify-between tw-items-end">
251291
<p className="u-fontSize--large u-textColor--primary u-fontWeight--bold">
@@ -258,7 +298,7 @@ const ConfirmAndDeploy = ({
258298
</div>
259299
)}
260300

261-
{preflightCheck?.showIgnorePreflight && (
301+
{hasPreflight && preflightCheck?.showIgnorePreflight && (
262302
<div className="flex flex0 justifyContent--center alignItems--center">
263303
<span
264304
className="u-fontSize--normal u-fontWeight--medium u-textDecoration--underline u-textColor--bodyCopy u-marginTop--15 u-cursor--pointer"
@@ -270,12 +310,11 @@ const ConfirmAndDeploy = ({
270310
)}
271311
</div>
272312
<div className="tw-flex tw-justify-between tw-mt-4">
273-
<button
274-
className="btn secondary blue"
275-
onClick={() => navigate(`/upgrade-service/app/${slug}/preflight`)}
276-
>
277-
Back: Preflight checks
278-
</button>
313+
<BackButton
314+
slug={slug}
315+
isConfigurable={isConfigurable}
316+
hasPreflight={hasPreflight}
317+
/>
279318
<button
280319
className="btn primary blue"
281320
disabled={preflightCheck?.showDeploymentBlocked || isLoading}

web/src/components/upgrade_service/PreflightChecks.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import SkipPreflightsModal from "@components/shared/modals/SkipPreflightsModal";
88
import PreflightsProgress from "@components/troubleshoot/PreflightsProgress";
99
import "../../scss/components/PreflightCheckPage.scss";
1010

11-
import { useGetPrelightResults, useRerunPreflights } from "./hooks/index";
11+
import { useGetPrelightResults, useRunPreflights } from "./hooks/index";
1212

1313
import { KotsParams } from "@types";
1414
import { useUpgradeServiceContext } from "./UpgradeServiceContext";
1515
import { isEqual } from "lodash";
1616

1717
const PreflightCheck = ({
1818
setCurrentStep,
19+
isConfigurable,
1920
}: {
2021
setCurrentStep: (step: number) => void;
22+
isConfigurable: boolean;
2123
}) => {
2224
const navigate = useNavigate();
2325

@@ -35,10 +37,13 @@ const PreflightCheck = ({
3537

3638
const { sequence = "0", slug } = useParams<keyof KotsParams>() as KotsParams;
3739

40+
const {
41+
mutate: runPreflights,
42+
error: runPreflightsError,
43+
isSuccess: runPreflightsSuccess,
44+
} = useRunPreflights({ slug, sequence });
3845
const { data: preflightCheck, error: getPreflightResultsError } =
39-
useGetPrelightResults({ slug, sequence });
40-
const { mutate: rerunPreflights, error: rerunPreflightsError } =
41-
useRerunPreflights({ slug, sequence });
46+
useGetPrelightResults({ slug, sequence, enabled: runPreflightsSuccess });
4247

4348
if (!preflightCheck?.showPreflightCheckPending) {
4449
if (showConfirmIgnorePreflightsModal) {
@@ -48,12 +53,17 @@ const PreflightCheck = ({
4853

4954
useEffect(() => {
5055
setCurrentStep(1);
51-
56+
// Config changed so we'll re-run the preflights
57+
if (!isEqual(prevConfig, config)) {
58+
runPreflights();
59+
return;
60+
}
61+
// No preflight results means we haven't run them yet, let's do that
5262
if (
53-
!isEqual(prevConfig, config) &&
54-
preflightCheck?.preflightResults.length > 0
63+
!preflightCheck?.preflightResults ||
64+
preflightCheck.preflightResults.length === 0
5565
) {
56-
rerunPreflights();
66+
runPreflights();
5767
}
5868
}, []);
5969

@@ -66,7 +76,10 @@ const PreflightCheck = ({
6676
return (
6777
<div className="flex-column flex1 container">
6878
<KotsPageTitle pageName="Preflight Checks" showAppSlug />
69-
<div className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]">
79+
<div
80+
data-testid="preflight-check-area"
81+
className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]"
82+
>
7083
<div
7184
className={`u-maxWidth--full u-marginTop--20 flex-column u-position--relative card-bg ${
7285
preflightCheck?.showPreflightCheckPending ? "flex1" : ""
@@ -82,12 +95,12 @@ const PreflightCheck = ({
8295
</div>
8396
)}
8497

85-
{rerunPreflightsError?.message && (
98+
{runPreflightsError?.message && (
8699
<div className="ErrorWrapper flex-auto flex alignItems--center u-marginBottom--20">
87100
<div className="icon redWarningIcon u-marginRight--10" />
88101
<div>
89102
<p className="title">Encountered an error</p>
90-
<p className="error">{rerunPreflightsError.message}</p>
103+
<p className="error">{runPreflightsError.message}</p>
91104
</div>
92105
</div>
93106
)}
@@ -126,7 +139,7 @@ const PreflightCheck = ({
126139
<button
127140
type="button"
128141
className="btn primary blue"
129-
onClick={() => rerunPreflights()}
142+
onClick={() => runPreflights()}
130143
>
131144
Re-run
132145
</button>
@@ -156,6 +169,7 @@ const PreflightCheck = ({
156169
<button
157170
className="btn secondary blue"
158171
onClick={() => navigate(`/upgrade-service/app/${slug}/config`)}
172+
disabled={!isConfigurable}
159173
>
160174
Back: Config
161175
</button>

0 commit comments

Comments
 (0)