1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/feature-manager.ts
Jussi Nummelin 55687b7d35
Kubeconfigs as file references (#466)
Signed-off-by: Jussi Nummelin <jussi.nummelin@gmail.com>
Co-authored-by: Lauri Nevala <lauri.nevala@gmail.com>
Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-07-03 16:53:23 +03:00

56 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { KubeConfig } from "@kubernetes/client-node"
import logger from "./logger";
import { Cluster } from "./cluster";
import { Feature, FeatureStatusMap } from "./feature"
import { MetricsFeature } from "../features/metrics"
import { UserModeFeature } from "../features/user-mode"
const ALL_FEATURES: any = {
'metrics': new MetricsFeature(null),
'user-mode': new UserModeFeature(null),
}
export async function getFeatures(cluster: Cluster): Promise<FeatureStatusMap> {
return new Promise<FeatureStatusMap>(async (resolve, reject) => {
const result: FeatureStatusMap = {};
logger.debug(`features for ${cluster.contextName}`);
for (const key in ALL_FEATURES) {
logger.debug(`feature ${key}`);
if (ALL_FEATURES.hasOwnProperty(key)) {
logger.debug("getting feature status...");
const feature = ALL_FEATURES[key] as Feature;
const kc = new KubeConfig()
kc.loadFromFile(cluster.proxyKubeconfigPath())
const status = await feature.featureStatus(kc);
result[feature.name] = status
} else {
logger.error("ALL_FEATURES.hasOwnProperty(key) returned FALSE ?!?!?!?!")
}
}
logger.debug(`getFeatures resolving with features: ${JSON.stringify(result)}`);
resolve(result);
});
}
export async function installFeature(name: string, cluster: Cluster, config: any) {
const feature = ALL_FEATURES[name] as Feature
// TODO Figure out how to handle config stuff
await feature.install(cluster)
}
export async function upgradeFeature(name: string, cluster: Cluster, config: any) {
const feature = ALL_FEATURES[name] as Feature
// TODO Figure out how to handle config stuff
await feature.upgrade(cluster)
}
export async function uninstallFeature(name: string, cluster: Cluster) {
const feature = ALL_FEATURES[name] as Feature
await feature.uninstall(cluster)
}