mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add eslint rule padding-line-between-statements (#1593)
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
7b77f18376
commit
dcf253e7d5
401 files changed
+2018
-40
No files matched your search
@@ -20,6 +20,7 @@ export class BaseClusterDetector {
|
||||
|
||||
protected async k8sRequest<T = any>(path: string, options: RequestPromiseOptions = {}): Promise<T> {
|
||||
const apiUrl = this.cluster.kubeProxyUrl + path;
|
||||
|
||||
return request(apiUrl, {
|
||||
json: true,
|
||||
timeout: 30000,
|
||||
|
||||
@@ -7,17 +7,20 @@ export class ClusterIdDetector extends BaseClusterDetector {
|
||||
|
||||
public async detect() {
|
||||
let id: string;
|
||||
|
||||
try {
|
||||
id = await this.getDefaultNamespaceId();
|
||||
} catch(_) {
|
||||
id = this.cluster.apiUrl;
|
||||
}
|
||||
const value = createHash("sha256").update(id).digest("hex");
|
||||
|
||||
return { value, accuracy: 100 };
|
||||
}
|
||||
|
||||
protected async getDefaultNamespaceId() {
|
||||
const response = await this.k8sRequest("/api/v1/namespaces/default");
|
||||
|
||||
return response.metadata.uid;
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,16 @@ export class DetectorRegistry {
|
||||
|
||||
async detectForCluster(cluster: Cluster): Promise<ClusterMetadata> {
|
||||
const results: {[key: string]: ClusterDetectionResult } = {};
|
||||
|
||||
for (const detectorClass of this.registry) {
|
||||
const detector = new detectorClass(cluster);
|
||||
|
||||
try {
|
||||
const data = await detector.detect();
|
||||
|
||||
if (!data) continue;
|
||||
const existingValue = results[detector.key];
|
||||
|
||||
if (existingValue && existingValue.accuracy > data.accuracy) continue; // previous value exists and is more accurate
|
||||
results[detector.key] = data;
|
||||
} catch (e) {
|
||||
@@ -30,9 +34,11 @@ export class DetectorRegistry {
|
||||
}
|
||||
}
|
||||
const metadata: ClusterMetadata = {};
|
||||
|
||||
for (const [key, result] of Object.entries(results)) {
|
||||
metadata[key] = result.value;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,30 +7,39 @@ export class DistributionDetector extends BaseClusterDetector {
|
||||
|
||||
public async detect() {
|
||||
this.version = await this.getKubernetesVersion();
|
||||
|
||||
if (await this.isRancher()) {
|
||||
return { value: "rancher", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isGKE()) {
|
||||
return { value: "gke", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isEKS()) {
|
||||
return { value: "eks", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isIKS()) {
|
||||
return { value: "iks", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isAKS()) {
|
||||
return { value: "aks", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isDigitalOcean()) {
|
||||
return { value: "digitalocean", accuracy: 90};
|
||||
}
|
||||
|
||||
if (this.isMinikube()) {
|
||||
return { value: "minikube", accuracy: 80};
|
||||
}
|
||||
|
||||
if (this.isCustom()) {
|
||||
return { value: "custom", accuracy: 10};
|
||||
}
|
||||
|
||||
return { value: "unknown", accuracy: 10};
|
||||
}
|
||||
|
||||
@@ -38,6 +47,7 @@ export class DistributionDetector extends BaseClusterDetector {
|
||||
if (this.cluster.version) return this.cluster.version;
|
||||
|
||||
const response = await this.k8sRequest("/version");
|
||||
|
||||
return response.gitVersion;
|
||||
}
|
||||
|
||||
@@ -72,6 +82,7 @@ export class DistributionDetector extends BaseClusterDetector {
|
||||
protected async isRancher() {
|
||||
try {
|
||||
const response = await this.k8sRequest("");
|
||||
|
||||
return response.data.find((api: any) => api?.apiVersion?.group === "meta.cattle.io") !== undefined;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
||||
@@ -8,6 +8,7 @@ export class LastSeenDetector extends BaseClusterDetector {
|
||||
if (!this.cluster.accessible) return null;
|
||||
|
||||
await this.k8sRequest("/version");
|
||||
|
||||
return { value: new Date().toJSON(), accuracy: 100 };
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ export class NodesCountDetector extends BaseClusterDetector {
|
||||
public async detect() {
|
||||
if (!this.cluster.accessible) return null;
|
||||
const nodeCount = await this.getNodeCount();
|
||||
|
||||
return { value: nodeCount, accuracy: 100};
|
||||
}
|
||||
|
||||
protected async getNodeCount(): Promise<number> {
|
||||
const response = await this.k8sRequest("/api/v1/nodes");
|
||||
|
||||
return response.items.length;
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ export class VersionDetector extends BaseClusterDetector {
|
||||
|
||||
public async detect() {
|
||||
const version = await this.getKubernetesVersion();
|
||||
|
||||
return { value: version, accuracy: 100};
|
||||
}
|
||||
|
||||
public async getKubernetesVersion() {
|
||||
const response = await this.k8sRequest("/version");
|
||||
|
||||
return response.gitVersion;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user