From 3636ac5c263db33ce1b23e37ab006ddae28d5671 Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Wed, 22 Mar 2023 15:34:44 +1300 Subject: [PATCH] fix(dashboard): use faster proxy request [EE-5160] (#8693) Co-authored-by: testa113 --- app/kubernetes/__module.js | 9 ++++++++- app/react/kubernetes/namespaces/service.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/kubernetes/__module.js b/app/kubernetes/__module.js index 5ebe986fb..470404b8e 100644 --- a/app/kubernetes/__module.js +++ b/app/kubernetes/__module.js @@ -1,4 +1,5 @@ import { EnvironmentStatus } from '@/react/portainer/environments/types'; +import { getSelfSubjectAccessReview } from '@/react/kubernetes/namespaces/service'; import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models'; @@ -47,7 +48,13 @@ angular.module('portainer.kubernetes', ['portainer.app', registriesModule, custo throw new Error('Unable to contact Edge agent, please ensure that the agent is properly running on the remote environment.'); } - await KubernetesNamespaceService.get(); + // use selfsubject access review to check if we can connect to the kubernetes environment + // because it's gets a fast response, and is accessible to all users + try { + await getSelfSubjectAccessReview(endpoint.Id, 'default'); + } catch (e) { + throw new Error('Environment is unreachable.'); + } } catch (e) { let params = {}; diff --git a/app/react/kubernetes/namespaces/service.ts b/app/react/kubernetes/namespaces/service.ts index 27549c2f3..405eed82a 100644 --- a/app/react/kubernetes/namespaces/service.ts +++ b/app/react/kubernetes/namespaces/service.ts @@ -3,6 +3,7 @@ import { EnvironmentId } from '@/react/portainer/environments/types'; import { Namespaces, SelfSubjectAccessReviewResponse } from './types'; +// getNamespace is used to retrieve a namespace using the Portainer backend export async function getNamespace( environmentId: EnvironmentId, namespace: string @@ -17,6 +18,7 @@ export async function getNamespace( } } +// getNamespaces is used to retrieve namespaces using the Portainer backend with caching export async function getNamespaces(environmentId: EnvironmentId) { try { const { data: namespaces } = await axios.get(