mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
use api groups
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
b87e750610
commit
8b5ccec50e
@ -5,6 +5,30 @@ import { getAppVersion } from "../../common/app-utils"
|
|||||||
import { CoreV1Api, AuthorizationV1Api } from "@kubernetes/client-node"
|
import { CoreV1Api, AuthorizationV1Api } from "@kubernetes/client-node"
|
||||||
import { Cluster } from "../cluster"
|
import { Cluster } from "../cluster"
|
||||||
|
|
||||||
|
// TODO: auto-populate all resources dynamically
|
||||||
|
const apiResources = [
|
||||||
|
{ resource: "configmaps" },
|
||||||
|
{ resource: "cronjobs", group: "batch" },
|
||||||
|
{ resource: "customresourcedefinitions", group: "apiextensions.k8s.io" },
|
||||||
|
{ resource: "daemonsets", group: "apps" },
|
||||||
|
{ resource: "deployments", group: "apps" },
|
||||||
|
{ resource: "endpoints" },
|
||||||
|
{ resource: "horizontalpodautoscalers" },
|
||||||
|
{ resource: "ingresses", group: "networking.k8s.io" },
|
||||||
|
{ resource: "jobs", group: "batch" },
|
||||||
|
{ resource: "namespaces" },
|
||||||
|
{ resource: "networkpolicies", group: "networking.k8s.io" },
|
||||||
|
{ resource: "nodes" },
|
||||||
|
{ resource: "persistentvolumes" },
|
||||||
|
{ resource: "pods" },
|
||||||
|
{ resource: "podsecuritypolicies" },
|
||||||
|
{ resource: "resourcequotas" },
|
||||||
|
{ resource: "secrets" },
|
||||||
|
{ resource: "services" },
|
||||||
|
{ resource: "statefulsets", group: "apps" },
|
||||||
|
{ resource: "storageclasses", group: "storage.k8s.io" },
|
||||||
|
]
|
||||||
|
|
||||||
async function getAllowedNamespaces(cluster: Cluster) {
|
async function getAllowedNamespaces(cluster: Cluster) {
|
||||||
const api = cluster.contextHandler.kc.makeApiClient(CoreV1Api)
|
const api = cluster.contextHandler.kc.makeApiClient(CoreV1Api)
|
||||||
try {
|
try {
|
||||||
@ -31,39 +55,17 @@ async function getAllowedNamespaces(cluster: Cluster) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getAllowedResources(cluster: Cluster, namespaces: string[]) {
|
async function getAllowedResources(cluster: Cluster, namespaces: string[]) {
|
||||||
// TODO: auto-populate all resources dynamically
|
|
||||||
const resources = [
|
|
||||||
"configmaps",
|
|
||||||
"cronjobs",
|
|
||||||
"customresourcedefinitions",
|
|
||||||
"daemonsets",
|
|
||||||
"deployments",
|
|
||||||
"endpoints",
|
|
||||||
"horizontalpodautoscalers",
|
|
||||||
"ingresses",
|
|
||||||
"jobs",
|
|
||||||
"namespaces",
|
|
||||||
"networkpolicies",
|
|
||||||
"nodes",
|
|
||||||
"persistentvolumes",
|
|
||||||
"pods",
|
|
||||||
"podsecuritypolicies",
|
|
||||||
"resourcequotas",
|
|
||||||
"secrets",
|
|
||||||
"services",
|
|
||||||
"statefulsets",
|
|
||||||
"storageclasses",
|
|
||||||
]
|
|
||||||
try {
|
try {
|
||||||
const resourceAccessStatuses = await Promise.all(
|
const resourceAccessStatuses = await Promise.all(
|
||||||
resources.map(resource => cluster.canI({
|
apiResources.map(apiResource => cluster.canI({
|
||||||
resource: resource,
|
resource: apiResource.resource,
|
||||||
|
group: apiResource.group,
|
||||||
verb: "list",
|
verb: "list",
|
||||||
namespace: namespaces[0]
|
namespace: namespaces[0]
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
return resources
|
return apiResources
|
||||||
.filter((resource, i) => resourceAccessStatuses[i])
|
.filter((resource, i) => resourceAccessStatuses[i]).map(apiResource => apiResource.resource)
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user