Fix installation of helm charts (#5841)

* Relax validator for installing charts

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Tweak spacing between words in confirmation dialog

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add mocks for monaco editor and virtualized auto sizer to allow components to be rendered in unit tests

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Improve typing for a function

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove usage of shared global state from a component

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Provide a way to unit test usages of storages

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add way to get current value from select in behavioural unit tests

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Rework installation of helm charts to get rid of the majority of bugs

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Update snapshots

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove technical test for being covered in behaviours

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Split behaviour to smaller pieces

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add tests accidentally removed back

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Mark functions causing side effects

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove behaviour covered by other behaviours

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Tweak naming

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Remove unused dependency

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen authored and GitHub committed 2022-07-20 08:15:27 +03:00
1 parent c70788569f
commit f281df1693
65 files changed
+28987 -1523

No files matched your search

@@ -0,0 +1,38 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { asyncComputed } from "@ogre-tools/injectable-react";
import callForHelmChartReadmeInjectable from "./readme/call-for-helm-chart-readme.injectable";
import helmChartDetailsVersionSelectionInjectable from "./versions/helm-chart-details-version-selection.injectable";
import type { HelmChart } from "../../../../common/k8s-api/endpoints/helm-charts.api";
const readmeOfSelectedHelmChartInjectable = getInjectable({
id: "readme-of-selected-helm-chart",
instantiate: (di, chart: HelmChart) => {
const selection = di.inject(helmChartDetailsVersionSelectionInjectable, chart);
const callForHelmChartReadme = di.inject(callForHelmChartReadmeInjectable);
return asyncComputed(async () => {
const chartVersion = selection.value.get();
if (!chartVersion) {
return "";
}
return await callForHelmChartReadme(
chartVersion.getRepository(),
chartVersion.getName(),
chartVersion.getVersion(),
);
}, "");
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, chart: HelmChart) => chart.getId(),
}),
});
export default readmeOfSelectedHelmChartInjectable;
@@ -0,0 +1,29 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { getChartDetails } from "../../../../../common/k8s-api/endpoints/helm-charts.api";
export type CallForHelmChartReadme = (
repo: string,
name: string,
version: string,
) => Promise<string>;
const callForHelmChartReadmeInjectable = getInjectable({
id: "call-for-helm-chart-readme",
instantiate:
(): CallForHelmChartReadme =>
async (repository: string, name: string, version: string) => {
// TODO: Dismantle wrong abstraction
const details = await getChartDetails(repository, name, { version });
return details.readme;
},
causesSideEffects: true,
});
export default callForHelmChartReadmeInjectable;
@@ -0,0 +1,28 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { asyncComputed } from "@ogre-tools/injectable-react";
import callForHelmChartVersionsInjectable from "./versions/call-for-helm-chart-versions.injectable";
import type { HelmChart } from "../../../../common/k8s-api/endpoints/helm-charts.api";
const versionsOfSelectedHelmChartInjectable = getInjectable({
id: "versions-of-selected-helm-chart",
instantiate: (di, chart: HelmChart) => {
const callForHelmChartVersions = di.inject(callForHelmChartVersionsInjectable);
return asyncComputed(
async () =>
await callForHelmChartVersions(chart.getRepository(), chart.getName()),
[],
);
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, chart: HelmChart) => chart.getId(),
}),
});
export default versionsOfSelectedHelmChartInjectable;
@@ -0,0 +1,28 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { HelmChart } from "../../../../../common/k8s-api/endpoints/helm-charts.api";
import { getChartDetails } from "../../../../../common/k8s-api/endpoints/helm-charts.api";
export type CallForHelmChartVersions = (
repo: string,
name: string
) => Promise<HelmChart[]>;
const callForHelmChartVersionsInjectable = getInjectable({
id: "call-for-helm-chart-versions",
instantiate:
(): CallForHelmChartVersions => async (repository: string, name: string) => {
// TODO: Dismantle wrong abstraction
const details = await getChartDetails(repository, name);
return details.versions;
},
causesSideEffects: true,
});
export default callForHelmChartVersionsInjectable;
@@ -0,0 +1,59 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import type { IComputedValue } from "mobx";
import { computed, observable } from "mobx";
import versionsOfSelectedHelmChartInjectable from "../versions-of-selected-helm-chart.injectable";
import type { HelmChart } from "../../../../../common/k8s-api/endpoints/helm-charts.api";
import type { SingleValue } from "react-select";
interface VersionSelectionOption {
label: string;
value: HelmChart;
}
export interface HelmChartDetailsVersionSelection {
value: IComputedValue<HelmChart | undefined>;
options: IComputedValue<VersionSelectionOption[]>;
onChange: (option: SingleValue<VersionSelectionOption>) => void;
}
const helmChartDetailsVersionSelectionInjectable = getInjectable({
id: "helm-chart-details-version-selection",
instantiate: (di, chart: HelmChart): HelmChartDetailsVersionSelection => {
const versionsOfSelectedHelmChart = di.inject(
versionsOfSelectedHelmChartInjectable,
chart,
);
const state = observable.box<HelmChart>();
return {
value: computed(
() => state.get() || versionsOfSelectedHelmChart.value.get()[0],
),
options: computed(() =>
versionsOfSelectedHelmChart.value.get().map((chartVersion) => ({
label: chartVersion.version,
value: chartVersion,
})),
),
onChange: (option) => {
if (option) {
state.set(option.value);
}
},
};
},
lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, chart: HelmChart) => chart.getId(),
}),
});
export default helmChartDetailsVersionSelectionInjectable;