mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Adding sorting charts by version
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
3b5d248d08
commit
d01fb04964
@ -31,7 +31,7 @@ export class HelmChartManager {
|
|||||||
|
|
||||||
return cachedYaml["entries"];
|
return cachedYaml["entries"];
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.error(error);
|
logger.error("HELM-CHART-MANAGER]: failed to list charts", { error });
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
|
import semver from "semver";
|
||||||
import { Cluster } from "../cluster";
|
import { Cluster } from "../cluster";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { repoManager } from "./helm-repo-manager";
|
import { repoManager } from "./helm-repo-manager";
|
||||||
import { HelmChartManager } from "./helm-chart-manager";
|
import { HelmChartManager } from "./helm-chart-manager";
|
||||||
import { releaseManager } from "./helm-release-manager";
|
import { releaseManager } from "./helm-release-manager";
|
||||||
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api";
|
import { HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
||||||
|
|
||||||
import type { HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
|
||||||
|
|
||||||
class HelmService {
|
class HelmService {
|
||||||
public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) {
|
public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) {
|
||||||
@ -21,9 +20,10 @@ class HelmService {
|
|||||||
for (const repo of repositories) {
|
for (const repo of repositories) {
|
||||||
charts[repo.name] = {};
|
charts[repo.name] = {};
|
||||||
const manager = new HelmChartManager(repo);
|
const manager = new HelmChartManager(repo);
|
||||||
const { groups } = new HelmChartGroups(await manager.charts());
|
const groups = this.excludeDeprecatedChartGroups(await manager.charts());
|
||||||
|
const sortedGroups = this.sortChartsByVersion(groups);
|
||||||
|
|
||||||
charts[repo.name] = groups;
|
charts[repo.name] = sortedGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
return charts;
|
return charts;
|
||||||
@ -93,26 +93,27 @@ class HelmService {
|
|||||||
|
|
||||||
return { message: output };
|
return { message: output };
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class HelmChartGroups {
|
private excludeDeprecatedChartGroups(chartGroups: RepoHelmChartList) {
|
||||||
private items: Map<string, HelmChart[]>;
|
const groups = new Map(Object.entries(chartGroups));
|
||||||
|
|
||||||
constructor(groups: RepoHelmChartList) {
|
for (const [chartName, charts] of groups) {
|
||||||
this.items = new Map(Object.entries(groups));
|
|
||||||
this.excludeDeprecatedGroups();
|
|
||||||
}
|
|
||||||
|
|
||||||
private excludeDeprecatedGroups() {
|
|
||||||
for (const [chartName, charts] of this.items) {
|
|
||||||
if (charts[0].deprecated) {
|
if (charts[0].deprecated) {
|
||||||
this.items.delete(chartName);
|
groups.delete(chartName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Object.fromEntries(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
get groups() {
|
private sortChartsByVersion(chartGroups: RepoHelmChartList) {
|
||||||
return Object.fromEntries(this.items);
|
for (const key in chartGroups) {
|
||||||
|
chartGroups[key] = chartGroups[key].sort((first, second) => {
|
||||||
|
return semver.compare(second.version, first.version);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return chartGroups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user