mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor of excludeDeprecated helm service method
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
1e5d682b9b
commit
4cf46d1778
@ -4,9 +4,12 @@ import { HelmRepo, HelmRepoManager } from "./helm-repo-manager";
|
||||
import logger from "../logger";
|
||||
import { promiseExec } from "../promise-exec";
|
||||
import { helmCli } from "./helm-cli";
|
||||
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
|
||||
type HelmGroups = { [key: string]: HelmChart[] };
|
||||
|
||||
type CachedYaml = {
|
||||
entries: any; // todo: types
|
||||
entries: HelmGroups
|
||||
};
|
||||
|
||||
export class HelmChartManager {
|
||||
@ -24,7 +27,7 @@ export class HelmChartManager {
|
||||
return charts[name];
|
||||
}
|
||||
|
||||
public async charts(): Promise<any> {
|
||||
public async charts(): Promise<HelmGroups> {
|
||||
try {
|
||||
const cachedYaml = await this.cachedYaml();
|
||||
|
||||
@ -32,7 +35,7 @@ export class HelmChartManager {
|
||||
} catch(error) {
|
||||
logger.error(error);
|
||||
|
||||
return [];
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import logger from "../logger";
|
||||
import { repoManager } from "./helm-repo-manager";
|
||||
import { HelmChartManager } from "./helm-chart-manager";
|
||||
import { releaseManager } from "./helm-release-manager";
|
||||
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
|
||||
class HelmService {
|
||||
public async installChart(cluster: Cluster, data: { chart: string; values: {}; name: string; namespace: string; version: string }) {
|
||||
@ -18,14 +19,9 @@ class HelmService {
|
||||
for (const repo of repositories) {
|
||||
charts[repo.name] = {};
|
||||
const manager = new HelmChartManager(repo);
|
||||
let entries = await manager.charts();
|
||||
const { groups } = new HelmChartGroups(await manager.charts());
|
||||
|
||||
entries = this.excludeDeprecated(entries);
|
||||
|
||||
for (const key in entries) {
|
||||
entries[key] = entries[key][0];
|
||||
}
|
||||
charts[repo.name] = entries;
|
||||
charts[repo.name] = groups;
|
||||
}
|
||||
|
||||
return charts;
|
||||
@ -95,21 +91,27 @@ class HelmService {
|
||||
|
||||
return { message: output };
|
||||
}
|
||||
}
|
||||
|
||||
protected excludeDeprecated(entries: any) {
|
||||
for (const key in entries) {
|
||||
entries[key] = entries[key].filter((entry: any) => {
|
||||
if (Array.isArray(entry)) {
|
||||
return entry[0]["deprecated"] != true;
|
||||
}
|
||||
class HelmChartGroups {
|
||||
items: Map<string, HelmChart[]>;
|
||||
|
||||
return entry["deprecated"] != true;
|
||||
});
|
||||
}
|
||||
|
||||
return entries;
|
||||
constructor(group: { [chartName: string]: HelmChart[] }) {
|
||||
this.items = new Map(Object.entries(group));
|
||||
this.excludeDeprecatedGroups();
|
||||
}
|
||||
|
||||
excludeDeprecatedGroups() {
|
||||
for (const [chartName, charts] of this.items) {
|
||||
if (charts[0].deprecated) {
|
||||
this.items.delete(chartName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get groups() {
|
||||
return Object.fromEntries(this.items);
|
||||
}
|
||||
}
|
||||
|
||||
export const helmService = new HelmService();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user