From ee9bedb1e59c26c1267b2bfce166d56e40db7f15 Mon Sep 17 00:00:00 2001 From: Craig O'Donnell Date: Fri, 26 Jan 2024 21:34:14 +0000 Subject: [PATCH] wip: show initial preflight page for helm chart preflights --- pkg/store/kotsstore/version_store.go | 23 +++++++++++++++---- .../AppConfig/components/AppConfig.tsx | 18 +++++++-------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pkg/store/kotsstore/version_store.go b/pkg/store/kotsstore/version_store.go index 31917bbab8..d0a9248efb 100644 --- a/pkg/store/kotsstore/version_store.go +++ b/pkg/store/kotsstore/version_store.go @@ -546,11 +546,26 @@ func (s *KOTSStore) upsertAppVersionStatements(appID string, sequence int64, bas appIcon := kotsKinds.KotsApplication.Spec.Icon - renderedPreflight, err := s.renderPreflightSpec(appID, a.Slug, sequence, a.IsAirgap, kotsKinds, renderer) + tsKinds, err := kotsutil.LoadTSKindsFromPath(filepath.Join(filesInDir, "rendered")) if err != nil { - return nil, errors.Wrap(err, "failed to render app preflight spec") + return nil, errors.Wrap(err, "failed to load troubleshoot kinds from path") } - kotsKinds.Preflight = renderedPreflight + + var builtPreflight *troubleshootv1beta2.Preflight + if tsKinds.PreflightsV1Beta2 != nil { + for _, v := range tsKinds.PreflightsV1Beta2 { + builtPreflight = troubleshootpreflight.ConcatPreflightSpec(builtPreflight, &v) + } + fmt.Println("***** loaded preflight from rendered") + } else { + renderedPreflight, err := s.renderPreflightSpec(appID, a.Slug, sequence, a.IsAirgap, kotsKinds, renderer) + if err != nil { + return nil, errors.Wrap(err, "failed to render app preflight spec") + } + builtPreflight = renderedPreflight + fmt.Println("***** loaded preflight from kotskinds") + } + kotsKinds.Preflight = builtPreflight renderedApplication, err := s.renderApplicationSpec(appID, a.Slug, sequence, a.IsAirgap, kotsKinds, renderer) if err != nil { @@ -613,7 +628,7 @@ func (s *KOTSStore) upsertAppVersionStatements(appID string, sequence int64, bas for _, d := range downstreams { // there's a small chance this is not optimal, but no current code path // will support multiple downstreams, so this is cleaner here for now - hasStrictPreflights, err := troubleshootpreflight.HasStrictAnalyzers(renderedPreflight) + hasStrictPreflights, err := troubleshootpreflight.HasStrictAnalyzers(builtPreflight) if err != nil { return nil, errors.Wrap(err, "failed to check strict preflights from spec") } diff --git a/web/src/features/AppConfig/components/AppConfig.tsx b/web/src/features/AppConfig/components/AppConfig.tsx index e9214d58f2..ff9057648d 100644 --- a/web/src/features/AppConfig/components/AppConfig.tsx +++ b/web/src/features/AppConfig/components/AppConfig.tsx @@ -141,8 +141,10 @@ class AppConfig extends Component { } window.addEventListener("resize", this.determineSidebarHeight); - if (!this.props.app) { - this.getApp(); + if (!app) { + this.fetchApp(); + } else { + this.setState({ app }); } this.getConfig(); } @@ -204,11 +206,7 @@ class AppConfig extends Component { } }; - getApp = async () => { - if (this.props.app) { - return; - } - + fetchApp = async (): Promise => { try { const { slug } = this.props.params; const res = await fetch(`${process.env.API_ENDPOINT}/app/${slug}`, { @@ -221,6 +219,7 @@ class AppConfig extends Component { if (res.ok && res.status == 200) { const app = await res.json(); this.setState({ app }); + return app; } } catch (err) { console.log(err); @@ -416,7 +415,8 @@ class AppConfig extends Component { } if (fromLicenseFlow) { - const hasPreflight = this.props.app.hasPreflight; + const app = await this.fetchApp(); + const hasPreflight = app?.hasPreflight; if (hasPreflight) { navigate(`/${slug}/preflight`, { replace: true }); @@ -661,6 +661,7 @@ class AppConfig extends Component { render() { const { + app, changed, showConfigError, configErrorMessage, @@ -675,7 +676,6 @@ class AppConfig extends Component { showValidationError, } = this.state; const { fromLicenseFlow, params, isHelmManaged } = this.props; - const app = this.props.app; if (configLoading || !app) { return (