Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upgrade-service): allow no preflights and no config #4942

Merged
8 changes: 0 additions & 8 deletions pkg/upgradeservice/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/replicatedhq/kots/pkg/render"
rendertypes "github.com/replicatedhq/kots/pkg/render/types"
"github.com/replicatedhq/kots/pkg/template"
upgradepreflight "github.com/replicatedhq/kots/pkg/upgradeservice/preflight"
"github.com/replicatedhq/kots/pkg/util"
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/kotskinds/multitype"
Expand Down Expand Up @@ -379,13 +378,6 @@ func (h *Handler) SaveConfig(w http.ResponseWriter, r *http.Request) {
}
}

if err := upgradepreflight.Run(params); err != nil {
response.Error = "failed to run preflights"
logger.Error(errors.Wrap(err, response.Error))
JSON(w, http.StatusInternalServerError, response)
return
}

sgalsaleh marked this conversation as resolved.
Show resolved Hide resolved
response.Success = true
JSON(w, http.StatusOK, response)
}
Expand Down
11 changes: 11 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@
"eslint-plugin-standard": "5.0.0",
"eslint-webpack-plugin": "^4.2.0",
"html-webpack-plugin": "^5.6.0",
"intersection-observer": "^0.12.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fixed-jsdom": "^0.0.4",
"mini-css-extract-plugin": "^2.9.1",
"msw": "^2.4.10",
"object-assign": "^4.1.1",
"os-browserify": "^0.3.0",
"path": "^0.12.7",
Expand Down Expand Up @@ -192,6 +195,14 @@
"not dead"
],
"jest": {
"setupFilesAfterEnv": [
"<rootDir>/src/jest-setup.ts"
],
"testEnvironmentOptions": {
"customExportConditions": [
""
]
},
Comment on lines +202 to +206
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(scss|css|less)$": "<rootDir>/__mocks__/styleMock.js",
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/upgrade_service/AppConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export const AppConfig = ({
);
})}
</div>
<div className="ConfigArea--wrapper">
<div data-testid="config-area" className="ConfigArea--wrapper">
<div
className={classNames("ConfigOuterWrapper card-bg u-padding--15")}
>
Expand Down
59 changes: 49 additions & 10 deletions web/src/components/upgrade_service/ConfirmAndDeploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,46 @@ interface PreflightResultResponse {
showWarn: boolean;
}

const BackButton = ({
slug,
hasPreflight,
isConfigurable,
}: {
slug: string;
hasPreflight: boolean;
isConfigurable: boolean;
}) => {
const navigate = useNavigate();

if (hasPreflight) {
return (
<button
className="btn secondary blue"
onClick={() => navigate(`/upgrade-service/app/${slug}/preflight`)}
>
Back: Preflight checks
</button>
);
}

return (
<button
className="btn secondary blue"
onClick={() => navigate(`/upgrade-service/app/${slug}/config`)}
disabled={!isConfigurable}
>
Back: Config
</button>
);
};

