Hi everyone I'm developing a Rancher UI extension ...
# extensions
b
Hi everyone I'm developing a Rancher UI extension and planning to add it as a Top-Level Product. I wanted to ask: • From a top-level product extension, is it possible to access Kubernetes cluster resources (like pods, CRDs, etc.) using Rancher's API ? • If so, is there any documentation or example that shows how to do this properly?
b
You can, but it’s a bit hacky though…. You’ll have to find out what the URL is, then you can use the store action
management/request
, like:
this.$store.dispatch('management/request', { url: '/k8s/clusters/local/v1/pods?exclude=metadata.managedFields' });
Just replace
local
with the CLUSTER MANAGEMENT ID for the cluster you want to get those resource from
management.cattle.io.cluster
You can get the list of all those with:
this.$store.dispatch('management/findAll', { type: management.cattle.io.cluster })
If you want to work in the context of a cluster, you use the cluster store (the cluster is always the one you’ve navigated into, which the system get’s “automatically” and you can do:
this.$store.dispatch('cluster/find', { type: NODE, id: nodeId });
to get a specific
NODE
, or you can just do
this.$store.dispatch('cluster/findAll', { type: NODE });
to get all
NODE
. Same analogy goes for a top-level-product, but the store is the
management
one, like:
this.$store.dispatch('management/find', { type: SETTING, id: some-setting-id });
to get a specific
SETTING
, or you can just do
this.$store.dispatch('management/findAll', { type: SETTING });
to get all
SETTING
. Examples: https://github.com/rancher/kubewarden-ui - cluster-level https://github.com/rancher/elemental-ui - top-level
You have rancher/dashboard repo, where if you search for
/k8s/clusters
or the other hints I gave you previously, you’ll find multiple examples
b
Thanks! I’ll give these a try and let you know how it goes