From 496f31b7cb0790d74d8550ef74139e18fd3c0243 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 20 Aug 2020 16:53:35 +0300 Subject: [PATCH] fix: incorrect path to install/re-install features Signed-off-by: Roman --- src/main/feature.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/feature.ts b/src/main/feature.ts index a62012af5ede..96053c2a0545 100644 --- a/src/main/feature.ts +++ b/src/main/feature.ts @@ -5,6 +5,7 @@ import { ResourceApplier } from "./resource-applier" import { CoreV1Api, KubeConfig, Watch } from "@kubernetes/client-node" import { Cluster } from "./cluster"; import logger from "./logger"; +import { isDevelopment } from "../common/vars"; export type FeatureStatusMap = Record export type FeatureMap = Record @@ -23,8 +24,8 @@ export interface FeatureStatus { } export abstract class Feature { - name: string; - latestVersion: string; + public name: string; + public latestVersion: string; abstract async upgrade(cluster: Cluster): Promise; @@ -35,6 +36,13 @@ export abstract class Feature { constructor(public config: any) { } + get folderPath() { + if (isDevelopment) { + return path.resolve(__static, "../src/features", this.name); + } + return path.resolve(__static, "../features", this.name); + } + async install(cluster: Cluster): Promise { const resources = this.renderTemplates(); try { @@ -70,9 +78,11 @@ export abstract class Feature { } protected renderTemplates(): string[] { + const folderPath = this.folderPath; const resources: string[] = []; - fs.readdirSync(this.manifestPath()).forEach(filename => { - const file = path.join(this.manifestPath(), filename); + logger.info(`[FEATURE]: render templates from ${folderPath}`); + fs.readdirSync(folderPath).forEach(filename => { + const file = path.join(folderPath, filename); const raw = fs.readFileSync(file); if (filename.endsWith('.hb')) { const template = hb.compile(raw.toString()); @@ -84,12 +94,4 @@ export abstract class Feature { return resources; } - - protected manifestPath() { - const devPath = path.join(__dirname, "..", 'src/features', this.name); - if (fs.existsSync(devPath)) { - return devPath; - } - return path.join(__dirname, "..", 'features', this.name); - } }