1
0
mirror of https://github.com/lensapp/lens.git synced 2024-11-28 11:53:41 +03:00

Extract pod metrics and cluster frame context

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
This commit is contained in:
Sami Tiilikainen 2023-06-01 12:10:28 +03:00
parent 323b3759fc
commit 3c16777784
24 changed files with 133 additions and 19 deletions

20
package-lock.json generated
View File

@ -3711,6 +3711,10 @@
"resolved": "packages/ui-components/button",
"link": true
},
"node_modules/@k8slens/cluster-frame-context": {
"resolved": "packages/cluster-frame-context",
"link": true
},
"node_modules/@k8slens/cluster-settings": {
"resolved": "packages/cluster-settings",
"link": true
@ -34177,6 +34181,20 @@
"react": "^17 || ^18"
}
},
"packages/cluster-frame-context": {
"version": "1.0.0-alpha.1",
"license": "MIT",
"devDependencies": {
"@k8slens/eslint-config": "^6.5.0-alpha.3",
"@k8slens/jest": "^6.5.0-alpha.5",
"@k8slens/typescript": "^6.5.0-alpha.2",
"@k8slens/webpack": "^6.5.0-alpha.5"
},
"peerDependencies": {
"@ogre-tools/injectable": "^17.2.0",
"react": "^17.0.2"
}
},
"packages/cluster-settings": {
"name": "@k8slens/cluster-settings",
"version": "6.5.0",
@ -34326,11 +34344,13 @@
"@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
"@k8slens/button": "^1.0.0-alpha.5",
"@k8slens/cluster-frame-context": "^1.0.0-alpha.1",
"@k8slens/cluster-settings": "^6.5.0-alpha.1",
"@k8slens/cluster-sidebar": "^1.0.0",
"@k8slens/error-boundary": "^1.0.0-alpha.5",
"@k8slens/event-emitter": "^1.0.0-alpha.1",
"@k8slens/icon": "^1.0.0-alpha.7",
"@k8slens/json-api": "^1.0.0-alpha.3",
"@k8slens/kube-api": "^1.0.0-alpha.1",
"@k8slens/kube-api-specifics": "^1.0.0-alpha.1",
"@k8slens/kube-object": "^1.0.0-alpha.5",

View File

@ -0,0 +1,6 @@
module.exports = {
extends: "@k8slens/eslint-config/eslint",
parserOptions: {
project: "./tsconfig.json",
},
};

View File

@ -0,0 +1 @@
"@k8slens/eslint-config/prettier"

View File

@ -0,0 +1,4 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

View File

@ -0,0 +1,2 @@
export { clusterFrameContextForClusterScopedResourcesInjectionToken } from "./src/token";
export type { ClusterContext } from "./src/types";

View File

@ -0,0 +1 @@
module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;

View File

@ -0,0 +1,44 @@
{
"name": "@k8slens/cluster-frame-context",
"private": false,
"version": "1.0.0-alpha.1",
"description": "Injection tokens for cluster frame context",
"type": "commonjs",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/lensapp/lens.git"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": {
"name": "OpenLens Authors",
"email": "info@k8slens.dev"
},
"license": "MIT",
"homepage": "https://github.com/lensapp/lens",
"scripts": {
"build": "lens-webpack-build",
"clean": "rimraf dist/",
"dev": "webpack --mode=development --watch",
"test": "jest --coverage --runInBand",
"lint": "lens-lint",
"lint:fix": "lens-lint --fix"
},
"peerDependencies": {
"@ogre-tools/injectable": "^17.2.0",
"react": "^17.0.2"
},
"devDependencies": {
"@k8slens/eslint-config": "^6.5.0-alpha.3",
"@k8slens/jest": "^6.5.0-alpha.5",
"@k8slens/typescript": "^6.5.0-alpha.2",
"@k8slens/webpack": "^6.5.0-alpha.5"
}
}

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { ClusterContext } from "./types";
export const clusterFrameContextForClusterScopedResourcesInjectionToken = getInjectionToken<ClusterContext>({
id: "cluster-frame-context-for-cluster-scoped-resources-injection-token",
});

View File

@ -1,11 +1,3 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
/**
* This type is used for KubeObjectStores
*/
export interface ClusterContext {
readonly allNamespaces: string[]; // available / allowed namespaces from cluster.ts
readonly contextNamespaces: string[]; // selected by user (see: namespace-select.tsx)

View File

@ -0,0 +1,4 @@
{
"extends": "@k8slens/typescript/config/base.json",
"include": ["**/*.ts"]
}

View File

@ -0,0 +1 @@
module.exports = require("@k8slens/webpack").configForNode;

View File

@ -211,11 +211,13 @@
"@k8slens/application": "^6.5.0-alpha.0",
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
"@k8slens/button": "^1.0.0-alpha.5",
"@k8slens/cluster-frame-context": "^1.0.0-alpha.1",
"@k8slens/cluster-settings": "^6.5.0-alpha.1",
"@k8slens/cluster-sidebar": "^1.0.0",
"@k8slens/error-boundary": "^1.0.0-alpha.5",
"@k8slens/event-emitter": "^1.0.0-alpha.1",
"@k8slens/icon": "^1.0.0-alpha.7",
"@k8slens/json-api": "^1.0.0-alpha.3",
"@k8slens/kube-api": "^1.0.0-alpha.1",
"@k8slens/kube-api-specifics": "^1.0.0-alpha.1",
"@k8slens/kube-object": "^1.0.0-alpha.5",

View File

@ -16,7 +16,7 @@ import type { Patch } from "rfc6902";
import type { Logger } from "@k8slens/logger";
import assert from "assert";
import type { PartialDeep } from "type-fest";
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
import autoBind from "auto-bind";
export type OnLoadFailure = (error: unknown) => void;

View File

@ -19,7 +19,7 @@ import { KubeObjectStore as InternalKubeObjectStore } from "../../common/k8s-api
import type { KubeJsonApiDataFor, KubeObject } from "@k8slens/kube-object";
import type { DerivedKubeApiOptions, KubeApiDependencies, KubeApiOptions, KubeJsonApi as InternalKubeJsonApi } from "@k8slens/kube-api";
import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable";
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
import { logErrorInjectionToken, loggerInjectionToken, logInfoInjectionToken, logWarningInjectionToken } from "@k8slens/logger";
import { maybeKubeApiInjectable, storesAndApisCanBeCreatedInjectionToken } from "@k8slens/kube-api-specifics";
import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi, KubeApi as InternalKubeApi } from "@k8slens/kube-api";

View File

@ -2,8 +2,9 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { clusterFrameContextForClusterScopedResourcesInjectionToken } from "@k8slens/cluster-frame-context";
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterContext } from "./cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
const clusterFrameContextForClusterScopedResourcesInjectable = getInjectable({
id: "cluster-frame-context-for-cluster-scoped-resources",
@ -16,6 +17,7 @@ const clusterFrameContextForClusterScopedResourcesInjectable = getInjectable({
contextNamespaces: [],
hasSelectedAll: true,
}),
injectionToken: clusterFrameContextForClusterScopedResourcesInjectionToken,
});
export default clusterFrameContextForClusterScopedResourcesInjectable;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterContext } from "./cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
import namespaceStoreInjectable from "../components/namespaces/store.injectable";
import hostedClusterInjectable from "./hosted-cluster.injectable";
import assert from "assert";

