Skip to content

Commit

Permalink
fix: incorrect path to install/re-install features (#723)
Browse files Browse the repository at this point in the history
Signed-off-by: Roman <ixrock@gmail.com>
  • Loading branch information
ixrock authored Aug 20, 2020
1 parent 1cf446e commit 86e1e23
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FeatureStatus>
export type FeatureMap = Record<string, Feature>
Expand All @@ -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<void>;

Expand All @@ -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<void> {
const resources = this.renderTemplates();
try {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}

0 comments on commit 86e1e23

Please # to comment.