diff --git a/src/common/k8s-api/endpoints/helm-charts.api/request-values.injectable.ts b/src/common/k8s-api/endpoints/helm-charts.api/request-values.injectable.ts index c48461bba5..71105c9ff9 100644 --- a/src/common/k8s-api/endpoints/helm-charts.api/request-values.injectable.ts +++ b/src/common/k8s-api/endpoints/helm-charts.api/request-values.injectable.ts @@ -3,12 +3,13 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { AsyncResult } from "../../../utils/async-result"; import { urlBuilderFor } from "../../../utils/buildUrl"; import apiBaseInjectable from "../../api-base.injectable"; const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values"); -export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise; +export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise>; const requestHelmChartValuesInjectable = getInjectable({ id: "request-helm-chart-values", diff --git a/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts b/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts index 6a28ea7284..f7aef8dd88 100644 --- a/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts +++ b/src/features/helm-charts/installing-chart/installing-helm-chart-from-new-tab.test.ts @@ -240,9 +240,10 @@ describe("installing helm chart from new tab", () => { describe("when default configuration and versions resolve", () => { beforeEach(async () => { - await requestHelmChartValuesMock.resolve( - "some-default-configuration", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-default-configuration", + }); await requestHelmChartVersionsMock.resolve([ HelmChart.create({ @@ -537,9 +538,10 @@ describe("installing helm chart from new tab", () => { describe("when configuration and versions resolve", () => { beforeEach(async () => { - await requestHelmChartValuesMock.resolve( - "some-other-default-configuration", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-other-default-configuration", + }); await requestHelmChartVersionsMock.resolve([]); }); @@ -702,9 +704,10 @@ describe("installing helm chart from new tab", () => { describe("when default configuration resolves", () => { beforeEach(async () => { - await requestHelmChartValuesMock.resolve( - "some-default-configuration-for-other-version", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-default-configuration-for-other-version", + }); }); it("renders", () => { @@ -847,9 +850,10 @@ describe("installing helm chart from new tab", () => { ) .selectOption("some-other-version"); - await requestHelmChartValuesMock.resolve( - "some-default-configuration-for-other-version", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-default-configuration-for-other-version", + }); expect(installButton).not.toHaveAttribute("disabled"); }); @@ -920,9 +924,10 @@ describe("installing helm chart from new tab", () => { ) .selectOption("some-other-version"); - await requestHelmChartValuesMock.resolve( - "some-default-configuration-for-other-version", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-default-configuration-for-other-version", + }); const input = rendered.getByTestId( "monaco-editor-for-some-first-tab-id", diff --git a/src/features/helm-charts/installing-chart/installing-helm-chart-from-previously-opened-tab.test.ts b/src/features/helm-charts/installing-chart/installing-helm-chart-from-previously-opened-tab.test.ts index 978e1635a7..0b4f749acc 100644 --- a/src/features/helm-charts/installing-chart/installing-helm-chart-from-previously-opened-tab.test.ts +++ b/src/features/helm-charts/installing-chart/installing-helm-chart-from-previously-opened-tab.test.ts @@ -149,9 +149,10 @@ describe("installing helm chart from previously opened tab", () => { describe("when configuration and version resolves", () => { beforeEach(async () => { - await requestHelmChartValuesMock.resolve( - "some-default-configuration", - ); + await requestHelmChartValuesMock.resolve({ + callWasSuccessful: true, + response: "some-default-configuration", + }); await requestHelmChartVersionsMock.resolve([ HelmChart.create({ diff --git a/src/renderer/components/dock/install-chart/install-chart-model.injectable.tsx b/src/renderer/components/dock/install-chart/install-chart-model.injectable.tsx index 0db94fbd59..b0bfcfcacc 100644 --- a/src/renderer/components/dock/install-chart/install-chart-model.injectable.tsx +++ b/src/renderer/components/dock/install-chart/install-chart-model.injectable.tsx @@ -122,14 +122,18 @@ export class InstallChartModel { this.configuration.isLoading.set(true); }); - const configuration = await this.dependencies.requestHelmChartValues( + const chartValuesRequest = await this.dependencies.requestHelmChartValues( this.chart.repo, this.chart.name, version, ); + if (!chartValuesRequest.callWasSuccessful) { + throw chartValuesRequest.error; + } + runInAction(() => { - this.configuration.onChange(configuration); + this.configuration.onChange(chartValuesRequest.response); this.configuration.isLoading.set(false); }); }, @@ -187,7 +191,7 @@ export class InstallChartModel { load = async () => { await this.dependencies.waitForChart(); - const [defaultConfiguration, versions] = await Promise.all([ + const [defaultConfigurationRequest, versions] = await Promise.all([ this.dependencies.requestHelmChartValues( this.chart.repo, this.chart.name, @@ -203,13 +207,14 @@ export class InstallChartModel { runInAction(() => { // TODO: Make "default" not hard-coded const namespace = this.chart.namespace || "default"; + const values = this.chart.values || (defaultConfigurationRequest.callWasSuccessful ? defaultConfigurationRequest.response : ""); this.versions.replace(versions); this.save({ version: this.chart.version, namespace, - values: this.chart.values || defaultConfiguration, + values, releaseName: this.chart.releaseName, }); });