mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Show lens-metrics on cluster settings (#2714)
* show lens-metrics on cluster settings Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ClusterFeature Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ClusterFeature Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * tweak resource applier/stack Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * update metrics stack components Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix drawer menu styles Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * clarify ui Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * built-in -> bundled Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * splitterError -> splitError Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * support multi-doc yamls Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * dedicated action button Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix headers Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * async file operations Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix bugs Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
d9c6e5c52f
commit
683e5926e0
35 files changed
+662
-443
No files matched your search
@@ -29,7 +29,7 @@ import logger from "./logger";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import { Singleton } from "../common/utils";
|
||||
import { catalogEntityRegistry } from "../common/catalog";
|
||||
import { KubernetesCluster } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster";
|
||||
|
||||
export class ClusterManager extends Singleton {
|
||||
constructor() {
|
||||
@@ -68,7 +68,7 @@ export class ClusterManager extends Singleton {
|
||||
const index = catalogEntityRegistry.items.findIndex((entity) => entity.metadata.uid === cluster.id);
|
||||
|
||||
if (index !== -1) {
|
||||
const entity = catalogEntityRegistry.items[index];
|
||||
const entity = catalogEntityRegistry.items[index] as KubernetesCluster;
|
||||
|
||||
entity.status.phase = cluster.disconnected ? "disconnected" : "connected";
|
||||
entity.status.active = !cluster.disconnected;
|
||||
@@ -76,6 +76,17 @@ export class ClusterManager extends Singleton {
|
||||
if (cluster.preferences?.clusterName) {
|
||||
entity.metadata.name = cluster.preferences.clusterName;
|
||||
}
|
||||
|
||||
entity.spec.metrics ||= { source: "local" };
|
||||
|
||||
if (entity.spec.metrics.source === "local") {
|
||||
const prometheus: KubernetesClusterPrometheusMetrics = entity.spec?.metrics?.prometheus || {};
|
||||
|
||||
prometheus.type = cluster.preferences.prometheusProvider?.type;
|
||||
prometheus.address = cluster.preferences.prometheus;
|
||||
entity.spec.metrics.prometheus = prometheus;
|
||||
}
|
||||
|
||||
catalogEntityRegistry.items.splice(index, 1, entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,15 @@ export class ResourceApplier {
|
||||
});
|
||||
}
|
||||
|
||||
public async kubectlApplyAll(resources: string[]): Promise<string> {
|
||||
public async kubectlApplyAll(resources: string[], extraArgs = ["-o", "json"]): Promise<string> {
|
||||
return this.kubectlCmdAll("apply", resources, extraArgs);
|
||||
}
|
||||
|
||||
public async kubectlDeleteAll(resources: string[], extraArgs?: string[]): Promise<string> {
|
||||
return this.kubectlCmdAll("delete", resources, extraArgs);
|
||||
}
|
||||
|
||||
protected async kubectlCmdAll(subCmd: string, resources: string[], args: string[] = []): Promise<string> {
|
||||
const { kubeCtl } = this.cluster;
|
||||
const kubectlPath = await kubeCtl.getPath();
|
||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||
@@ -85,19 +93,24 @@ export class ResourceApplier {
|
||||
resources.forEach((resource, index) => {
|
||||
fs.writeFileSync(path.join(tmpDir, `${index}.yaml`), resource);
|
||||
});
|
||||
const cmd = `"${kubectlPath}" apply --kubeconfig "${proxyKubeconfigPath}" -o json -f "${tmpDir}"`;
|
||||
args.push("-f", `"${tmpDir}"`);
|
||||
const cmd = `"${kubectlPath}" ${subCmd} --kubeconfig "${proxyKubeconfigPath}" ${args.join(" ")}`;
|
||||
|
||||
console.log("shooting manifests with:", cmd);
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
logger.info(`[RESOURCE-APPLIER] running cmd ${cmd}`);
|
||||
exec(cmd, (error, stdout) => {
|
||||
if (error) {
|
||||
reject(`Error applying manifests:${error}`);
|
||||
}
|
||||
logger.error(`[RESOURCE-APPLIER] cmd errored: ${error}`);
|
||||
const splitError = error.toString().split(`.yaml": `);
|
||||
|
||||
if (stderr != "") {
|
||||
reject(stderr);
|
||||
if (splitError[1]) {
|
||||
reject(splitError[1]);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user