mirror of
https://github.com/lensapp/lens.git
synced 2024-12-11 09:03:28 +03:00
998cc36454
Signed-off-by: Sebastian Malton <sebastian@malton.name>
3.9 KiB
3.9 KiB
Cluster Connection
Current Flow for local cluster
- A kubeconfig file is discovered by the "kubeconfig sync"
- The kubeconfig file is read and verified to have a correctly shaped
context
,cluster
, anduser
entries - The user clicks on the cluster icon in the catalog
- The renderer is navigated to
/cluster/<cluster-id>
- The user is shown a list of connection updates
- A new iframe is initialized for that specific cluster using the cluster ID as part of the src field as a means of communication into the iframe about which cluster the iframe is for
- Then the cluster is requested to be "activated" on main
- Activation is as follows:
- Bind intervals to refresh connection status, accessibility, and metadata
- Bind reactions to update prometheus settings when the user changes them on the front end
- Bind reaction to recreate the proxy kubeconfig when the user changes the default namespace setting
- The KubeAuthProxy (spawns a k8s-lens-proxy instance) server is started and the flow waits for the server to report back the port it is using over STDOUT and also waits for that port to become used as reported by the OS
- The connection status is checked by "detecting the cluster version"
- By making a request to the Lens Proxy using the cluster id and the
/version
pathname - Lens Proxy receives the request with a pathname of
/<cluster-id>/version
- It detects and extracts the
cluster-id
and finds the relevantCluster
for that ID while modifying thepathname
to be/api-kube/version
- It detects that the pathname starts with
/api-kube
and removes that modification - It ensures that the proxy server is running and gets a proxy target to that local server
- It then proxies the rest of the request to that proxy
- The k8s-lens-proxy instance for that cluster then proxies the request to the kubelet
- The kubelet then returns an HTTP 200 responds with a JSON body containing the field
version
- By making a request to the Lens Proxy using the cluster id and the
- If the version is detected the cluster is marked as "accessible"
- The user still sees the list of connection updates
- Then the accessibility of the cluster is refreshed as follows:
- A kubeconfig pointing to the k8s-lens-proxy instance is loaded
- Check if the user for the kube context for this cluster ("kube user") has permissions to create all resources in the
kube-system
namespace (checking for admin permissions) - Check if the kube user has permissions to watch all resources (checking for global watch permissions)
- Request all namespaces for this cluster as follows:
- If the user has any configured "accessible namespaces" use those
- Try and do a GET request for
/api/v1/namespace
- If that succeeds use that list
- If it fails and the user has a "default namespace" configured in the kubeconfig file use that
- Otherwise fall back to an empty list
- Request all kube api resources descriptors as follows:
- Request legacy kube resources descriptors from
/api
- Request new groups of kube resources from
/apis
- For all the groups request the kube resources descriptors under them
- If the attempt to list kube api resources fails but a previous attempt succeeded continue to use the old list
- Using the list of namespaces retrieved above and the current list of kube api resource descriptors check which resources the user has LIST permissions for across at least one namespace as follows:
- Do a
SelfSubjectRulesReview
for each namespace - Compute from that result if the kube user definitely doesn't have LIST permissions for each resource in that namespace.
- Do a
- If at least one resource is known to be LIST-able we set the cluster to be "ready"
- Once the cluster is "ready" the iframe is made visible