mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
temp
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ad23e51704
commit
2a6e85409a
@ -3,6 +3,8 @@ import { clusterMetaStore } from "./cluster-meta-store";
|
||||
import { ClusterId } from "./cluster-store";
|
||||
import Singleton from "./utils/singleton";
|
||||
|
||||
export class StopError extends Error { }
|
||||
|
||||
export abstract class ClusterMetaCollector {
|
||||
/**
|
||||
* start tells the collector to start collecting its metadata once.
|
||||
|
||||
@ -0,0 +1 @@
|
||||
import { Distribution } from "../distribution"
|
||||
@ -1,16 +1,76 @@
|
||||
import { ClusterMetaCollector } from "../cluster-meta-manager";
|
||||
import { ClusterId } from "../cluster-store";
|
||||
import { observable, when } from "mobx";
|
||||
import requestPromise from "request-promise-native";
|
||||
import { ClusterMetaCollector, StopError } from "../cluster-meta-manager";
|
||||
import { ClusterId, clusterStore } from "../cluster-store";
|
||||
|
||||
export class Distribution extends ClusterMetaCollector {
|
||||
constructor(protected clusterId: ClusterId, protected onSuccess: (result: any) => void, protected onError: (err: string) => void) {
|
||||
private isCollecting = false
|
||||
|
||||
shouldStop = when(() => this.isStopping);
|
||||
@observable isStopping = false
|
||||
|
||||
|
||||
constructor(
|
||||
protected clusterId: ClusterId,
|
||||
protected onSuccess: (result: any) => void,
|
||||
protected onError: (err: string) => void,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
start(): void {
|
||||
// TODO
|
||||
promStopEarly<T>(prom: Promise<T>): Promise<T> {
|
||||
return Promise.race([
|
||||
prom,
|
||||
this.shouldStop.then(() => { throw new StopError() }),
|
||||
])
|
||||
}
|
||||
|
||||
// private detectDistribution() {
|
||||
// if (kubernetesVersion.includes("gke")) return "gke"
|
||||
// if (kubernetesVersion.includes("eks")) return "eks"
|
||||
// if (kubernetesVersion.includes("IKS")) return "iks"
|
||||
// if (this.apiUrl.endsWith("azmk8s.io")) return "aks"
|
||||
// if (this.apiUrl.endsWith("k8s.ondigitalocean.com")) return "digitalocean"
|
||||
// if (this.contextName.startsWith("minikube")) return "minikube"
|
||||
// if (kubernetesVersion.includes("+")) return "custom"
|
||||
// return "vanilla"
|
||||
// }
|
||||
|
||||
async start(): Promise<void> {
|
||||
if (this.isCollecting) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
this.isCollecting = true
|
||||
const cluster = clusterStore.getById(this.clusterId)
|
||||
const url = cluster.kubeProxyUrl + "/version"
|
||||
|
||||
const res = await this.promStopEarly(requestPromise(url, {
|
||||
json: true,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
Host: `${this.clusterId}.${(new URL(cluster.kubeProxyUrl)).host}`
|
||||
}
|
||||
}))
|
||||
|
||||
} catch (err) {
|
||||
if (err instanceof StopError) {
|
||||
return
|
||||
}
|
||||
|
||||
this.onError(String(err))
|
||||
} finally {
|
||||
this.isStopping = false
|
||||
this.isCollecting = false
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
// TODO
|
||||
if (!this.isCollecting) {
|
||||
return
|
||||
}
|
||||
|
||||
this.isStopping = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,12 +51,12 @@ export class Cluster implements ClusterModel {
|
||||
whenInitialized = when(() => this.initialized);
|
||||
whenReady = when(() => this.ready);
|
||||
|
||||
public port: number;
|
||||
@observable initialized = false;
|
||||
@observable contextName: string;
|
||||
@observable workspace: WorkspaceId;
|
||||
@observable kubeConfigPath: string;
|
||||
@observable apiUrl: string; // cluster server url
|
||||
@observable kubeProxyUrl: string; // lens-proxy to kube-api url
|
||||
@observable online = false;
|
||||
@observable accessible = false;
|
||||
@observable ready = false;
|
||||
@ -90,12 +90,16 @@ export class Cluster implements ClusterModel {
|
||||
Object.assign(this, model);
|
||||
}
|
||||
|
||||
get kubeProxyUrl() {
|
||||
return `http://localhost:${this.port}${apiKubePrefix}`
|
||||
}
|
||||
|
||||
@action
|
||||
async init(port: number) {
|
||||
try {
|
||||
this.contextHandler = new ContextHandler(this);
|
||||
this.kubeconfigManager = new KubeconfigManager(this, this.contextHandler, port);
|
||||
this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`;
|
||||
this.port = port
|
||||
this.initialized = true;
|
||||
logger.info(`[CLUSTER]: "${this.contextName}" init success`, {
|
||||
id: this.id,
|
||||
@ -262,6 +266,7 @@ export class Cluster implements ClusterModel {
|
||||
protected async getConnectionStatus(): Promise<ClusterStatus> {
|
||||
try {
|
||||
const response = await this.k8sRequest("/version")
|
||||
console.log(response)
|
||||
this.version = response.gitVersion
|
||||
this.failureReason = null
|
||||
return ClusterStatus.AccessGranted;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user