View File

@ -27,7 +27,7 @@ import type { PageParam } from "../../navigation/page-param";
import type { ToggleKubeDetailsPane } from "../kube-detail-params/toggle-details.injectable";
import kubeSelectedUrlParamInjectable from "../kube-detail-params/kube-selected-url.injectable";
import toggleKubeDetailsPaneInjectable from "../kube-detail-params/toggle-details.injectable";
import type { ClusterContext } from "../../cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
import type { GeneralKubeObjectListLayoutColumn, SpecificKubeListLayoutColumn } from "@k8slens/list-layout";
import { kubeObjectListLayoutColumnInjectionToken } from "@k8slens/list-layout";
import { sortBy } from "lodash";

View File

@ -11,7 +11,7 @@ import { Icon } from "@k8slens/icon";
import type { SelectOption } from "../../select";
import { observableCrate } from "@k8slens/utilities";
import type { IsMultiSelectionKey } from "./is-selection-key.injectable";
import type { ClusterContext } from "../../../cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
interface Dependencies {
context: ClusterContext;

View File

@ -14,7 +14,7 @@ import { cssNames } from "@k8slens/utilities";
import { Icon } from "@k8slens/icon";
import { withInjectables } from "@ogre-tools/injectable-react";
import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable";
import type { ClusterContext } from "../../cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
export type NamespaceSelectSort = (left: string, right: string) => number;

View File

@ -34,7 +34,7 @@ import jobStoreInjectable from "../workloads-jobs/store.injectable";
import statefulSetStoreInjectable from "../workloads-statefulsets/store.injectable";
import type { EventStore } from "../events/store";
import eventStoreInjectable from "../events/store.injectable";
import type { ClusterContext } from "../../cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
interface Dependencies {
detailComponents: IComputedValue<React.ElementType<{}>[]>;

View File

@ -8,7 +8,7 @@ import { disposer, getOrInsert, noop, WrappedAbortController } from "@k8slens/ut
import { once } from "lodash";
import type { Logger } from "@k8slens/logger";
import type { KubeObjectStoreLoadAllParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
import type { ClusterContext } from "../cluster-frame-context/cluster-frame-context";
import type { ClusterContext } from "@k8slens/cluster-frame-context";
// Kubernetes watch-api client
// API: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { PodMetricsApi } from "@k8slens/kube-api";
export const podMetricsApiInjectionToken = getInjectionToken<PodMetricsApi>({
id: "pod-metrics-api-injection-token",
});

View File

@ -6,9 +6,9 @@ import { getInjectable } from "@ogre-tools/injectable";
import assert from "assert";
import { storesAndApisCanBeCreatedInjectionToken } from "./can-be-created-token";
import { PodMetricsApi } from "@k8slens/kube-api";
import { kubeApiInjectionToken } from "./token";
import { logErrorInjectionToken, logInfoInjectionToken, logWarningInjectionToken } from "@k8slens/logger";
import { maybeKubeApiInjectable } from "./maybe-kube-api.injectable";
import { podMetricsApiInjectionToken } from "./pod-metrics-api-injection-token";
export const podMetricsApiInjectable = getInjectable({
id: "pod-metrics-api",
@ -26,5 +26,5 @@ export const podMetricsApiInjectable = getInjectable({
});
},
injectionToken: kubeApiInjectionToken,
injectionToken: podMetricsApiInjectionToken,
});

View File

@ -0,0 +1,15 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { kubeApiInjectionToken } from "@k8slens/kube-api-specifics";
import { podMetricsApiInjectable } from "./pod-metrics.api.injectable";
const podMetricsKubeApiInjectable = getInjectable({
id: "pod-metrics-kube-api",
instantiate: (di) => di.inject(podMetricsApiInjectable),
injectionToken: kubeApiInjectionToken,
});
export default podMetricsKubeApiInjectable;