mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Restructure to monorepo (#6907)
* wip: restructure to monorepo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor create-release-pr to a package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * github workflow fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix typo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add webpack-env types to core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix github workflows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor/fix integration tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * yarn run dev Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * eslint settings for vscode Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move templates to right package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * open-lens build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * integration test fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix nx task dependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use bash shell for unit tests in test workflow Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix test:unit for windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build:app on windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ELECTRON_BUILDER_EXTRA_ARGS Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * sync src/ from master Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove Makefile from core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
0066ca4ea2
commit
2657df2293
3321 files changed
+28699
-11447
No files matched your search
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
import { ClusterMetadataKey } from "../../common/cluster-types";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import k8SRequestInjectable from "../k8s-request.injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import requestClusterVersionInjectable from "./request-cluster-version.injectable";
|
||||
|
||||
const isGKE = (version: string) => version.includes("gke");
|
||||
const isEKS = (version: string) => version.includes("eks");
|
||||
const isIKS = (version: string) => version.includes("IKS");
|
||||
const isAKS = (cluster: Cluster) => cluster.apiUrl.includes("azmk8s.io");
|
||||
const isMirantis = (version: string) => version.includes("-mirantis-") || version.includes("-docker-");
|
||||
const isDigitalOcean = (cluster: Cluster) => cluster.apiUrl.endsWith("k8s.ondigitalocean.com");
|
||||
const isMinikube = (cluster: Cluster) => cluster.contextName.startsWith("minikube");
|
||||
const isMicrok8s = (cluster: Cluster) => cluster.contextName.startsWith("microk8s");
|
||||
const isKind = (cluster: Cluster) => cluster.contextName.startsWith("kubernetes-admin@kind-");
|
||||
const isDockerDesktop = (cluster: Cluster) => cluster.contextName === "docker-desktop";
|
||||
const isTke = (version: string) => version.includes("-tke.");
|
||||
const isCustom = (version: string) => version.includes("+");
|
||||
const isVMWare = (version: string) => version.includes("+vmware");
|
||||
const isRke = (version: string) => version.includes("-rancher");
|
||||
const isRancherDesktop = (cluster: Cluster) => cluster.contextName === "rancher-desktop";
|
||||
const isK3s = (version: string) => version.includes("+k3s");
|
||||
const isK0s = (version: string) => version.includes("-k0s") || version.includes("+k0s");
|
||||
const isAlibaba = (version: string) => version.includes("-aliyun");
|
||||
const isHuawei = (version: string) => version.includes("-CCE");
|
||||
|
||||
const clusterDistributionDetectorInjectable = getInjectable({
|
||||
id: "cluster-distribution-detector",
|
||||
instantiate: (di) => {
|
||||
const k8sRequest = di.inject(k8SRequestInjectable);
|
||||
const requestClusterVersion = di.inject(requestClusterVersionInjectable);
|
||||
const isOpenshift = async (cluster: Cluster) => {
|
||||
try {
|
||||
const { paths = [] } = await k8sRequest(cluster, "") as { paths?: string[] };
|
||||
|
||||
return paths.includes("/apis/project.openshift.io");
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
key: ClusterMetadataKey.DISTRIBUTION,
|
||||
detect: async (cluster) => {
|
||||
const version = await requestClusterVersion(cluster);
|
||||
|
||||
if (isRke(version)) {
|
||||
return { value: "rke", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isRancherDesktop(cluster)) {
|
||||
return { value: "rancher-desktop", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isK3s(version)) {
|
||||
return { value: "k3s", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isGKE(version)) {
|
||||
return { value: "gke", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isEKS(version)) {
|
||||
return { value: "eks", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isIKS(version)) {
|
||||
return { value: "iks", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isAKS(cluster)) {
|
||||
return { value: "aks", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isDigitalOcean(cluster)) {
|
||||
return { value: "digitalocean", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isK0s(version)) {
|
||||
return { value: "k0s", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isVMWare(version)) {
|
||||
return { value: "vmware", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isMirantis(version)) {
|
||||
return { value: "mirantis", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isAlibaba(version)) {
|
||||
return { value: "alibaba", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isHuawei(version)) {
|
||||
return { value: "huawei", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isTke(version)) {
|
||||
return { value: "tencent", accuracy: 90 };
|
||||
}
|
||||
|
||||
if (isMinikube(cluster)) {
|
||||
return { value: "minikube", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isMicrok8s(cluster)) {
|
||||
return { value: "microk8s", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isKind(cluster)) {
|
||||
return { value: "kind", accuracy: 70 };
|
||||
}
|
||||
|
||||
if (isDockerDesktop(cluster)) {
|
||||
return { value: "docker-desktop", accuracy: 80 };
|
||||
}
|
||||
|
||||
if (isCustom(version)) {
|
||||
if (await isOpenshift(cluster)) {
|
||||
return { value: "openshift", accuracy: 90 };
|
||||
}
|
||||
|
||||
return { value: "custom", accuracy: 10 };
|
||||
}
|
||||
|
||||
return { value: "unknown", accuracy: 10 };
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: clusterMetadataDetectorInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterDistributionDetectorInjectable;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
import { createHash } from "crypto";
|
||||
import { ClusterMetadataKey } from "../../common/cluster-types";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import k8SRequestInjectable from "../k8s-request.injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
|
||||
const clusterIdDetectorFactoryInjectable = getInjectable({
|
||||
id: "cluster-id-detector-factory",
|
||||
instantiate: (di) => {
|
||||
const k8sRequest = di.inject(k8SRequestInjectable);
|
||||
const getDefaultNamespaceId = async (cluster: Cluster) => {
|
||||
const { metadata } = await k8sRequest(cluster, "/api/v1/namespaces/default") as { metadata: { uid: string }};
|
||||
|
||||
return metadata.uid;
|
||||
};
|
||||
|
||||
return {
|
||||
key: ClusterMetadataKey.CLUSTER_ID,
|
||||
detect: async (cluster) => {
|
||||
let id: string;
|
||||
|
||||
try {
|
||||
id = await getDefaultNamespaceId(cluster);
|
||||
} catch(_) {
|
||||
id = cluster.apiUrl;
|
||||
}
|
||||
const value = createHash("sha256").update(id).digest("hex");
|
||||
|
||||
return { value, accuracy: 100 };
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: clusterMetadataDetectorInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterIdDetectorFactoryInjectable;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
import { ClusterMetadataKey } from "../../common/cluster-types";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import requestClusterVersionInjectable from "./request-cluster-version.injectable";
|
||||
|
||||
const clusterLastSeenDetectorInjectable = getInjectable({
|
||||
id: "cluster-last-seen-detector",
|
||||
instantiate: (di) => {
|
||||
const requestClusterVersion = di.inject(requestClusterVersionInjectable);
|
||||
|
||||
return {
|
||||
key: ClusterMetadataKey.LAST_SEEN,
|
||||
detect: async (cluster) => {
|
||||
try {
|
||||
await requestClusterVersion(cluster);
|
||||
|
||||
return { value: new Date().toJSON(), accuracy: 100 };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: clusterMetadataDetectorInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterLastSeenDetectorInjectable;
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
import { ClusterMetadataKey } from "../../common/cluster-types";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import k8SRequestInjectable from "../k8s-request.injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
|
||||
const clusterNodeCountDetectorInjectable = getInjectable({
|
||||
id: "cluster-node-count-detector",
|
||||
instantiate: (di) => {
|
||||
const k8sRequest = di.inject(k8SRequestInjectable);
|
||||
const requestNodeCount = async (cluster: Cluster) => {
|
||||
const { items } = await k8sRequest(cluster, "/api/v1/nodes") as { items: unknown[] };
|
||||
|
||||
return items.length;
|
||||
};
|
||||
|
||||
return {
|
||||
key: ClusterMetadataKey.NODES_COUNT,
|
||||
detect: async (cluster) => {
|
||||
try {
|
||||
return {
|
||||
value: await requestNodeCount(cluster),
|
||||
accuracy: 1000,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: clusterMetadataDetectorInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterNodeCountDetectorInjectable;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
import { ClusterMetadataKey } from "../../common/cluster-types";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import requestClusterVersionInjectable from "./request-cluster-version.injectable";
|
||||
|
||||
const clusterVersionDetectorInjectable = getInjectable({
|
||||
id: "cluster-version-detector",
|
||||
instantiate: (di) => {
|
||||
const requestClusterVersion = di.inject(requestClusterVersionInjectable);
|
||||
|
||||
return {
|
||||
key: ClusterMetadataKey.VERSION,
|
||||
detect: async (cluster) => ({
|
||||
value: await requestClusterVersion(cluster),
|
||||
accuracy: 100,
|
||||
}),
|
||||
};
|
||||
},
|
||||
injectionToken: clusterMetadataDetectorInjectionToken,
|
||||
});
|
||||
|
||||
export default clusterVersionDetectorInjectable;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { groupBy, reduce } from "lodash";
|
||||
import { filter, map } from "lodash/fp";
|
||||
import type { ClusterMetadata } from "../../common/cluster-types";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import { hasDefinedTupleValue, isDefined, object } from "../../common/utils";
|
||||
import type { ClusterDetectionResult, ClusterMetadataDetector } from "./token";
|
||||
import { clusterMetadataDetectorInjectionToken } from "./token";
|
||||
|
||||
export type DetectClusterMetadata = (cluster: Cluster) => Promise<ClusterMetadata>;
|
||||
|
||||
const pickHighestAccuracy = (prev: ClusterDetectionResult, curr: ClusterDetectionResult) => (
|
||||
prev.accuracy > curr.accuracy
|
||||
? prev
|
||||
: curr
|
||||
);
|
||||
|
||||
const detectMetadataWithFor = (cluster: Cluster) => async (clusterMetadataDetector: ClusterMetadataDetector) => {
|
||||
try {
|
||||
return await clusterMetadataDetector.detect(cluster);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const detectClusterMetadataInjectable = getInjectable({
|
||||
id: "detect-cluster-metadata",
|
||||
instantiate: (di): DetectClusterMetadata => {
|
||||
const clusterMetadataDetectors = di.injectMany(clusterMetadataDetectorInjectionToken);
|
||||
|
||||
return async (cluster) => {
|
||||
const entries = pipeline(
|
||||
await Promise.all(clusterMetadataDetectors.map(detectMetadataWithFor(cluster))),
|
||||
filter(isDefined),
|
||||
(arg) => groupBy(arg, "key"),
|
||||
(arg) => object.entries(arg),
|
||||
map(([ key, results ]) => [key, reduce(results, pickHighestAccuracy)] as const),
|
||||
filter(hasDefinedTupleValue),
|
||||
);
|
||||
|
||||
return object.fromEntries(entries);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default detectClusterMetadataInjectable;
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import k8SRequestInjectable from "../k8s-request.injectable";
|
||||
|
||||
const requestClusterVersionInjectable = getInjectable({
|
||||
id: "request-cluster-version",
|
||||
instantiate: (di) => {
|
||||
const k8sRequest = di.inject(k8SRequestInjectable);
|
||||
|
||||
return async (cluster: Cluster) => {
|
||||
const { gitVersion } = await k8sRequest(cluster, "/version") as { gitVersion: string };
|
||||
|
||||
return gitVersion;
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default requestClusterVersionInjectable;
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
|
||||
export interface ClusterDetectionResult {
|
||||
value: string | number | boolean;
|
||||
accuracy: number;
|
||||
}
|
||||
|
||||
export interface FalibleOnlyClusterMetadataDetector {
|
||||
readonly key: string;
|
||||
detect(cluster: Cluster): Promise<ClusterDetectionResult>;
|
||||
}
|
||||
|
||||
export interface ClusterMetadataDetector {
|
||||
readonly key: string;
|
||||
detect(cluster: Cluster): Promise<ClusterDetectionResult | null>;
|
||||
}
|
||||
|
||||
export const clusterMetadataDetectorInjectionToken = getInjectionToken<ClusterMetadataDetector>({
|
||||
id: "cluster-metadata-detector-token",
|
||||
});
|
||||
Reference in new issue
Block a user