mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix allowed resources checks on GKE (#6657)
* Add check for incomplete SelfSubjectRulesReview to fix GKE Signed-off-by: Sebastian Malton <sebastian@malton.name> * Adding namespaced for KubeApiResource Signed-off-by: Sebastian Malton <sebastian@malton.name> * Refactoring of AuthorizationNamespaceReview Signed-off-by: Sebastian Malton <sebastian@malton.name> * Removing dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Refactoring ListApiResources Signed-off-by: Sebastian Malton <sebastian@malton.name> * Extract ClusterContext into deps for KubeObjectStore to fix circular import Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix remaining type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix crash in frame by consolidating setup into runnables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors and remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix core resources not showing up Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix namespaces not being shown Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify ClusterContext to remove something only NamespaceStore needs Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make sure the public API doesn't change Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixing namespace-select-filter tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix other tests requiring overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix kludge in cluster-frame tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix remaining test failures Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration test due to incorrect casting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration test and kube watches not working at all Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix secret details test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix non-ApplicationBuilder tests by adding overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix crash due to trying to read hostedCluster too soon Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix crash due to timing issues - Make injectable phases more explicit for renderer Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
e36f3d2d70
commit
443081493b
196 files changed
+2379
-2146
No files matched your search
@@ -12,6 +12,7 @@ import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import workloadsInjectable from "./workloads/workloads.injectable";
|
||||
import type { Workload } from "./workloads/workload-injection-token";
|
||||
import { formatKubeApiResource } from "../../../common/rbac";
|
||||
|
||||
export interface OverviewStatusesProps {}
|
||||
|
||||
@@ -24,7 +25,7 @@ const NonInjectedOverviewStatuses = observer(
|
||||
<div className="OverviewStatuses">
|
||||
<div className="workloads">
|
||||
{workloads.get().map((workload) => (
|
||||
<div className="workload" key={workload.resourceName}>
|
||||
<div className="workload" key={formatKubeApiResource(workload.resource)}>
|
||||
<div className="title">
|
||||
<a onClick={workload.open}>
|
||||
{`${workload.title} (${workload.amountOfItems.get()})`}
|
||||
|
||||
@@ -17,8 +17,7 @@ import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
|
||||
import { Icon } from "../icon";
|
||||
import { TooltipPosition } from "../tooltip";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
|
||||
import type { ClusterFrameContext } from "../../cluster-frame-context/cluster-frame-context";
|
||||
import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable";
|
||||
import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api";
|
||||
import workloadOverviewDetailsInjectable from "./workload-overview-details/workload-overview-details.injectable";
|
||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||
@@ -35,10 +34,11 @@ 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";
|
||||
|
||||
interface Dependencies {
|
||||
detailComponents: IComputedValue<React.ElementType<{}>[]>;
|
||||
clusterFrameContext: ClusterFrameContext;
|
||||
clusterFrameContext: ClusterContext;
|
||||
subscribeStores: SubscribeStores;
|
||||
podStore: PodStore;
|
||||
daemonSetStore: DaemonSetStore;
|
||||
@@ -123,7 +123,7 @@ class NonInjectedWorkloadsOverview extends React.Component<Dependencies> {
|
||||
export const WorkloadsOverview = withInjectables<Dependencies>(NonInjectedWorkloadsOverview, {
|
||||
getProps: (di) => ({
|
||||
detailComponents: di.inject(workloadOverviewDetailsInjectable),
|
||||
clusterFrameContext: di.inject(clusterFrameContextInjectable),
|
||||
clusterFrameContext: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
|
||||
subscribeStores: di.inject(subscribeStoresInjectable),
|
||||
daemonSetStore: di.inject(daemonSetStoreInjectable),
|
||||
podStore: di.inject(podStoreInjectable),
|
||||
|
||||
+4
-4
@@ -19,17 +19,17 @@ const cronJobsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(cronJobsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "cronjobs",
|
||||
resource: {
|
||||
apiName: "cronjobs",
|
||||
group: "batch",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
|
||||
),
|
||||
|
||||
status: computed(() =>
|
||||
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
|
||||
),
|
||||
|
||||
title: ResourceNames.cronjobs,
|
||||
orderNumber: 70,
|
||||
};
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const daemonsetsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(daemonsetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "daemonsets",
|
||||
resource: {
|
||||
apiName: "daemonsets",
|
||||
group: "apps",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const deploymentsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(deploymentsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "deployments",
|
||||
resource: {
|
||||
apiName: "deployments",
|
||||
group: "apps",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const jobsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(jobStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "jobs",
|
||||
resource: {
|
||||
apiName: "jobs",
|
||||
group: "batch",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const podsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(podStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "pods",
|
||||
resource: {
|
||||
apiName: "pods",
|
||||
group: "v1",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const replicasetsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(replicasetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "replicasets",
|
||||
resource: {
|
||||
apiName: "replicasets",
|
||||
group: "apps",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
+4
-1
@@ -19,7 +19,10 @@ const statefulsetsWorkloadInjectable = getInjectable({
|
||||
const store = di.inject(statefulsetsStoreInjectable);
|
||||
|
||||
return {
|
||||
resourceName: "statefulsets",
|
||||
resource: {
|
||||
apiName: "statefulsets",
|
||||
group: "apps",
|
||||
},
|
||||
open: navigate,
|
||||
|
||||
amountOfItems: computed(
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import type { KubeApiResourceDescriptor } from "../../../../common/rbac";
|
||||
import type { WorkloadStatus } from "../overview-workload-status";
|
||||
|
||||
export interface Workload {
|
||||
resourceName: string;
|
||||
resource: KubeApiResourceDescriptor;
|
||||
open: () => void;
|
||||
amountOfItems: IComputedValue<number>;
|
||||
status: IComputedValue<WorkloadStatus>;
|
||||
|
||||
@@ -2,18 +2,11 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { filter, sortBy as sortByWithBadTyping } from "lodash/fp";
|
||||
import { computed } from "mobx";
|
||||
import type { Workload } from "./workload-injection-token";
|
||||
import { shouldShowResourceInjectionToken } from "../../../../common/cluster-store/allowed-resources-injection-token";
|
||||
import { byOrderNumber } from "../../../../common/utils/composable-responsibilities/orderable/orderable";
|
||||
import { workloadInjectionToken } from "./workload-injection-token";
|
||||
import isAllowedResourceInjectable from "../../../../common/utils/is-allowed-resource.injectable";
|
||||
|
||||
const sortBy =
|
||||
(propertyPath: string) =>
|
||||
<Collection extends object>(collection: Collection[]) =>
|
||||
sortByWithBadTyping(propertyPath, collection);
|
||||
|
||||
const workloadsInjectable = getInjectable({
|
||||
id: "workloads",
|
||||
@@ -21,22 +14,11 @@ const workloadsInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const workloads = di.injectMany(workloadInjectionToken);
|
||||
|
||||
const isAllowedResource = (resourceName: string) =>
|
||||
di.inject(isAllowedResourceInjectable, resourceName);
|
||||
|
||||
return computed(() =>
|
||||
pipeline(
|
||||
workloads,
|
||||
|
||||
filter((workload: Workload) => {
|
||||
const isAllowed = isAllowedResource(workload.resourceName);
|
||||
|
||||
return isAllowed.get();
|
||||
}),
|
||||
|
||||
sortBy("orderNumber"),
|
||||
),
|
||||
);
|
||||
return computed(() => (
|
||||
workloads
|
||||
.filter(w => di.inject(shouldShowResourceInjectionToken, w.resource).get())
|
||||
.sort(byOrderNumber)
|
||||
));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user