mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Initialize HelmRepoManager on demand (#2591)
This commit is contained in:
parent
7132bf3834
commit
b20bedfbae
@ -35,7 +35,7 @@ export class HelmRepoManager extends Singleton {
|
||||
protected helmEnv: HelmEnv;
|
||||
protected initialized: boolean;
|
||||
|
||||
async loadAvailableRepos(): Promise<HelmRepo[]> {
|
||||
public static async loadAvailableRepos(): Promise<HelmRepo[]> {
|
||||
const res = await customRequestPromise({
|
||||
uri: "https://github.com/lensapp/artifact-hub-repositories/releases/download/latest/repositories.json",
|
||||
json: true,
|
||||
@ -46,18 +46,18 @@ export class HelmRepoManager extends Singleton {
|
||||
return orderBy<HelmRepo>(res.body, repo => repo.name);
|
||||
}
|
||||
|
||||
async init() {
|
||||
private async init() {
|
||||
helmCli.setLogger(logger);
|
||||
await helmCli.ensureBinary();
|
||||
|
||||
if (!this.initialized) {
|
||||
this.helmEnv = await this.parseHelmEnv();
|
||||
await this.update();
|
||||
this.helmEnv = await HelmRepoManager.parseHelmEnv();
|
||||
await HelmRepoManager.update();
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected async parseHelmEnv() {
|
||||
protected static async parseHelmEnv() {
|
||||
const helm = await helmCli.binaryPath();
|
||||
const { stdout } = await promiseExec(`"${helm}" env`).catch((error) => {
|
||||
throw(error.stderr);
|
||||
@ -78,6 +78,10 @@ export class HelmRepoManager extends Singleton {
|
||||
|
||||
public async repositories(): Promise<HelmRepo[]> {
|
||||
try {
|
||||
if (!this.initialized) {
|
||||
await this.init();
|
||||
}
|
||||
|
||||
const repoConfigFile = this.helmEnv.HELM_REPOSITORY_CONFIG;
|
||||
const { repositories }: HelmRepoConfig = await readFile(repoConfigFile, "utf8")
|
||||
.then((yamlContent: string) => yaml.safeLoad(yamlContent))
|
||||
@ -86,7 +90,7 @@ export class HelmRepoManager extends Singleton {
|
||||
}));
|
||||
|
||||
if (!repositories.length) {
|
||||
await this.addRepo({ name: "bitnami", url: "https://charts.bitnami.com/bitnami" });
|
||||
await HelmRepoManager.addRepo({ name: "bitnami", url: "https://charts.bitnami.com/bitnami" });
|
||||
|
||||
return await this.repositories();
|
||||
}
|
||||
@ -102,13 +106,7 @@ export class HelmRepoManager extends Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
public async repository(name: string) {
|
||||
const repositories = await this.repositories();
|
||||
|
||||
return repositories.find(repo => repo.name == name);
|
||||
}
|
||||
|
||||
public async update() {
|
||||
public static async update() {
|
||||
const helm = await helmCli.binaryPath();
|
||||
const { stdout } = await promiseExec(`"${helm}" repo update`).catch((error) => {
|
||||
return { stdout: error.stdout };
|
||||
@ -117,7 +115,7 @@ export class HelmRepoManager extends Singleton {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
public async addRepo({ name, url }: HelmRepo) {
|
||||
public static async addRepo({ name, url }: HelmRepo) {
|
||||
logger.info(`[HELM]: adding repo "${name}" from ${url}`);
|
||||
const helm = await helmCli.binaryPath();
|
||||
const { stdout } = await promiseExec(`"${helm}" repo add ${name} ${url}`).catch((error) => {
|
||||
@ -127,7 +125,7 @@ export class HelmRepoManager extends Singleton {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
public async addСustomRepo(repoAttributes : HelmRepo) {
|
||||
public static async addСustomRepo(repoAttributes : HelmRepo) {
|
||||
logger.info(`[HELM]: adding repo "${repoAttributes.name}" from ${repoAttributes.url}`);
|
||||
const helm = await helmCli.binaryPath();
|
||||
|
||||
@ -146,7 +144,7 @@ export class HelmRepoManager extends Singleton {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
public async removeRepo({ name, url }: HelmRepo): Promise<string> {
|
||||
public static async removeRepo({ name, url }: HelmRepo): Promise<string> {
|
||||
logger.info(`[HELM]: removing repo "${name}" from ${url}`);
|
||||
const helm = await helmCli.binaryPath();
|
||||
const { stdout } = await promiseExec(`"${helm}" repo remove ${name}`).catch((error) => {
|
||||
|
||||
@ -34,7 +34,8 @@ class HelmService {
|
||||
readme: "",
|
||||
versions: {}
|
||||
};
|
||||
const repo = await HelmRepoManager.getInstance().repository(repoName);
|
||||
const repos = await HelmRepoManager.getInstance().repositories();
|
||||
const repo = repos.find(repo => repo.name === repoName);
|
||||
const chartManager = new HelmChartManager(repo);
|
||||
const chart = await chartManager.chart(chartName);
|
||||
|
||||
@ -45,7 +46,8 @@ class HelmService {
|
||||
}
|
||||
|
||||
public async getChartValues(repoName: string, chartName: string, version = "") {
|
||||
const repo = await HelmRepoManager.getInstance().repository(repoName);
|
||||
const repos = await HelmRepoManager.getInstance().repositories();
|
||||
const repo = repos.find(repo => repo.name === repoName);
|
||||
const chartManager = new HelmChartManager(repo);
|
||||
|
||||
return chartManager.getValues(chartName, version);
|
||||
|
||||
@ -32,6 +32,7 @@ import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import { CatalogPusher } from "./catalog-pusher";
|
||||
import { catalogEntityRegistry } from "../common/catalog-entity-registry";
|
||||
import { HotbarStore } from "../common/hotbar-store";
|
||||
import { HelmRepoManager } from "./helm/helm-repo-manager";
|
||||
|
||||
const workingDir = path.join(app.getPath("appData"), appName);
|
||||
|
||||
@ -104,6 +105,8 @@ app.on("ready", async () => {
|
||||
const extensionsStore = ExtensionsStore.createInstance();
|
||||
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
||||
|
||||
HelmRepoManager.createInstance(); // create the instance
|
||||
|
||||
logger.info("💾 Loading stores");
|
||||
// preload
|
||||
await Promise.all([
|
||||
|
||||
@ -60,7 +60,8 @@ export async function bootstrap(App: AppComponent) {
|
||||
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
||||
const themeStore = ThemeStore.createInstance();
|
||||
const hotbarStore = HotbarStore.createInstance();
|
||||
const helmRepoManager = HelmRepoManager.createInstance();
|
||||
|
||||
HelmRepoManager.createInstance(); // initialize the manager
|
||||
|
||||
// preload common stores
|
||||
await Promise.all([
|
||||
@ -70,7 +71,6 @@ export async function bootstrap(App: AppComponent) {
|
||||
extensionsStore.load(),
|
||||
filesystemStore.load(),
|
||||
themeStore.init(),
|
||||
helmRepoManager.init(),
|
||||
]);
|
||||
|
||||
// Register additional store listeners
|
||||
|
||||
@ -79,7 +79,7 @@ export class AddHelmRepoDialog extends React.Component<Props> {
|
||||
|
||||
async addCustomRepo() {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().addСustomRepo(this.helmRepo);
|
||||
await HelmRepoManager.addСustomRepo(this.helmRepo);
|
||||
Notifications.ok(<>Helm repository <b>{this.helmRepo.name}</b> has added</>);
|
||||
this.props.onAddRepo();
|
||||
this.close();
|
||||
|
||||
@ -34,7 +34,7 @@ export class HelmCharts extends React.Component {
|
||||
|
||||
try {
|
||||
if (!this.repos.length) {
|
||||
this.repos = await HelmRepoManager.getInstance().loadAvailableRepos(); // via https://helm.sh
|
||||
this.repos = await HelmRepoManager.loadAvailableRepos();
|
||||
}
|
||||
const repos = await HelmRepoManager.getInstance().repositories(); // via helm-cli
|
||||
|
||||
@ -49,7 +49,7 @@ export class HelmCharts extends React.Component {
|
||||
|
||||
async addRepo(repo: HelmRepo) {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().addRepo(repo);
|
||||
await HelmRepoManager.addRepo(repo);
|
||||
this.addedRepos.set(repo.name, repo);
|
||||
} catch (err) {
|
||||
Notifications.error(<>Adding helm branch <b>{repo.name}</b> has failed: {String(err)}</>);
|
||||
@ -58,7 +58,7 @@ export class HelmCharts extends React.Component {
|
||||
|
||||
async removeRepo(repo: HelmRepo) {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().removeRepo(repo);
|
||||
await HelmRepoManager.removeRepo(repo);
|
||||
this.addedRepos.delete(repo.name);
|
||||
} catch (err) {
|
||||
Notifications.error(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user