Enforce semicolons in eslint

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti committed 2020-11-19 16:35:04 +02:00
1 parent 0f3f5611ba
commit 1477bb8274
531 files changed
+3979 -3975

No files matched your search

@@ -1,4 +1,4 @@
import request, { RequestPromiseOptions } from "request-promise-native"
import request, { RequestPromiseOptions } from "request-promise-native";
import { Cluster } from "../cluster";
export type ClusterDetectionResult = {
@@ -11,11 +11,11 @@ export class BaseClusterDetector {
key: string
constructor(cluster: Cluster) {
this.cluster = cluster
this.cluster = cluster;
}
detect(): Promise<ClusterDetectionResult> {
return null
return null;
}
protected async k8sRequest<T = any>(path: string, options: RequestPromiseOptions = {}): Promise<T> {
@@ -28,6 +28,6 @@ export class BaseClusterDetector {
Host: `${this.cluster.id}.${new URL(this.cluster.kubeProxyUrl).host}`, // required in ClusterManager.getClusterForRequest()
...(options.headers || {}),
},
})
});
}
}
@@ -1,23 +1,23 @@
import { BaseClusterDetector } from "./base-cluster-detector";
import { createHash } from "crypto"
import { createHash } from "crypto";
import { ClusterMetadataKey } from "../cluster";
export class ClusterIdDetector extends BaseClusterDetector {
key = ClusterMetadataKey.CLUSTER_ID
public async detect() {
let id: string
let id: string;
try {
id = await this.getDefaultNamespaceId()
id = await this.getDefaultNamespaceId();
} catch(_) {
id = this.cluster.apiUrl
id = this.cluster.apiUrl;
}
const value = createHash("sha256").update(id).digest("hex")
return { value: value, accuracy: 100 }
const value = createHash("sha256").update(id).digest("hex");
return { value: value, accuracy: 100 };
}
protected async getDefaultNamespaceId() {
const response = await this.k8sRequest("/api/v1/namespaces/default")
return response.metadata.uid
const response = await this.k8sRequest("/api/v1/namespaces/default");
return response.metadata.uid;
}
}
+15 -15
View File
@@ -12,34 +12,34 @@ export class DetectorRegistry {
registry = observable.array<typeof BaseClusterDetector>([], { deep: false });
add(detectorClass: typeof BaseClusterDetector) {
this.registry.push(detectorClass)
this.registry.push(detectorClass);
}
async detectForCluster(cluster: Cluster): Promise<ClusterMetadata> {
const results: {[key: string]: ClusterDetectionResult } = {}
const results: {[key: string]: ClusterDetectionResult } = {};
for (const detectorClass of this.registry) {
const detector = new detectorClass(cluster)
const detector = new detectorClass(cluster);
try {
const data = await detector.detect()
const data = await detector.detect();
if (!data) continue;
const existingValue = results[detector.key]
const existingValue = results[detector.key];
if (existingValue && existingValue.accuracy > data.accuracy) continue; // previous value exists and is more accurate
results[detector.key] = data
results[detector.key] = data;
} catch (e) {
// detector raised error, do nothing
}
}
const metadata: ClusterMetadata = {}
const metadata: ClusterMetadata = {};
for (const [key, result] of Object.entries(results)) {
metadata[key] = result.value
metadata[key] = result.value;
}
return metadata
return metadata;
}
}
export const detectorRegistry = new DetectorRegistry()
detectorRegistry.add(ClusterIdDetector)
detectorRegistry.add(LastSeenDetector)
detectorRegistry.add(VersionDetector)
detectorRegistry.add(DistributionDetector)
detectorRegistry.add(NodesCountDetector)
export const detectorRegistry = new DetectorRegistry();
detectorRegistry.add(ClusterIdDetector);
detectorRegistry.add(LastSeenDetector);
detectorRegistry.add(VersionDetector);
detectorRegistry.add(DistributionDetector);
detectorRegistry.add(NodesCountDetector);
@@ -6,75 +6,75 @@ export class DistributionDetector extends BaseClusterDetector {
version: string
public async detect() {
this.version = await this.getKubernetesVersion()
this.version = await this.getKubernetesVersion();
if (await this.isRancher()) {
return { value: "rancher", accuracy: 80}
return { value: "rancher", accuracy: 80};
}
if (this.isGKE()) {
return { value: "gke", accuracy: 80}
return { value: "gke", accuracy: 80};
}
if (this.isEKS()) {
return { value: "eks", accuracy: 80}
return { value: "eks", accuracy: 80};
}
if (this.isIKS()) {
return { value: "iks", accuracy: 80}
return { value: "iks", accuracy: 80};
}
if (this.isAKS()) {
return { value: "aks", accuracy: 80}
return { value: "aks", accuracy: 80};
}
if (this.isDigitalOcean()) {
return { value: "digitalocean", accuracy: 90}
return { value: "digitalocean", accuracy: 90};
}
if (this.isMinikube()) {
return { value: "minikube", accuracy: 80}
return { value: "minikube", accuracy: 80};
}
if (this.isCustom()) {
return { value: "custom", accuracy: 10}
return { value: "custom", accuracy: 10};
}
return { value: "unknown", accuracy: 10}
return { value: "unknown", accuracy: 10};
}
public async getKubernetesVersion() {
if (this.cluster.version) return this.cluster.version
if (this.cluster.version) return this.cluster.version;
const response = await this.k8sRequest("/version")
return response.gitVersion
const response = await this.k8sRequest("/version");
return response.gitVersion;
}
protected isGKE() {
return this.version.includes("gke")
return this.version.includes("gke");
}
protected isEKS() {
return this.version.includes("eks")
return this.version.includes("eks");
}
protected isIKS() {
return this.version.includes("IKS")
return this.version.includes("IKS");
}
protected isAKS() {
return this.cluster.apiUrl.endsWith("azmk8s.io")
return this.cluster.apiUrl.endsWith("azmk8s.io");
}
protected isDigitalOcean() {
return this.cluster.apiUrl.endsWith("k8s.ondigitalocean.com")
return this.cluster.apiUrl.endsWith("k8s.ondigitalocean.com");
}
protected isMinikube() {
return this.cluster.contextName.startsWith("minikube")
return this.cluster.contextName.startsWith("minikube");
}
protected isCustom() {
return this.version.includes("+")
return this.version.includes("+");
}
protected async isRancher() {
try {
const response = await this.k8sRequest("")
return response.data.find((api: any) => api?.apiVersion?.group === "meta.cattle.io") !== undefined
const response = await this.k8sRequest("");
return response.data.find((api: any) => api?.apiVersion?.group === "meta.cattle.io") !== undefined;
} catch (e) {
return false
return false;
}
}
}
@@ -7,7 +7,7 @@ export class LastSeenDetector extends BaseClusterDetector {
public async detect() {
if (!this.cluster.accessible) return null;
await this.k8sRequest("/version")
return { value: new Date().toJSON(), accuracy: 100 }
await this.k8sRequest("/version");
return { value: new Date().toJSON(), accuracy: 100 };
}
}
@@ -6,12 +6,12 @@ export class NodesCountDetector extends BaseClusterDetector {
public async detect() {
if (!this.cluster.accessible) return null;
const nodeCount = await this.getNodeCount()
return { value: nodeCount, accuracy: 100}
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
const response = await this.k8sRequest("/api/v1/nodes");
return response.items.length;
}
}
@@ -6,12 +6,12 @@ export class VersionDetector extends BaseClusterDetector {
value: string
public async detect() {
const version = await this.getKubernetesVersion()
return { value: version, accuracy: 100}
const version = await this.getKubernetesVersion();
return { value: version, accuracy: 100};
}
public async getKubernetesVersion() {
const response = await this.k8sRequest("/version")
return response.gitVersion
const response = await this.k8sRequest("/version");
return response.gitVersion;
}
}