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 logger from "../logger";
|
||||||
import { promiseExec } from "../promise-exec";
|
import { promiseExec } from "../promise-exec";
|
||||||
import { helmCli } from "./helm-cli";
|
import { helmCli } from "./helm-cli";
|
||||||
|
import { HelmChart } from "../../renderer/api/endpoints/helm-charts.api";
|
||||||
|
|
||||||
|
type HelmGroups = { [key: string]: HelmChart[] };
|
||||||
|
|
||||||
type CachedYaml = {
|
type CachedYaml = {
|
||||||
entries: any; // todo: types
|
entries: HelmGroups
|
||||||
};
|
};
|
||||||
|
|
||||||
export class HelmChartManager {
|
export class HelmChartManager {
|
||||||
@ -24,7 +27,7 @@ export class HelmChartManager {
|
|||||||
return charts[name];
|
return charts[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async charts(): Promise<any> {
|
public async charts(): Promise<HelmGroups> {
|
||||||
try {
|
try {
|
||||||
const cachedYaml = await this.cachedYaml();
|
const cachedYaml = await this.cachedYaml();
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ export class HelmChartManager {
|
|||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
|
||||||
return [];
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ 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";
|
||||||
|
|
||||||
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 }) {
|
||||||
@ -18,14 +19,9 @@ 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);
|
||||||
let entries = await manager.charts();
|
const { groups } = new HelmChartGroups(await manager.charts());
|
||||||
|
|
||||||
entries = this.excludeDeprecated(entries);
|
charts[repo.name] = groups;
|
||||||
|
|
||||||
for (const key in entries) {
|
|
||||||
entries[key] = entries[key][0];
|
|
||||||
}
|
|
||||||
charts[repo.name] = entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return charts;
|
return charts;
|
||||||
@ -95,21 +91,27 @@ class HelmService {
|
|||||||
|
|
||||||
return { message: output };
|
return { message: output };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected excludeDeprecated(entries: any) {
|
class HelmChartGroups {
|
||||||
for (const key in entries) {
|
items: Map<string, HelmChart[]>;
|
||||||
entries[key] = entries[key].filter((entry: any) => {
|
|
||||||
if (Array.isArray(entry)) {
|
|
||||||
return entry[0]["deprecated"] != true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry["deprecated"] != true;
|
constructor(group: { [chartName: string]: HelmChart[] }) {
|
||||||
});
|
this.items = new Map(Object.entries(group));
|
||||||
}
|
this.excludeDeprecatedGroups();
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
export const helmService = new HelmService();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user