Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: incorrect path to install/uninstall feature #723

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}