diff --git a/dashboard/client/api/__test__/parseAPI.test.ts b/dashboard/client/api/__test__/parseAPI.test.ts index 82c0c59f75..b3a1320082 100644 --- a/dashboard/client/api/__test__/parseAPI.test.ts +++ b/dashboard/client/api/__test__/parseAPI.test.ts @@ -45,10 +45,23 @@ const tests: ParseAPITest[] = [ namespace: undefined, }, }, + { + url: "/apis/namespaces/default/es/gke-svc-vodka-1-app-1-w-l-1-9eea2bfe-4jnl", + expected: { + apiBase: "/apis", + apiPrefix: "/apis", + apiGroup: undefined, + apiVersion: undefined, + apiVersionWithGroup: "", + resource: undefined, + name: undefined, + namespace: undefined, + }, + }, ]; jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi'); -describe("parseAPI unit tests", () => { +describe("parseApi unit tests", () => { for (const i in tests) { const { url: tUrl, expected:tExpect} = tests[i]; test(`test #${parseInt(i)+1}`, () => { diff --git a/dashboard/client/api/api-manager.ts b/dashboard/client/api/api-manager.ts index 3bfb0caebd..89e1b1cf34 100644 --- a/dashboard/client/api/api-manager.ts +++ b/dashboard/client/api/api-manager.ts @@ -18,23 +18,17 @@ export class ApiManager { private views = observable.map(); getApi(pathOrCallback: string | ((api: KubeApi) => boolean)) { - const apis = this.apis; if (typeof pathOrCallback === "string") { - let api = apis.get(pathOrCallback); - if (!api) { - const { apiBase } = KubeApi.parseApi(pathOrCallback); - api = apis.get(apiBase); - } - return api; - } - else { - return Array.from(apis.values()).find(pathOrCallback); + return this.apis.get(pathOrCallback) || this.apis.get(KubeApi.parseApi(pathOrCallback).apiBase); } + + return Array.from(this.apis.values()).find(pathOrCallback); } registerApi(apiBase: string, api: KubeApi) { - if (this.apis.has(apiBase)) return; - this.apis.set(apiBase, api); + if (!this.apis.has(apiBase)) { + this.apis.set(apiBase, api); + } } protected resolveApi(api: string | KubeApi): KubeApi { diff --git a/dashboard/client/api/kube-api.ts b/dashboard/client/api/kube-api.ts index be8016c68c..f495e1eb5f 100644 --- a/dashboard/client/api/kube-api.ts +++ b/dashboard/client/api/kube-api.ts @@ -48,11 +48,7 @@ export class KubeApi { const [left, right, found] = split(parts, "namespaces"); let apiGroup, apiVersion, namespace, resource, name; - if (found) { - if (left.length == 0) { - throw new Error(`invalid apiPath: ${apiPath}`) - } - + if (found && left.length > 0) { apiVersion = left.pop(); apiGroup = left.join("/"); [namespace, resource, name] = right;