const ConfirmAndDeploy = ({
setCurrentStep,
hasPreflight,
isConfigurable,
}: {
isConfigurable: boolean;
hasPreflight: boolean;
setCurrentStep: (step: number) => void;
}) => {
useEffect(() => {
Expand Down Expand Up @@ -181,7 +218,10 @@ const ConfirmAndDeploy = ({
return (
<div className="flex-column flex1 container">
<KotsPageTitle pageName="Confirm and Deploy" showAppSlug />
<div className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]">
<div
data-testid="deploy-and-confirm-area"
className="PreflightChecks--wrapper flex-column u-paddingTop--30 flex1 flex tw-max-h-[60%]"
>
{location.pathname.includes("version-history") && (
<div className="u-fontWeight--bold link" onClick={() => navigate(-1)}>
<Icon
Expand Down Expand Up @@ -212,7 +252,7 @@ const ConfirmAndDeploy = ({
Confirm and Deploy
</p>

{preflightCheck?.showPreflightCheckPending && (
{hasPreflight && preflightCheck?.showPreflightCheckPending && (
<div className="flex-column justifyContent--center alignItems--center flex1 u-minWidth--full">
<PreflightsProgress
pendingPreflightCheckName={
Expand Down Expand Up @@ -245,7 +285,7 @@ const ConfirmAndDeploy = ({
</div>
</div>

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

{preflightCheck?.showIgnorePreflight && (
{hasPreflight && preflightCheck?.showIgnorePreflight && (
<div className="flex flex0 justifyContent--center alignItems--center">
<span
className="u-fontSize--normal u-fontWeight--medium u-textDecoration--underline u-textColor--bodyCopy u-marginTop--15 u-cursor--pointer"
Expand All @@ -270,12 +310,11 @@ const ConfirmAndDeploy = ({
)}
</div>
<div className="tw-flex tw-justify-between tw-mt-4">
<button
className="btn secondary blue"
onClick={() => navigate(`/upgrade-service/app/${slug}/preflight`)}
>
Back: Preflight checks
</button>
<BackButton
slug={slug}
isConfigurable={isConfigurable}
hasPreflight={hasPreflight}
/>
<button
className="btn primary blue"
disabled={preflightCheck?.showDeploymentBlocked || isLoading}
Expand Down
38 changes: 26 additions & 12 deletions web/src/components/upgrade_service/PreflightChecks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import SkipPreflightsModal from "@components/shared/modals/SkipPreflightsModal";
import PreflightsProgress from "@components/troubleshoot/PreflightsProgress";
import "../../scss/components/PreflightCheckPage.scss";

import { useGetPrelightResults, useRerunPreflights } from "./hooks/index";
import { useGetPrelightResults, useRunPreflights } from "./hooks/index";

import { KotsParams } from "@types";
import { useUpgradeServiceContext } from "./UpgradeServiceContext";
import { isEqual } from "lodash";

const PreflightCheck = ({
setCurrentStep,
isConfigurable,
}: {
setCurrentStep: (step: number) => void;
isConfigurable: boolean;
}) => {
const navigate = useNavigate();

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

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

const {
mutate: runPreflights,
error: runPreflightsError,
isSuccess: runPreflightsSuccess,
} = useRunPreflights({ slug, sequence });
const { data: preflightCheck, error: getPreflightResultsError } =
useGetPrelightResults({ slug, sequence });
const { mutate: rerunPreflights, error: rerunPreflightsError } =
useRerunPreflights({ slug, sequence });
useGetPrelightResults({ slug, sequence, enabled: runPreflightsSuccess });

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

useEffect(() => {
setCurrentStep(1);

// Config changed so we'll re-run the preflights
if (!isEqual(prevConfig, config)) {
runPreflights();
return;
}
// No preflight results means we haven't run them yet, let's do that
if (
!isEqual(prevConfig, config) &&
preflightCheck?.preflightResults.length > 0
!preflightCheck?.preflightResults ||
preflightCheck.preflightResults.length === 0
) {
rerunPreflights();
runPreflights();
}
}, []);

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

{rerunPreflightsError?.message && (
{runPreflightsError?.message && (
<div className="ErrorWrapper flex-auto flex alignItems--center u-marginBottom--20">
<div className="icon redWarningIcon u-marginRight--10" />
<div>
<p className="title">Encountered an error</p>
<p className="error">{rerunPreflightsError.message}</p>
<p className="error">{runPreflightsError.message}</p>
</div>
</div>
)}
Expand Down Expand Up @@ -126,7 +139,7 @@ const PreflightCheck = ({
<button
type="button"
className="btn primary blue"
onClick={() => rerunPreflights()}
onClick={() => runPreflights()}
>
Re-run
</button>
Expand Down Expand Up @@ -156,6 +169,7 @@ const PreflightCheck = ({
<button
className="btn secondary blue"
onClick={() => navigate(`/upgrade-service/app/${slug}/config`)}
disabled={!isConfigurable}
>
Back: Config
</button>
Expand Down
Loading
Loading