mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor k8s api to common (#3553)
* refactor kube api to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor more utils to common Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * switch to use node-fetch on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * improve logger Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix lint errors Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix/improve tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix node-fetch require error on prod build Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * preload fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * read serverAddress from apiBase Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
476aa74101
commit
58a446bd45
@ -221,6 +221,7 @@
|
||||
"mock-fs": "^4.14.0",
|
||||
"moment": "^2.29.1",
|
||||
"moment-timezone": "^0.5.33",
|
||||
"node-fetch": "^2.6.1",
|
||||
"node-pty": "^0.10.1",
|
||||
"npm": "^6.14.8",
|
||||
"openid-client": "^3.15.2",
|
||||
@ -245,6 +246,7 @@
|
||||
"uuid": "^8.3.2",
|
||||
"win-ca": "^3.2.0",
|
||||
"winston": "^3.3.3",
|
||||
"winston-console-format": "^1.0.8",
|
||||
"winston-transport-browserconsole": "^1.0.5",
|
||||
"ws": "^7.4.6"
|
||||
},
|
||||
@ -283,6 +285,7 @@
|
||||
"@types/mock-fs": "^4.13.1",
|
||||
"@types/module-alias": "^2.0.0",
|
||||
"@types/node": "12.20",
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"@types/npm": "^2.0.31",
|
||||
"@types/progress-bar-webpack-plugin": "^2.1.2",
|
||||
"@types/proper-lockfile": "^4.1.1",
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { ingressStore } from "../../components/+network-ingresses/ingress.store";
|
||||
import { ingressStore } from "../../../renderer/components/+network-ingresses/ingress.store";
|
||||
import { apiManager } from "../api-manager";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -20,12 +20,22 @@
|
||||
*/
|
||||
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeJsonApi } from "../kube-json-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
|
||||
describe("KubeApi", () => {
|
||||
let request: KubeJsonApi;
|
||||
|
||||
beforeEach(() => {
|
||||
request = new KubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:9999`,
|
||||
apiBase: "/api-kube"
|
||||
});
|
||||
});
|
||||
|
||||
it("uses url from apiBase if apiBase contains the resource", async () => {
|
||||
(fetch as any).mockResponse(async (request: any) => {
|
||||
if (request.url === "/api-kube/apis/networking.k8s.io/v1") {
|
||||
if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") {
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
resources: [{
|
||||
@ -33,7 +43,7 @@ describe("KubeApi", () => {
|
||||
}] as any[]
|
||||
})
|
||||
};
|
||||
} else if (request.url === "/api-kube/apis/extensions/v1beta1") {
|
||||
} else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") {
|
||||
// Even if the old API contains ingresses, KubeApi should prefer the apiBase url
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
@ -54,6 +64,7 @@ describe("KubeApi", () => {
|
||||
const apiBase = "/apis/networking.k8s.io/v1/ingresses";
|
||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||
const kubeApi = new KubeApi({
|
||||
request,
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
fallbackApiBases: [fallbackApiBase],
|
||||
@ -67,13 +78,13 @@ describe("KubeApi", () => {
|
||||
|
||||
it("uses url from fallbackApiBases if apiBase lacks the resource", async () => {
|
||||
(fetch as any).mockResponse(async (request: any) => {
|
||||
if (request.url === "/api-kube/apis/networking.k8s.io/v1") {
|
||||
if (request.url === "http://127.0.0.1:9999/api-kube/apis/networking.k8s.io/v1") {
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
resources: [] as any[]
|
||||
})
|
||||
};
|
||||
} else if (request.url === "/api-kube/apis/extensions/v1beta1") {
|
||||
} else if (request.url === "http://127.0.0.1:9999/api-kube/apis/extensions/v1beta1") {
|
||||
return {
|
||||
body: JSON.stringify({
|
||||
resources: [{
|
||||
@ -93,6 +104,7 @@ describe("KubeApi", () => {
|
||||
const apiBase = "apis/networking.k8s.io/v1/ingresses";
|
||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||
const kubeApi = new KubeApi({
|
||||
request,
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
fallbackApiBases: [fallbackApiBase],
|
||||
@ -19,7 +19,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type { KubeObjectStore } from "../kube-object.store";
|
||||
import type { KubeObjectStore } from "./kube-object.store";
|
||||
|
||||
import { action, observable, makeObservable } from "mobx";
|
||||
import { autoBind, iter } from "../utils";
|
||||
@ -49,6 +49,8 @@ export class ApiManager {
|
||||
}
|
||||
|
||||
registerApi(apiBase: string, api: KubeApi<KubeObject>) {
|
||||
if (!api.apiBase) return;
|
||||
|
||||
if (!this.apis.has(apiBase)) {
|
||||
this.stores.forEach((store) => {
|
||||
if (store.api === api) {
|
||||
@ -84,8 +86,8 @@ export class ApiManager {
|
||||
|
||||
@action
|
||||
registerStore(store: KubeObjectStore<KubeObject>, apis: KubeApi<KubeObject>[] = [store.api]) {
|
||||
apis.forEach(api => {
|
||||
this.stores.set(api.apiBase, store);
|
||||
apis.filter(Boolean).forEach(api => {
|
||||
if (api.apiBase) this.stores.set(api.apiBase, store);
|
||||
});
|
||||
}
|
||||
|
||||
28
src/common/k8s-api/cluster-context.ts
Normal file
28
src/common/k8s-api/cluster-context.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type { Cluster } from "../../main/cluster";
|
||||
|
||||
export interface ClusterContext {
|
||||
cluster?: Cluster;
|
||||
allNamespaces: string[]; // available / allowed namespaces from cluster.ts
|
||||
contextNamespaces: string[]; // selected by user (see: namespace-select.tsx)
|
||||
}
|
||||
@ -18,6 +18,7 @@
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
|
||||
@ -53,6 +54,17 @@ export class ClusterRoleBinding extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const clusterRoleBindingApi = new KubeApi({
|
||||
objectConstructor: ClusterRoleBinding,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let clusterRoleBindingApi: KubeApi<ClusterRoleBinding>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
clusterRoleBindingApi = new KubeApi({
|
||||
objectConstructor: ClusterRoleBinding,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
clusterRoleBindingApi
|
||||
};
|
||||
@ -19,6 +19,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
|
||||
@ -41,6 +42,17 @@ export class ClusterRole extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const clusterRoleApi = new KubeApi({
|
||||
objectConstructor: ClusterRole,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let clusterRoleApi: KubeApi<ClusterRole>;
|
||||
|
||||
if (isClusterPageContext()) { // initialize automatically only when within a cluster iframe/context
|
||||
clusterRoleApi = new KubeApi({
|
||||
objectConstructor: ClusterRole,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
clusterRoleApi
|
||||
};
|
||||
@ -22,6 +22,7 @@
|
||||
import { IMetrics, IMetricsReqParams, metricsApi } from "./metrics.api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class ClusterApi extends KubeApi<Cluster> {
|
||||
static kind = "Cluster";
|
||||
@ -122,6 +123,17 @@ export class Cluster extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const clusterApi = new ClusterApi({
|
||||
objectConstructor: Cluster,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let clusterApi: ClusterApi;
|
||||
|
||||
if (isClusterPageContext()) { // initialize automatically only when within a cluster iframe/context
|
||||
clusterApi = new ClusterApi({
|
||||
objectConstructor: Cluster,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
clusterApi
|
||||
};
|
||||
@ -22,7 +22,8 @@
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autoBind } from "../../../common/utils";
|
||||
import { autoBind } from "../../utils";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface ConfigMap {
|
||||
data: {
|
||||
@ -47,6 +48,17 @@ export class ConfigMap extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const configMapApi = new KubeApi({
|
||||
objectConstructor: ConfigMap,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let configMapApi: KubeApi<ConfigMap>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
configMapApi = new KubeApi({
|
||||
objectConstructor: ConfigMap,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
configMapApi
|
||||
};
|
||||
@ -21,7 +21,8 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { crdResourcesURL } from "../../../common/routes";
|
||||
import { crdResourcesURL } from "../../routes";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
type AdditionalPrinterColumnsCommon = {
|
||||
name: string;
|
||||
@ -174,7 +175,18 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const crdApi = new KubeApi<CustomResourceDefinition>({
|
||||
objectConstructor: CustomResourceDefinition,
|
||||
checkPreferredVersion: true,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let crdApi: KubeApi<CustomResourceDefinition>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
crdApi = new KubeApi<CustomResourceDefinition>({
|
||||
objectConstructor: CustomResourceDefinition,
|
||||
checkPreferredVersion: true,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
crdApi
|
||||
};
|
||||
@ -26,6 +26,7 @@ import { formatDuration } from "../../utils/formatDuration";
|
||||
import { autoBind } from "../../utils";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class CronJobApi extends KubeApi<CronJob> {
|
||||
suspend(params: { namespace: string; name: string }) {
|
||||
@ -140,6 +141,17 @@ export class CronJob extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const cronJobApi = new CronJobApi({
|
||||
objectConstructor: CronJob,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let cronJobApi: CronJobApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
cronJobApi = new CronJobApi({
|
||||
objectConstructor: CronJob,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
cronJobApi
|
||||
};
|
||||
@ -26,6 +26,7 @@ import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { IPodContainer, IPodMetrics } from "./pods.api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class DaemonSet extends WorkloadKubeObject {
|
||||
static kind = "DaemonSet";
|
||||
@ -116,6 +117,17 @@ export function getMetricsForDaemonSets(daemonsets: DaemonSet[], namespace: stri
|
||||
});
|
||||
}
|
||||
|
||||
export const daemonSetApi = new DaemonSetApi({
|
||||
objectConstructor: DaemonSet,
|
||||
});
|
||||
/**
|
||||
* Only available within kubernetes cluster pages
|
||||
*/
|
||||
let daemonSetApi: DaemonSetApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
daemonSetApi = new DaemonSetApi({
|
||||
objectConstructor: DaemonSet,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
daemonSetApi
|
||||
};
|
||||
@ -27,6 +27,7 @@ import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { IPodMetrics } from "./pods.api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class DeploymentApi extends KubeApi<Deployment> {
|
||||
protected getScaleApiUrl(params: { namespace: string; name: string }) {
|
||||
@ -232,6 +233,14 @@ export class Deployment extends WorkloadKubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const deploymentApi = new DeploymentApi({
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
let deploymentApi: DeploymentApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
deploymentApi = new DeploymentApi({
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
deploymentApi
|
||||
};
|
||||
@ -24,6 +24,7 @@ import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { get } from "lodash";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface IEndpointPort {
|
||||
name?: string;
|
||||
@ -149,6 +150,14 @@ export class Endpoint extends KubeObject {
|
||||
|
||||
}
|
||||
|
||||
export const endpointApi = new KubeApi({
|
||||
objectConstructor: Endpoint,
|
||||
});
|
||||
let endpointApi: KubeApi<Endpoint>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
endpointApi = new KubeApi<Endpoint>({
|
||||
objectConstructor: Endpoint,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
endpointApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import moment from "moment";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface KubeEvent {
|
||||
involvedObject: {
|
||||
@ -77,6 +78,14 @@ export class KubeEvent extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const eventApi = new KubeApi({
|
||||
objectConstructor: KubeEvent,
|
||||
});
|
||||
let eventApi: KubeApi<KubeEvent>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
eventApi = new KubeApi<KubeEvent>({
|
||||
objectConstructor: KubeEvent,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
eventApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { compile } from "path-to-regexp";
|
||||
import { apiBase } from "../index";
|
||||
import { stringify } from "querystring";
|
||||
import { autoBind } from "../../utils";
|
||||
import type { RequestInit } from "node-fetch";
|
||||
|
||||
export type RepoHelmChartList = Record<string, HelmChart[]>;
|
||||
export type HelmChartList = Record<string, RepoHelmChartList>;
|
||||
@ -23,11 +23,11 @@ import jsYaml from "js-yaml";
|
||||
import { autoBind, formatDuration } from "../../utils";
|
||||
import capitalize from "lodash/capitalize";
|
||||
import { apiBase } from "../index";
|
||||
import { helmChartStore } from "../../components/+apps-helm-charts/helm-chart.store";
|
||||
import { helmChartStore } from "../../../renderer/components/+apps-helm-charts/helm-chart.store";
|
||||
import type { ItemObject } from "../../item.store";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { JsonApiData } from "../json-api";
|
||||
import { buildURLPositional } from "../../../common/utils/buildUrl";
|
||||
import { buildURLPositional } from "../../utils/buildUrl";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
interface IReleasePayload {
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export enum HpaMetricType {
|
||||
Resource = "Resource",
|
||||
@ -163,6 +164,14 @@ export class HorizontalPodAutoscaler extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const hpaApi = new KubeApi({
|
||||
objectConstructor: HorizontalPodAutoscaler,
|
||||
});
|
||||
let hpaApi: KubeApi<HorizontalPodAutoscaler>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
hpaApi = new KubeApi<HorizontalPodAutoscaler>({
|
||||
objectConstructor: HorizontalPodAutoscaler,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
hpaApi
|
||||
};
|
||||
@ -24,6 +24,7 @@ import { autoBind } from "../../utils";
|
||||
import { IMetrics, metricsApi } from "./metrics.api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class IngressApi extends KubeApi<Ingress> {
|
||||
}
|
||||
@ -203,10 +204,17 @@ export class Ingress extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const ingressApi = new IngressApi({
|
||||
objectConstructor: Ingress,
|
||||
// Add fallback for Kubernetes <1.19
|
||||
checkPreferredVersion: true,
|
||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
|
||||
logStuff: true
|
||||
} as any);
|
||||
let ingressApi: IngressApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
ingressApi = new IngressApi({
|
||||
objectConstructor: Ingress,
|
||||
// Add fallback for Kubernetes <1.19
|
||||
checkPreferredVersion: true,
|
||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
ingressApi
|
||||
};
|
||||
@ -27,6 +27,7 @@ import { metricsApi } from "./metrics.api";
|
||||
import type { JsonApiParams } from "../json-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { IPodContainer, IPodMetrics } from "./pods.api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class Job extends WorkloadKubeObject {
|
||||
static kind = "Job";
|
||||
@ -148,6 +149,14 @@ export function getMetricsForJobs(jobs: Job[], namespace: string, selector = "")
|
||||
});
|
||||
}
|
||||
|
||||
export const jobApi = new JobApi({
|
||||
objectConstructor: Job,
|
||||
});
|
||||
let jobApi: JobApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
jobApi = new JobApi({
|
||||
objectConstructor: Job,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
jobApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export enum LimitType {
|
||||
CONTAINER = "Container",
|
||||
@ -80,6 +81,14 @@ export class LimitRange extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const limitRangeApi = new KubeApi({
|
||||
objectConstructor: LimitRange,
|
||||
});
|
||||
let limitRangeApi: KubeApi<LimitRange>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
limitRangeApi = new KubeApi<LimitRange>({
|
||||
objectConstructor: LimitRange,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
limitRangeApi
|
||||
};
|
||||
@ -21,10 +21,11 @@
|
||||
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { autoBind } from "../../utils";
|
||||
import { autoBind } from "../../../renderer/utils";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { IPodMetrics } from "./pods.api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export enum NamespaceStatus {
|
||||
ACTIVE = "Active",
|
||||
@ -69,6 +70,14 @@ export function getMetricsForNamespace(namespace: string, selector = ""): Promis
|
||||
});
|
||||
}
|
||||
|
||||
export const namespacesApi = new NamespaceApi({
|
||||
objectConstructor: Namespace,
|
||||
});
|
||||
let namespacesApi: NamespaceApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
namespacesApi = new NamespaceApi({
|
||||
objectConstructor: Namespace,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
namespacesApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object";
|
||||
import { autoBind } from "../../utils";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface IPolicyIpBlock {
|
||||
cidr: string;
|
||||
@ -96,6 +97,14 @@ export class NetworkPolicy extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const networkPolicyApi = new KubeApi({
|
||||
objectConstructor: NetworkPolicy,
|
||||
});
|
||||
let networkPolicyApi: KubeApi<NetworkPolicy>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
networkPolicyApi = new KubeApi<NetworkPolicy>({
|
||||
objectConstructor: NetworkPolicy,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
networkPolicyApi
|
||||
};
|
||||
@ -20,10 +20,11 @@
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../utils";
|
||||
import { autoBind, cpuUnitsToNumber, unitsToBytes } from "../../../renderer/utils";
|
||||
import { IMetrics, metricsApi } from "./metrics.api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class NodesApi extends KubeApi<Node> {
|
||||
}
|
||||
@ -225,6 +226,14 @@ export class Node extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const nodesApi = new NodesApi({
|
||||
objectConstructor: Node,
|
||||
});
|
||||
let nodesApi: NodesApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
nodesApi = new NodesApi({
|
||||
objectConstructor: Node,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
nodesApi
|
||||
};
|
||||
@ -25,6 +25,7 @@ import { IMetrics, metricsApi } from "./metrics.api";
|
||||
import type { Pod } from "./pods.api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class PersistentVolumeClaimsApi extends KubeApi<PersistentVolumeClaim> {
|
||||
}
|
||||
@ -116,6 +117,14 @@ export class PersistentVolumeClaim extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const pvcApi = new PersistentVolumeClaimsApi({
|
||||
objectConstructor: PersistentVolumeClaim,
|
||||
});
|
||||
let pvcApi: PersistentVolumeClaimsApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
pvcApi = new PersistentVolumeClaimsApi({
|
||||
objectConstructor: PersistentVolumeClaim,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
pvcApi
|
||||
};
|
||||
@ -20,10 +20,10 @@
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { unitsToBytes } from "../../utils/convertMemory";
|
||||
import { autoBind } from "../../utils";
|
||||
import { autoBind, unitsToBytes } from "../../utils";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface PersistentVolume {
|
||||
spec: {
|
||||
@ -102,6 +102,14 @@ export class PersistentVolume extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const persistentVolumeApi = new KubeApi({
|
||||
objectConstructor: PersistentVolume,
|
||||
});
|
||||
let persistentVolumeApi: KubeApi<PersistentVolume>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
persistentVolumeApi = new KubeApi({
|
||||
objectConstructor: PersistentVolume,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
persistentVolumeApi
|
||||
};
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface PodMetrics {
|
||||
timestamp: string;
|
||||
@ -40,6 +41,14 @@ export class PodMetrics extends KubeObject {
|
||||
static apiBase = "/apis/metrics.k8s.io/v1beta1/pods";
|
||||
}
|
||||
|
||||
export const podMetricsApi = new KubeApi({
|
||||
objectConstructor: PodMetrics,
|
||||
});
|
||||
let podMetricsApi: KubeApi<PodMetrics>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
podMetricsApi = new KubeApi<PodMetrics>({
|
||||
objectConstructor: PodMetrics,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
podMetricsApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { autoBind } from "../../utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface PodDisruptionBudget {
|
||||
spec: {
|
||||
@ -72,6 +73,14 @@ export class PodDisruptionBudget extends KubeObject {
|
||||
|
||||
}
|
||||
|
||||
export const pdbApi = new KubeApi({
|
||||
objectConstructor: PodDisruptionBudget,
|
||||
});
|
||||
let pdbApi: KubeApi<PodDisruptionBudget>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
pdbApi = new KubeApi({
|
||||
objectConstructor: PodDisruptionBudget,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
pdbApi
|
||||
};
|
||||
@ -24,6 +24,7 @@ import { autoBind } from "../../utils";
|
||||
import { IMetrics, metricsApi } from "./metrics.api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class PodsApi extends KubeApi<Pod> {
|
||||
async getLogs(params: { namespace: string; name: string }, query?: IPodLogsQuery): Promise<string> {
|
||||
@ -502,6 +503,14 @@ export class Pod extends WorkloadKubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const podsApi = new PodsApi({
|
||||
objectConstructor: Pod,
|
||||
});
|
||||
let podsApi: PodsApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
podsApi = new PodsApi({
|
||||
objectConstructor: Pod,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
podsApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { autoBind } from "../../utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface PodSecurityPolicy {
|
||||
spec: {
|
||||
@ -117,6 +118,14 @@ export class PodSecurityPolicy extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const pspApi = new KubeApi({
|
||||
objectConstructor: PodSecurityPolicy,
|
||||
});
|
||||
let pspApi: KubeApi<PodSecurityPolicy>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
pspApi = new KubeApi({
|
||||
objectConstructor: PodSecurityPolicy,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
pspApi
|
||||
};
|
||||
@ -20,12 +20,13 @@
|
||||
*/
|
||||
|
||||
import get from "lodash/get";
|
||||
import { autoBind } from "../../utils";
|
||||
import { autoBind } from "../../../renderer/utils";
|
||||
import { WorkloadKubeObject } from "../workload-kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { IPodContainer, IPodMetrics, Pod } from "./pods.api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class ReplicaSetApi extends KubeApi<ReplicaSet> {
|
||||
protected getScaleApiUrl(params: { namespace: string; name: string }) {
|
||||
@ -123,6 +124,14 @@ export class ReplicaSet extends WorkloadKubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const replicaSetApi = new ReplicaSetApi({
|
||||
objectConstructor: ReplicaSet,
|
||||
});
|
||||
let replicaSetApi: ReplicaSetApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
replicaSetApi = new ReplicaSetApi({
|
||||
objectConstructor: ReplicaSet,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
replicaSetApi
|
||||
};
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface IResourceQuotaValues {
|
||||
[quota: string]: string;
|
||||
@ -80,6 +81,14 @@ export class ResourceQuota extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const resourceQuotaApi = new KubeApi({
|
||||
objectConstructor: ResourceQuota,
|
||||
});
|
||||
let resourceQuotaApi: KubeApi<ResourceQuota>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
resourceQuotaApi = new KubeApi<ResourceQuota>({
|
||||
objectConstructor: ResourceQuota,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
resourceQuotaApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { autoBind } from "../../utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export type RoleBindingSubjectKind = "Group" | "ServiceAccount" | "User";
|
||||
|
||||
@ -61,6 +62,14 @@ export class RoleBinding extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const roleBindingApi = new KubeApi({
|
||||
objectConstructor: RoleBinding,
|
||||
});
|
||||
let roleBindingApi: KubeApi<RoleBinding>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
roleBindingApi = new KubeApi({
|
||||
objectConstructor: RoleBinding,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
roleBindingApi
|
||||
};
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface Role {
|
||||
rules: {
|
||||
@ -41,6 +42,14 @@ export class Role extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const roleApi = new KubeApi({
|
||||
objectConstructor: Role,
|
||||
});
|
||||
let roleApi: KubeApi<Role>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
roleApi = new KubeApi<Role>({
|
||||
objectConstructor: Role,
|
||||
});
|
||||
}
|
||||
|
||||
export{
|
||||
roleApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export enum SecretType {
|
||||
Opaque = "Opaque",
|
||||
@ -69,6 +70,14 @@ export class Secret extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const secretsApi = new KubeApi({
|
||||
objectConstructor: Secret,
|
||||
});
|
||||
let secretsApi: KubeApi<Secret>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
secretsApi = new KubeApi({
|
||||
objectConstructor: Secret,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
secretsApi
|
||||
};
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class SelfSubjectRulesReviewApi extends KubeApi<SelfSubjectRulesReview> {
|
||||
create({ namespace = "default" }): Promise<SelfSubjectRulesReview> {
|
||||
@ -86,6 +87,15 @@ export class SelfSubjectRulesReview extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const selfSubjectRulesReviewApi = new SelfSubjectRulesReviewApi({
|
||||
objectConstructor: SelfSubjectRulesReview,
|
||||
});
|
||||
let selfSubjectRulesReviewApi: SelfSubjectRulesReviewApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
selfSubjectRulesReviewApi = new SelfSubjectRulesReviewApi({
|
||||
objectConstructor: SelfSubjectRulesReview,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
selfSubjectRulesReviewApi
|
||||
};
|
||||
|
||||
@ -23,6 +23,7 @@ import { autoBind } from "../../utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface ServiceAccount {
|
||||
secrets?: {
|
||||
@ -52,6 +53,14 @@ export class ServiceAccount extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceAccountsApi = new KubeApi<ServiceAccount>({
|
||||
objectConstructor: ServiceAccount,
|
||||
});
|
||||
let serviceAccountsApi: KubeApi<ServiceAccount>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
serviceAccountsApi = new KubeApi<ServiceAccount>({
|
||||
objectConstructor: ServiceAccount,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
serviceAccountsApi
|
||||
};
|
||||
@ -19,10 +19,11 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { autoBind } from "../../utils";
|
||||
import { autoBind } from "../../../renderer/utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface ServicePort {
|
||||
name?: string;
|
||||
@ -143,6 +144,14 @@ export class Service extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceApi = new KubeApi({
|
||||
objectConstructor: Service,
|
||||
});
|
||||
let serviceApi: KubeApi<Service>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
serviceApi = new KubeApi<Service>({
|
||||
objectConstructor: Service,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
serviceApi
|
||||
};
|
||||
@ -26,6 +26,7 @@ import { KubeApi } from "../kube-api";
|
||||
import { metricsApi } from "./metrics.api";
|
||||
import type { IPodContainer, IPodMetrics } from "./pods.api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export class StatefulSetApi extends KubeApi<StatefulSet> {
|
||||
protected getScaleApiUrl(params: { namespace: string; name: string }) {
|
||||
@ -149,6 +150,14 @@ export class StatefulSet extends WorkloadKubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const statefulSetApi = new StatefulSetApi({
|
||||
objectConstructor: StatefulSet,
|
||||
});
|
||||
let statefulSetApi: StatefulSetApi;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
statefulSetApi = new StatefulSetApi({
|
||||
objectConstructor: StatefulSet,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
statefulSetApi
|
||||
};
|
||||
@ -23,6 +23,7 @@ import { autoBind } from "../../utils";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
|
||||
export interface StorageClass {
|
||||
provisioner: string; // e.g. "storage.k8s.io/v1"
|
||||
@ -62,6 +63,14 @@ export class StorageClass extends KubeObject {
|
||||
}
|
||||
}
|
||||
|
||||
export const storageClassApi = new KubeApi({
|
||||
objectConstructor: StorageClass,
|
||||
});
|
||||
let storageClassApi: KubeApi<StorageClass>;
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
storageClassApi = new KubeApi({
|
||||
objectConstructor: StorageClass,
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
storageClassApi
|
||||
};
|
||||
67
src/common/k8s-api/index.ts
Normal file
67
src/common/k8s-api/index.ts
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JsonApi } from "./json-api";
|
||||
import { KubeJsonApi } from "./kube-json-api";
|
||||
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
|
||||
import { isClusterPageContext } from "../utils/cluster-id-url-parsing";
|
||||
|
||||
let apiBase: JsonApi;
|
||||
let apiKube: KubeJsonApi;
|
||||
|
||||
if (typeof window === "undefined") {
|
||||
apiBase = new JsonApi({
|
||||
serverAddress: `http://127.0.0.1:${process.env.LENS_PROXY_PORT}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": `localhost:${process.env.LENS_PROXY_PORT}`
|
||||
}
|
||||
});
|
||||
} else {
|
||||
apiBase = new JsonApi({
|
||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": window.location.host
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (isClusterPageContext()) {
|
||||
apiKube = new KubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDevelopment
|
||||
}, {
|
||||
headers: {
|
||||
"Host": window.location.host
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
apiBase,
|
||||
apiKube
|
||||
};
|
||||
@ -21,9 +21,11 @@
|
||||
|
||||
// Base http-service / json-api class
|
||||
|
||||
import { merge } from "lodash";
|
||||
import fetch, { Response, RequestInit } from "node-fetch";
|
||||
import { stringify } from "querystring";
|
||||
import { EventEmitter } from "../../common/event-emitter";
|
||||
import { randomBytes } from "crypto";
|
||||
import logger from "../../common/logger";
|
||||
|
||||
export interface JsonApiData {
|
||||
}
|
||||
@ -49,9 +51,9 @@ export interface JsonApiLog {
|
||||
|
||||
export interface JsonApiConfig {
|
||||
apiBase: string;
|
||||
serverAddress: string;
|
||||
debug?: boolean;
|
||||
}
|
||||
|
||||
export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
static reqInitDefault: RequestInit = {
|
||||
headers: {
|
||||
@ -63,9 +65,9 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
debug: false
|
||||
};
|
||||
|
||||
constructor(protected config: JsonApiConfig, protected reqInit?: RequestInit) {
|
||||
constructor(public readonly config: JsonApiConfig, protected reqInit?: RequestInit) {
|
||||
this.config = Object.assign({}, JsonApi.configDefault, config);
|
||||
this.reqInit = Object.assign({}, JsonApi.reqInitDefault, reqInit);
|
||||
this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit);
|
||||
this.parseResponse = this.parseResponse.bind(this);
|
||||
}
|
||||
|
||||
@ -77,10 +79,8 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
}
|
||||
|
||||
getResponse(path: string, params?: P, init: RequestInit = {}): Promise<Response> {
|
||||
const reqPath = `${this.config.apiBase}${path}`;
|
||||
const subdomain = randomBytes(2).toString("hex");
|
||||
let reqUrl = `http://${subdomain}.${window.location.host}${reqPath}`; // hack around browser connection limits (chromium allows 6 per domain)
|
||||
const reqInit: RequestInit = { ...init };
|
||||
let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
||||
const reqInit: RequestInit = merge({}, this.reqInit, init);
|
||||
const { query } = params || {} as P;
|
||||
|
||||
if (!reqInit.method) {
|
||||
@ -95,7 +95,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
|
||||
this.writeLog({
|
||||
method: reqInit.method.toUpperCase(),
|
||||
reqUrl: reqPath,
|
||||
reqUrl,
|
||||
reqInit,
|
||||
});
|
||||
|
||||
@ -119,8 +119,8 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
}
|
||||
|
||||
protected async request<D>(path: string, params?: P, init: RequestInit = {}) {
|
||||
let reqUrl = this.config.apiBase + path;
|
||||
const reqInit: RequestInit = { ...this.reqInit, ...init };
|
||||
let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
||||
const reqInit: RequestInit = merge({}, this.reqInit, init);
|
||||
const { data, query } = params || {} as P;
|
||||
|
||||
if (data && !reqInit.body) {
|
||||
@ -192,13 +192,9 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
||||
}
|
||||
|
||||
protected writeLog(log: JsonApiLog) {
|
||||
if (!this.config.debug) return;
|
||||
const { method, reqUrl, ...params } = log;
|
||||
let textStyle = "font-weight: bold;";
|
||||
|
||||
if (params.data) textStyle += "background: green; color: white;";
|
||||
if (params.error) textStyle += "background: red; color: white;";
|
||||
console.log(`%c${method} ${reqUrl}`, textStyle, params);
|
||||
logger.info(`[JSON-API] request ${method} ${reqUrl}`, params);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
|
||||
// Parse kube-api path and get api-version, group, etc.
|
||||
|
||||
import { splitArray } from "../../common/utils";
|
||||
import { isDebugging } from "../../common/vars";
|
||||
import { splitArray } from "../utils";
|
||||
import { isDebugging } from "../vars";
|
||||
import logger from "../../main/logger";
|
||||
import { inspect } from "util";
|
||||
|
||||
@ -66,7 +66,7 @@ export function parseKubeApi(path: string): IKubeApiParsed {
|
||||
}
|
||||
|
||||
function _parseKubeApi(path: string): IKubeApiParsed {
|
||||
const apiPath = new URL(path, location.origin).pathname;
|
||||
const apiPath = new URL(path, "http://localhost").pathname;
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
const [left, right, namespaced] = splitArray(parts, "namespaces");
|
||||
@ -23,17 +23,18 @@
|
||||
|
||||
import merge from "lodash/merge";
|
||||
import { stringify } from "querystring";
|
||||
import { apiKubePrefix, isDevelopment, isTestEnv } from "../../common/vars";
|
||||
import { apiKubePrefix, isDevelopment } from "../../common/vars";
|
||||
import logger from "../../main/logger";
|
||||
import { apiManager } from "./api-manager";
|
||||
import { apiKube } from "./index";
|
||||
import { apiBase, apiKube } from "./index";
|
||||
import { createKubeApiURL, parseKubeApi } from "./kube-api-parse";
|
||||
import { KubeObjectConstructor, KubeObject, KubeStatus } from "./kube-object";
|
||||
import byline from "byline";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-api";
|
||||
import { ReadableWebToNodeStream } from "../utils/readableStream";
|
||||
import { KubeJsonApi, KubeJsonApiData } from "./kube-json-api";
|
||||
import { noop } from "../utils";
|
||||
import type { RequestInit } from "node-fetch";
|
||||
import AbortController from "abort-controller";
|
||||
|
||||
export interface IKubeApiOptions<T extends KubeObject> {
|
||||
/**
|
||||
@ -96,11 +97,12 @@ export interface IKubeApiCluster {
|
||||
|
||||
export function forCluster<T extends KubeObject>(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor<T>): KubeApi<T> {
|
||||
const request = new KubeJsonApi({
|
||||
serverAddress: apiBase.config.serverAddress,
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDevelopment,
|
||||
}, {
|
||||
headers: {
|
||||
"X-Cluster-ID": cluster.metadata.uid
|
||||
"Host": apiBase.config.serverAddress
|
||||
}
|
||||
});
|
||||
|
||||
@ -168,7 +170,6 @@ export class KubeApi<T extends KubeObject> {
|
||||
this.request = request;
|
||||
this.objectConstructor = objectConstructor;
|
||||
|
||||
this.checkPreferredVersion();
|
||||
this.parseResponse = this.parseResponse.bind(this);
|
||||
apiManager.registerApi(apiBase, this);
|
||||
}
|
||||
@ -201,18 +202,9 @@ export class KubeApi<T extends KubeObject> {
|
||||
}
|
||||
} catch (error) {
|
||||
// Exception is ignored as we can try the next url
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid throwing in tests
|
||||
if (isTestEnv) {
|
||||
return {
|
||||
apiPrefix: this.apiPrefix,
|
||||
apiGroup: this.apiGroup
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`Can't find working API for the Kubernetes resource ${this.apiResource}`);
|
||||
}
|
||||
|
||||
@ -435,7 +427,7 @@ export class KubeApi<T extends KubeObject> {
|
||||
});
|
||||
|
||||
const watchUrl = this.getWatchUrl(namespace);
|
||||
const responsePromise = this.request.getResponse(watchUrl, null, { signal });
|
||||
const responsePromise = this.request.getResponse(watchUrl, null, { signal, timeout: 600_000 });
|
||||
|
||||
responsePromise
|
||||
.then(response => {
|
||||
@ -443,10 +435,8 @@ export class KubeApi<T extends KubeObject> {
|
||||
return callback(null, response);
|
||||
}
|
||||
|
||||
const nodeStream = new ReadableWebToNodeStream(response.body);
|
||||
|
||||
["end", "close", "error"].forEach((eventName) => {
|
||||
nodeStream.on(eventName, () => {
|
||||
response.body.on(eventName, () => {
|
||||
if (errorReceived) return; // kubernetes errors should be handled in a callback
|
||||
|
||||
clearTimeout(timedRetry);
|
||||
@ -456,7 +446,7 @@ export class KubeApi<T extends KubeObject> {
|
||||
});
|
||||
});
|
||||
|
||||
byline(nodeStream).on("data", (line) => {
|
||||
byline(response.body).on("data", (line) => {
|
||||
try {
|
||||
const event: IKubeWatchEvent<KubeJsonApiData> = JSON.parse(line);
|
||||
|
||||
@ -474,7 +464,7 @@ export class KubeApi<T extends KubeObject> {
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error instanceof DOMException) return; // AbortController rejects, we can ignore it
|
||||
if (error?.type === "aborted") return; // AbortController rejects, we can ignore it
|
||||
|
||||
callback(null, error);
|
||||
});
|
||||
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
import { JsonApi, JsonApiData, JsonApiError } from "./json-api";
|
||||
import type { Response } from "node-fetch";
|
||||
|
||||
export interface KubeJsonApiListMetadata {
|
||||
resourceVersion: string;
|
||||
@ -79,3 +80,4 @@ export class KubeJsonApi extends JsonApi<KubeJsonApiData> {
|
||||
return super.parseError(error, res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,18 +19,19 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import type { ClusterContext } from "./components/context";
|
||||
import type { ClusterContext } from "./cluster-context";
|
||||
|
||||
import { action, computed, makeObservable, observable, reaction, when } from "mobx";
|
||||
import { autoBind, noop, rejectPromiseBy } from "./utils";
|
||||
import { KubeObject, KubeStatus } from "./api/kube-object";
|
||||
import type { IKubeWatchEvent } from "./api/kube-watch-api";
|
||||
import { ItemStore } from "./item.store";
|
||||
import { apiManager } from "./api/api-manager";
|
||||
import { ensureObjectSelfLink, IKubeApiQueryParams, KubeApi } from "./api/kube-api";
|
||||
import { parseKubeApi } from "./api/kube-api-parse";
|
||||
import type { KubeJsonApiData } from "./api/kube-json-api";
|
||||
import { Notifications } from "./components/notifications";
|
||||
import { autoBind, noop, rejectPromiseBy } from "../utils";
|
||||
import { KubeObject, KubeStatus } from "./kube-object";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-api";
|
||||
import { ItemStore } from "../item.store";
|
||||
import { apiManager } from "./api-manager";
|
||||
import { ensureObjectSelfLink, IKubeApiQueryParams, KubeApi } from "./kube-api";
|
||||
import { parseKubeApi } from "./kube-api-parse";
|
||||
import type { KubeJsonApiData } from "./kube-json-api";
|
||||
import type { RequestInit } from "node-fetch";
|
||||
import AbortController from "abort-controller";
|
||||
|
||||
export interface KubeObjectStoreLoadingParams<K extends KubeObject> {
|
||||
namespaces: string[];
|
||||
@ -193,9 +194,6 @@ export abstract class KubeObjectStore<T extends KubeObject> extends ItemStore<T>
|
||||
|
||||
return items;
|
||||
} catch (error) {
|
||||
if (error.message) {
|
||||
Notifications.error(error.message);
|
||||
}
|
||||
console.warn("[KubeObjectStore] loadAll failed", this.api.apiBase, error);
|
||||
this.resetOnError(error);
|
||||
this.failedLoading = true;
|
||||
@ -348,7 +346,7 @@ export abstract class KubeObjectStore<T extends KubeObject> extends ItemStore<T>
|
||||
const { signal } = abortController;
|
||||
|
||||
const callback = (data: IKubeWatchEvent<T>, error: any) => {
|
||||
if (!this.isLoaded || error instanceof DOMException) return;
|
||||
if (!this.isLoaded || error?.type === "aborted") return;
|
||||
|
||||
if (error instanceof Response) {
|
||||
if (error.status === 404 || error.status === 401) {
|
||||
@ -22,15 +22,15 @@
|
||||
// Kubernetes watch-api client
|
||||
// API: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams
|
||||
|
||||
import type { KubeObjectStore } from "../kube-object.store";
|
||||
import type { ClusterContext } from "../components/context";
|
||||
import type { KubeObjectStore } from "./kube-object.store";
|
||||
import type { ClusterContext } from "./cluster-context";
|
||||
|
||||
import plimit from "p-limit";
|
||||
import { comparer, observable, reaction, makeObservable } from "mobx";
|
||||
import { autoBind, Disposer, noop } from "../utils";
|
||||
import type { KubeApi } from "./kube-api";
|
||||
import type { KubeJsonApiData } from "./kube-json-api";
|
||||
import { isDebugging, isProduction } from "../../common/vars";
|
||||
import { isDebugging, isProduction } from "../vars";
|
||||
import type { KubeObject } from "./kube-object";
|
||||
|
||||
export interface IKubeWatchEvent<T extends KubeJsonApiData> {
|
||||
81
src/common/logger.ts
Normal file
81
src/common/logger.ts
Normal file
@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { app, ipcMain, remote } from "electron";
|
||||
import winston from "winston";
|
||||
import { consoleFormat } from "winston-console-format";
|
||||
import { isDebugging, isTestEnv } from "./vars";
|
||||
import BrowserConsole from "winston-transport-browserconsole";
|
||||
|
||||
|
||||
const logLevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : isDebugging ? "debug" : "info";
|
||||
let consoleOptions: winston.transports.ConsoleTransportOptions;
|
||||
|
||||
if (ipcMain) {
|
||||
consoleOptions = {
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ level: true, message: false}),
|
||||
winston.format.padLevels(),
|
||||
winston.format.ms(),
|
||||
consoleFormat({
|
||||
showMeta: true,
|
||||
inspectOptions: {
|
||||
depth: 4,
|
||||
colors: true,
|
||||
maxArrayLength: 10,
|
||||
breakLength: 120,
|
||||
compact: Infinity,
|
||||
},
|
||||
})
|
||||
)
|
||||
};
|
||||
} else {
|
||||
consoleOptions = {
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ level: true, message: false}),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
const fileOptions: winston.transports.FileTransportOptions = {
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
filename: "lens.log",
|
||||
dirname: (app ?? remote?.app)?.getPath("logs"),
|
||||
maxsize: 16 * 1024,
|
||||
maxFiles: 16,
|
||||
tailable: true,
|
||||
};
|
||||
const logger = winston.createLogger({
|
||||
format: winston.format.combine(
|
||||
winston.format.simple()
|
||||
),
|
||||
transports: [
|
||||
ipcMain ? new winston.transports.Console(consoleOptions) : new BrowserConsole(),
|
||||
...(isTestEnv ? [] : [new winston.transports.File(fileOptions)]),
|
||||
],
|
||||
});
|
||||
|
||||
export default logger;
|
||||
@ -48,3 +48,12 @@ export function getClusterFrameUrl(clusterId: ClusterId) {
|
||||
export function getHostedClusterId(): ClusterId | undefined {
|
||||
return getClusterIdFromHost(location.host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true only if code is running within a cluster iframe context
|
||||
*/
|
||||
export function isClusterPageContext(): boolean {
|
||||
if (typeof window === "undefined") return false;
|
||||
|
||||
return !!getClusterIdFromHost(window.location.host);
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ export * from "./defineGlobal";
|
||||
export * from "./delay";
|
||||
export * from "./disposer";
|
||||
export * from "./downloadFile";
|
||||
export * from "./formatDuration";
|
||||
export * from "./escapeRegExp";
|
||||
export * from "./extended-map";
|
||||
export * from "./getRandId";
|
||||
@ -54,6 +55,8 @@ export * from "./toggle-set";
|
||||
export * from "./toJS";
|
||||
export * from "./type-narrowing";
|
||||
export * from "./types";
|
||||
export * from "./convertMemory";
|
||||
export * from "./convertCpu";
|
||||
|
||||
import * as iter from "./iter";
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ export const publicPath = "/build/" as string;
|
||||
// Webpack build paths
|
||||
export const contextDir = process.cwd();
|
||||
export const buildDir = path.join(contextDir, "static", publicPath);
|
||||
export const preloadEntrypoint = path.join(contextDir, "src/preload.ts");
|
||||
export const mainDir = path.join(contextDir, "src/main");
|
||||
export const rendererDir = path.join(contextDir, "src/renderer");
|
||||
export const htmlTemplate = path.resolve(rendererDir, "template.html");
|
||||
|
||||
@ -21,12 +21,14 @@
|
||||
|
||||
import * as Catalog from "./catalog";
|
||||
import * as Navigation from "./navigation";
|
||||
import * as K8sApi from "./k8s-api";
|
||||
import { IpcMain as Ipc } from "../ipc/ipc-main";
|
||||
import { LensMainExtension as LensExtension } from "../lens-main-extension";
|
||||
|
||||
export {
|
||||
Catalog,
|
||||
Navigation,
|
||||
K8sApi,
|
||||
Ipc,
|
||||
LensExtension,
|
||||
};
|
||||
|
||||
60
src/extensions/main-api/k8s-api.ts
Normal file
60
src/extensions/main-api/k8s-api.ts
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export { isAllowedResource } from "../../common/utils/allowed-resource";
|
||||
export { ResourceStack } from "../../common/k8s/resource-stack";
|
||||
export { apiManager } from "../../common/k8s-api/api-manager";
|
||||
export { KubeApi, forCluster } from "../../common/k8s-api/kube-api";
|
||||
export { KubeObject } from "../../common/k8s-api/kube-object";
|
||||
export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints/nodes.api";
|
||||
export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints/deployment.api";
|
||||
export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints/daemon-set.api";
|
||||
export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints/stateful-set.api";
|
||||
export { Job, jobApi } from "../../common/k8s-api/endpoints/job.api";
|
||||
export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints/cron-job.api";
|
||||
export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints/configmap.api";
|
||||
export { Secret, secretsApi } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints/replica-set.api";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints/resource-quota.api";
|
||||
export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints/limit-range.api";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints/hpa.api";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints/poddisruptionbudget.api";
|
||||
export { Service, serviceApi } from "../../common/k8s-api/endpoints/service.api";
|
||||
export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints/endpoint.api";
|
||||
export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints/ingress.api";
|
||||
export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints/network-policy.api";
|
||||
export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints/persistent-volume.api";
|
||||
export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints/persistent-volume-claims.api";
|
||||
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints/storage-class.api";
|
||||
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints/namespaces.api";
|
||||
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints/events.api";
|
||||
export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints/service-accounts.api";
|
||||
export { Role, roleApi } from "../../common/k8s-api/endpoints/role.api";
|
||||
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints/role-binding.api";
|
||||
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints/cluster-role.api";
|
||||
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints/cluster-role-binding.api";
|
||||
export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints/crd.api";
|
||||
|
||||
// types
|
||||
export type { IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export type { ISecretRef } from "../../common/k8s-api/endpoints/secret.api";
|
||||
@ -21,45 +21,45 @@
|
||||
|
||||
export { isAllowedResource } from "../../common/utils/allowed-resource";
|
||||
export { ResourceStack } from "../../common/k8s/resource-stack";
|
||||
export { apiManager } from "../../renderer/api/api-manager";
|
||||
export { KubeObjectStore } from "../../renderer/kube-object.store";
|
||||
export { KubeApi, forCluster } from "../../renderer/api/kube-api";
|
||||
export { KubeObject } from "../../renderer/api/kube-object";
|
||||
export { Pod, podsApi, PodsApi } from "../../renderer/api/endpoints";
|
||||
export { Node, nodesApi, NodesApi } from "../../renderer/api/endpoints";
|
||||
export { Deployment, deploymentApi, DeploymentApi } from "../../renderer/api/endpoints";
|
||||
export { DaemonSet, daemonSetApi } from "../../renderer/api/endpoints";
|
||||
export { StatefulSet, statefulSetApi } from "../../renderer/api/endpoints";
|
||||
export { Job, jobApi } from "../../renderer/api/endpoints";
|
||||
export { CronJob, cronJobApi } from "../../renderer/api/endpoints";
|
||||
export { ConfigMap, configMapApi } from "../../renderer/api/endpoints";
|
||||
export { Secret, secretsApi } from "../../renderer/api/endpoints";
|
||||
export { ReplicaSet, replicaSetApi } from "../../renderer/api/endpoints";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../renderer/api/endpoints";
|
||||
export { LimitRange, limitRangeApi } from "../../renderer/api/endpoints";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../renderer/api/endpoints";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../renderer/api/endpoints";
|
||||
export { Service, serviceApi } from "../../renderer/api/endpoints";
|
||||
export { Endpoint, endpointApi } from "../../renderer/api/endpoints";
|
||||
export { Ingress, ingressApi, IngressApi } from "../../renderer/api/endpoints";
|
||||
export { NetworkPolicy, networkPolicyApi } from "../../renderer/api/endpoints";
|
||||
export { PersistentVolume, persistentVolumeApi } from "../../renderer/api/endpoints";
|
||||
export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../renderer/api/endpoints";
|
||||
export { StorageClass, storageClassApi } from "../../renderer/api/endpoints";
|
||||
export { Namespace, namespacesApi } from "../../renderer/api/endpoints";
|
||||
export { KubeEvent, eventApi } from "../../renderer/api/endpoints";
|
||||
export { ServiceAccount, serviceAccountsApi } from "../../renderer/api/endpoints";
|
||||
export { Role, roleApi } from "../../renderer/api/endpoints";
|
||||
export { RoleBinding, roleBindingApi } from "../../renderer/api/endpoints";
|
||||
export { ClusterRole, clusterRoleApi } from "../../renderer/api/endpoints";
|
||||
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../renderer/api/endpoints";
|
||||
export { CustomResourceDefinition, crdApi } from "../../renderer/api/endpoints";
|
||||
export { apiManager } from "../../common/k8s-api/api-manager";
|
||||
export { KubeObjectStore } from "../../common/k8s-api/kube-object.store";
|
||||
export { KubeApi, forCluster } from "../../common/k8s-api/kube-api";
|
||||
export { KubeObject } from "../../common/k8s-api/kube-object";
|
||||
export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints";
|
||||
export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints";
|
||||
export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { Job, jobApi } from "../../common/k8s-api/endpoints";
|
||||
export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints";
|
||||
export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints";
|
||||
export { Secret, secretsApi } from "../../common/k8s-api/endpoints";
|
||||
export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints";
|
||||
export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints";
|
||||
export { Service, serviceApi } from "../../common/k8s-api/endpoints";
|
||||
export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints";
|
||||
export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints";
|
||||
export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints";
|
||||
export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints";
|
||||
export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints";
|
||||
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints";
|
||||
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints";
|
||||
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints";
|
||||
export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Role, roleApi } from "../../common/k8s-api/endpoints";
|
||||
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints";
|
||||
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints";
|
||||
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../common/k8s-api/endpoints";
|
||||
export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints";
|
||||
export { KubeObjectStatusLevel } from "./kube-object-status";
|
||||
|
||||
// types
|
||||
export type { IKubeApiCluster } from "../../renderer/api/kube-api";
|
||||
export type { IPodContainer, IPodContainerStatus } from "../../renderer/api/endpoints";
|
||||
export type { ISecretRef } from "../../renderer/api/endpoints";
|
||||
export type { IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints";
|
||||
export type { ISecretRef } from "../../common/k8s-api/endpoints";
|
||||
export type { KubeObjectStatus } from "./kube-object-status";
|
||||
|
||||
// stores
|
||||
|
||||
@ -25,7 +25,7 @@ import { HelmRepo, HelmRepoManager } from "./helm-repo-manager";
|
||||
import logger from "../logger";
|
||||
import { promiseExec } from "../promise-exec";
|
||||
import { helmCli } from "./helm-cli";
|
||||
import type { RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
import type { RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
|
||||
|
||||
type CachedYaml = {
|
||||
entries: RepoHelmChartList
|
||||
|
||||
@ -24,7 +24,7 @@ import type { Cluster } from "../cluster";
|
||||
import logger from "../logger";
|
||||
import { HelmRepoManager } from "./helm-repo-manager";
|
||||
import { HelmChartManager } from "./helm-chart-manager";
|
||||
import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../renderer/api/endpoints/helm-charts.api";
|
||||
import type { HelmChart, HelmChartList, RepoHelmChartList } from "../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { deleteRelease, getHistory, getRelease, getValues, installChart, listReleases, rollback, upgradeRelease } from "./helm-release-manager";
|
||||
import { iter, sortCompareChartVersions } from "../../common/utils";
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
import request, { RequestPromiseOptions } from "request-promise-native";
|
||||
import { apiKubePrefix } from "../common/vars";
|
||||
import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
|
||||
import type { IMetricsReqParams } from "../common/k8s-api/endpoints/metrics.api";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
import type { Cluster } from "./cluster";
|
||||
|
||||
|
||||
@ -97,6 +97,7 @@ export class LensProxy extends Singleton {
|
||||
});
|
||||
|
||||
this.port = port;
|
||||
process.env.LENS_PROXY_PORT = port.toString();
|
||||
resolve();
|
||||
})
|
||||
.once("error", (error) => {
|
||||
|
||||
@ -19,95 +19,6 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { app, remote } from "electron";
|
||||
import winston from "winston";
|
||||
import Transport from "winston-transport";
|
||||
import { isDebugging, isTestEnv } from "../common/vars";
|
||||
import { LEVEL } from "triple-beam";
|
||||
import { Severity } from "@sentry/browser";
|
||||
import * as Sentry from "@sentry/electron";
|
||||
import logger from "../common/logger";
|
||||
|
||||
const SENTRY_LEVELS_MAP = {
|
||||
silly: Severity.Debug,
|
||||
verbose: Severity.Debug,
|
||||
debug: Severity.Debug,
|
||||
info: Severity.Info,
|
||||
warn: Severity.Warning,
|
||||
error: Severity.Error,
|
||||
};
|
||||
const WINSTON_CMP: Record<WinstonLevel, Set<WinstonLevel>> = {
|
||||
silly: new Set(["silly", "verbose", "debug", "info", "warn", "error"]),
|
||||
verbose: new Set(["verbose", "debug", "info", "warn", "error"]),
|
||||
debug: new Set(["debug", "info", "warn", "error"]),
|
||||
info: new Set(["info", "warn", "error"]),
|
||||
warn: new Set(["warn", "error"]),
|
||||
error: new Set(["error"]),
|
||||
};
|
||||
|
||||
type WinstonLevel = keyof typeof SENTRY_LEVELS_MAP;
|
||||
|
||||
class SentryTransport extends Transport {
|
||||
logLevels: Set<WinstonLevel>;
|
||||
|
||||
constructor(minWinstonLevel: WinstonLevel) {
|
||||
super();
|
||||
|
||||
this.logLevels = WINSTON_CMP[minWinstonLevel];
|
||||
}
|
||||
|
||||
log(info: any, next: () => void) {
|
||||
setImmediate(() => {
|
||||
this.emit("logged", info);
|
||||
});
|
||||
|
||||
const { message, level: _, tags, user, ...extra } = info;
|
||||
const winstonLevel: WinstonLevel = info[LEVEL];
|
||||
const level = SENTRY_LEVELS_MAP[winstonLevel];
|
||||
|
||||
try {
|
||||
if (this.logLevels.has(winstonLevel)) {
|
||||
Sentry.captureMessage(message, {
|
||||
level,
|
||||
tags,
|
||||
extra,
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface CreateLoggerOpts extends winston.LoggerOptions {
|
||||
transports?: Transport[];
|
||||
}
|
||||
|
||||
const logLevel = process.env.LOG_LEVEL || (isDebugging ? "debug" : "info");
|
||||
|
||||
const loggerOpts: CreateLoggerOpts = {
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple(),
|
||||
),
|
||||
transports: [
|
||||
new SentryTransport("error"),
|
||||
new winston.transports.Console({
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
if (!isTestEnv) {
|
||||
loggerOpts.transports.push(new winston.transports.File({
|
||||
handleExceptions: false,
|
||||
level: logLevel,
|
||||
filename: "lens.log",
|
||||
dirname: (app ?? remote?.app)?.getPath("logs"),
|
||||
maxsize: 16 * 1024,
|
||||
maxFiles: 16,
|
||||
tailable: true,
|
||||
}));
|
||||
}
|
||||
|
||||
export default winston.createLogger(loggerOpts);
|
||||
export default logger;
|
||||
|
||||
@ -31,6 +31,7 @@ import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import logger from "./logger";
|
||||
import { productName } from "../common/vars";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
import * as path from "path";
|
||||
|
||||
function isHideable(window: BrowserWindow | null): boolean {
|
||||
return Boolean(window && !window.isDestroyed());
|
||||
@ -84,6 +85,7 @@ export class WindowManager extends Singleton {
|
||||
titleBarStyle: "hidden",
|
||||
backgroundColor: "#1e2124",
|
||||
webPreferences: {
|
||||
preload: path.join(__static, "build", "preload.js"),
|
||||
nodeIntegration: true,
|
||||
nodeIntegrationInSubFrames: true,
|
||||
enableRemoteModule: true,
|
||||
|
||||
26
src/preload.ts
Normal file
26
src/preload.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import fetch from "node-fetch";
|
||||
|
||||
export {
|
||||
fetch
|
||||
};
|
||||
@ -19,19 +19,12 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JsonApi, JsonApiErrorParsed } from "./json-api";
|
||||
import { KubeJsonApi } from "./kube-json-api";
|
||||
import type { JsonApiErrorParsed } from "../../common/k8s-api/json-api";
|
||||
import type { Response } from "node-fetch";
|
||||
import { Notifications } from "../components/notifications";
|
||||
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
|
||||
import { apiBase, apiKube } from "../../common/k8s-api";
|
||||
export { apiBase, apiKube } from "../../common/k8s-api";
|
||||
|
||||
export const apiBase = new JsonApi({
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
});
|
||||
export const apiKube = new KubeJsonApi({
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDevelopment,
|
||||
});
|
||||
|
||||
// Common handler for HTTP api errors
|
||||
export function onApiError(error: JsonApiErrorParsed, res: Response) {
|
||||
@ -43,5 +36,5 @@ export function onApiError(error: JsonApiErrorParsed, res: Response) {
|
||||
}
|
||||
}
|
||||
|
||||
apiBase.onError.addListener(onApiError);
|
||||
apiKube.onError.addListener(onApiError);
|
||||
if (apiBase) apiBase.onError.addListener(onApiError);
|
||||
if (apiKube) apiKube.onError.addListener(onApiError);
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
import "./helm-chart-details.scss";
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { getChartDetails, HelmChart } from "../../api/endpoints/helm-charts.api";
|
||||
import { getChartDetails, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { observable, autorun, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { Drawer, DrawerItem } from "../drawer";
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
import semver from "semver";
|
||||
import { observable, makeObservable } from "mobx";
|
||||
import { autoBind, sortCompareChartVersions } from "../../utils";
|
||||
import { getChartDetails, HelmChart, listCharts } from "../../api/endpoints/helm-charts.api";
|
||||
import { ItemStore } from "../../item.store";
|
||||
import { getChartDetails, HelmChart, listCharts } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { ItemStore } from "../../../common/item.store";
|
||||
import flatten from "lodash/flatten";
|
||||
|
||||
export interface IChartVersion {
|
||||
|
||||
@ -25,7 +25,7 @@ import React, { Component } from "react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { observer } from "mobx-react";
|
||||
import { helmChartStore } from "./helm-chart.store";
|
||||
import type { HelmChart } from "../../api/endpoints/helm-charts.api";
|
||||
import type { HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { HelmChartDetails } from "./helm-chart-details";
|
||||
import { navigation } from "../../navigation";
|
||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||
|
||||
@ -27,7 +27,7 @@ import isEqual from "lodash/isEqual";
|
||||
import { observable, reaction, makeObservable } from "mobx";
|
||||
import { Link } from "react-router-dom";
|
||||
import kebabCase from "lodash/kebabCase";
|
||||
import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../api/endpoints/helm-releases.api";
|
||||
import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import { HelmReleaseMenu } from "./release-menu";
|
||||
import { Drawer, DrawerItem, DrawerTitle } from "../drawer";
|
||||
import { Badge } from "../badge";
|
||||
@ -41,10 +41,10 @@ import { releaseStore } from "./release.store";
|
||||
import { Notifications } from "../notifications";
|
||||
import { createUpgradeChartTab } from "../dock/upgrade-chart.store";
|
||||
import { ThemeStore } from "../../theme.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { secretsStore } from "../+config-secrets/secrets.store";
|
||||
import { Secret } from "../../api/endpoints";
|
||||
import { Secret } from "../../../common/k8s-api/endpoints";
|
||||
import { getDetailsUrl } from "../kube-detail-params";
|
||||
import { Checkbox } from "../checkbox";
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import type { HelmRelease } from "../../api/endpoints/helm-releases.api";
|
||||
import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import { boundMethod, cssNames } from "../../utils";
|
||||
import { releaseStore } from "./release.store";
|
||||
import { MenuActions, MenuActionsProps } from "../menu/menu-actions";
|
||||
|
||||
@ -26,7 +26,7 @@ import { observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { Dialog, DialogProps } from "../dialog";
|
||||
import { Wizard, WizardStep } from "../wizard";
|
||||
import { getReleaseHistory, HelmRelease, IReleaseRevision } from "../../api/endpoints/helm-releases.api";
|
||||
import { getReleaseHistory, HelmRelease, IReleaseRevision } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import { releaseStore } from "./release.store";
|
||||
import { Select, SelectOption } from "../select";
|
||||
import { Notifications } from "../notifications";
|
||||
|
||||
@ -22,9 +22,9 @@
|
||||
import isEqual from "lodash/isEqual";
|
||||
import { action, observable, reaction, when, makeObservable } from "mobx";
|
||||
import { autoBind } from "../../utils";
|
||||
import { createRelease, deleteRelease, HelmRelease, IReleaseCreatePayload, IReleaseUpdatePayload, listReleases, rollbackRelease, updateRelease } from "../../api/endpoints/helm-releases.api";
|
||||
import { ItemStore } from "../../item.store";
|
||||
import type { Secret } from "../../api/endpoints";
|
||||
import { createRelease, deleteRelease, HelmRelease, IReleaseCreatePayload, IReleaseUpdatePayload, listReleases, rollbackRelease, updateRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import { ItemStore } from "../../../common/item.store";
|
||||
import type { Secret } from "../../../common/k8s-api/endpoints";
|
||||
import { secretsStore } from "../+config-secrets/secrets.store";
|
||||
import { namespaceStore } from "../+namespaces/namespace.store";
|
||||
import { Notifications } from "../notifications";
|
||||
|
||||
@ -26,7 +26,7 @@ import kebabCase from "lodash/kebabCase";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { releaseStore } from "./release.store";
|
||||
import type { HelmRelease } from "../../api/endpoints/helm-releases.api";
|
||||
import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import { ReleaseDetails } from "./release-details";
|
||||
import { ReleaseRollbackDialog } from "./release-rollback-dialog";
|
||||
import { navigation } from "../../navigation";
|
||||
|
||||
@ -25,14 +25,14 @@ import React from "react";
|
||||
import { action, computed, IReactionDisposer, makeObservable, observable, reaction } from "mobx";
|
||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalog-entity";
|
||||
import { ItemObject, ItemStore } from "../../item.store";
|
||||
import { ItemObject, ItemStore } from "../../../common/item.store";
|
||||
import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog";
|
||||
import { autoBind } from "../../../common/utils";
|
||||
import { Badge } from "../badge";
|
||||
import { navigation } from "../../navigation";
|
||||
import { searchUrlParam } from "../input";
|
||||
import { makeCss } from "../../../common/utils/makeCss";
|
||||
import { KubeObject } from "../../api/kube-object";
|
||||
import { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
|
||||
const css = makeCss(styles);
|
||||
|
||||
|
||||
@ -30,12 +30,12 @@ import { Table, TableCell, TableHead, TableRow } from "../table";
|
||||
import { nodesStore } from "../+nodes/nodes.store";
|
||||
import { eventStore } from "../+events/event.store";
|
||||
import { boundMethod, cssNames, prevDefault } from "../../utils";
|
||||
import type { ItemObject } from "../../item.store";
|
||||
import type { ItemObject } from "../../../common/item.store";
|
||||
import { Spinner } from "../spinner";
|
||||
import { ThemeStore } from "../../theme.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { kubeSelectedUrlParam, showDetails } from "../kube-detail-params";
|
||||
import { kubeWatchApi } from "../../api/kube-watch-api";
|
||||
import { kubeWatchApi } from "../../../common/k8s-api/kube-watch-api";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
|
||||
@ -31,7 +31,7 @@ import { Spinner } from "../spinner";
|
||||
import { ZebraStripes } from "../chart/zebra-stripes.plugin";
|
||||
import { ClusterNoMetrics } from "./cluster-no-metrics";
|
||||
import { ClusterMetricSwitchers } from "./cluster-metric-switchers";
|
||||
import { getMetricLastPoints } from "../../api/endpoints/metrics.api";
|
||||
import { getMetricLastPoints } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||
|
||||
export const ClusterMetrics = observer(() => {
|
||||
const { metricType, metricNodeRole, getMetricsValues, metricsLoaded, metrics } = clusterOverviewStore;
|
||||
|
||||
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
import { action, observable, reaction, when, makeObservable } from "mobx";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { Cluster, clusterApi, getMetricsByNodeNames, IClusterMetrics } from "../../api/endpoints";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { Cluster, clusterApi, getMetricsByNodeNames, IClusterMetrics } from "../../../common/k8s-api/endpoints";
|
||||
import { autoBind, createStorage } from "../../utils";
|
||||
import { IMetricsReqParams, normalizeMetrics } from "../../api/endpoints/metrics.api";
|
||||
import { IMetricsReqParams, normalizeMetrics } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||
import { nodesStore } from "../+nodes/nodes.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
|
||||
export enum MetricType {
|
||||
MEMORY = "memory",
|
||||
|
||||
@ -31,7 +31,7 @@ import { ChartData, PieChart } from "../chart";
|
||||
import { ClusterNoMetrics } from "./cluster-no-metrics";
|
||||
import { bytesToUnits } from "../../utils";
|
||||
import { ThemeStore } from "../../theme.store";
|
||||
import { getMetricLastPoints } from "../../api/endpoints/metrics.api";
|
||||
import { getMetricLastPoints } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||
|
||||
function createLabels(rawLabelData: [string, number | undefined][]): string[] {
|
||||
return rawLabelData.map(([key, value]) => `${key}: ${value?.toFixed(2) || "N/A"}`);
|
||||
|
||||
@ -28,9 +28,9 @@ import { DrawerItem, DrawerTitle } from "../drawer";
|
||||
import { Badge } from "../badge";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { cssNames } from "../../utils";
|
||||
import { HorizontalPodAutoscaler, HpaMetricType, IHpaMetric } from "../../api/endpoints/hpa.api";
|
||||
import { HorizontalPodAutoscaler, HpaMetricType, IHpaMetric } from "../../../common/k8s-api/endpoints/hpa.api";
|
||||
import { Table, TableCell, TableHead, TableRow } from "../table";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
import { getDetailsUrl } from "../kube-detail-params";
|
||||
|
||||
|
||||
@ -19,9 +19,9 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { HorizontalPodAutoscaler, hpaApi } from "../../api/endpoints/hpa.api";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { HorizontalPodAutoscaler, hpaApi } from "../../../common/k8s-api/endpoints/hpa.api";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
|
||||
export class HPAStore extends KubeObjectStore<HorizontalPodAutoscaler> {
|
||||
api = hpaApi;
|
||||
|
||||
@ -25,7 +25,7 @@ import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router";
|
||||
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
||||
import type { HorizontalPodAutoscaler } from "../../api/endpoints/hpa.api";
|
||||
import type { HorizontalPodAutoscaler } from "../../../common/k8s-api/endpoints/hpa.api";
|
||||
import { hpaStore } from "./hpa.store";
|
||||
import { Badge } from "../badge";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
@ -24,7 +24,7 @@ import "./limit-range-details.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import { LimitPart, LimitRange, LimitRangeItem, Resource } from "../../api/endpoints/limit-range.api";
|
||||
import { LimitPart, LimitRange, LimitRangeItem, Resource } from "../../../common/k8s-api/endpoints/limit-range.api";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
import { DrawerItem } from "../drawer/drawer-item";
|
||||
import { Badge } from "../badge";
|
||||
|
||||
@ -19,9 +19,9 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { LimitRange, limitRangeApi } from "../../api/endpoints/limit-range.api";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
import { LimitRange, limitRangeApi } from "../../../common/k8s-api/endpoints/limit-range.api";
|
||||
|
||||
export class LimitRangesStore extends KubeObjectStore<LimitRange> {
|
||||
api = limitRangeApi;
|
||||
|
||||
@ -30,7 +30,7 @@ import { Input } from "../input";
|
||||
import { Button } from "../button";
|
||||
import { configMapsStore } from "./config-maps.store";
|
||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||
import type { ConfigMap } from "../../api/endpoints";
|
||||
import type { ConfigMap } from "../../../common/k8s-api/endpoints";
|
||||
import { KubeObjectMeta } from "../kube-object-meta";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<ConfigMap> {
|
||||
|
||||
@ -19,9 +19,9 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { ConfigMap, configMapApi } from "../../api/endpoints/configmap.api";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { ConfigMap, configMapApi } from "../../../common/k8s-api/endpoints/configmap.api";
|
||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||
|
||||
export class ConfigMapsStore extends KubeObjectStore<ConfigMap> {
|
||||
api = configMapApi;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user