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