-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve SelfSubjectRulesReview globs
Signed-off-by: Andreas Hippler <[email protected]>
- Loading branch information
Showing
6 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import type { | ||
V1APIGroupList, | ||
V1APIResourceList, | ||
} from "@kubernetes/client-node"; | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import type { K8sRequest } from "../../main/k8s-request.injectable"; | ||
import k8SRequestInjectable from "../../main/k8s-request.injectable"; | ||
import type { Logger } from "../logger"; | ||
import loggerInjectable from "../logger.injectable"; | ||
import type { KubeApiResource, KubeResource } from "../rbac"; | ||
import type { Cluster } from "./cluster"; | ||
import plimit from "p-limit"; | ||
|
||
export type RequestListApiResources = () => Promise<KubeApiResource[]>; | ||
|
||
/** | ||
* @param proxyConfig This config's `currentContext` field must be set, and will be used as the target cluster | ||
*/ | ||
export type ListApiResources = (cluster: Cluster) => RequestListApiResources; | ||
|
||
interface Dependencies { | ||
logger: Logger; | ||
k8sRequest: K8sRequest; | ||
} | ||
|
||
const listApiResources = ({ k8sRequest, logger }: Dependencies): ListApiResources => { | ||
return (cluster) => { | ||
const clusterRequest = (path: string) => k8sRequest(cluster, path); | ||
const apiLimit = plimit(5); | ||
|
||
return async () => { | ||
const resources: KubeApiResource[] = []; | ||
|
||
try { | ||
const response = (await clusterRequest("/apis")) as V1APIGroupList; | ||
|
||
const requests: Promise<void>[] = []; | ||
|
||
if (!response.groups) { | ||
return resources; | ||
} | ||
|
||
for (const group of response.groups) { | ||
const endPoint = group.preferredVersion?.groupVersion; | ||
|
||
if (endPoint === undefined) { | ||
continue; | ||
} | ||
|
||
requests.push(apiLimit(async () => { | ||
const apiResources = (await clusterRequest(`/apis/${endPoint}`)) as V1APIResourceList; | ||
|
||
if (apiResources.resources) { | ||
resources.push( | ||
...apiResources.resources.map((resource) => ({ | ||
apiName: resource.name as KubeResource, | ||
group: group.name, | ||
kind: resource.kind, | ||
})), | ||
); | ||
} | ||
})); | ||
} | ||
|
||
await Promise.all(requests); | ||
} catch (error) { | ||
logger.error(`[LIST-API-RESOURCES]: failed to list api resources: ${error}`); | ||
} | ||
|
||
return resources; | ||
}; | ||
}; | ||
}; | ||
|
||
const listApiResourcesInjectable = getInjectable({ | ||
id: "list-api-resources", | ||
instantiate: (di) => { | ||
const k8sRequest = di.inject(k8SRequestInjectable); | ||
const logger = di.inject(loggerInjectable); | ||
|
||
return listApiResources({ k8sRequest, logger }); | ||
}, | ||
}); | ||
|
||
export default listApiResourcesInjectable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters