mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix api parsing for /api/v1/namespaces
This commit is contained in:
parent
de94d0bdad
commit
060a7e541e
@ -24,8 +24,8 @@
|
|||||||
"build:linux": "yarn compile && electron-builder --linux --dir -c.productName=LensDev",
|
"build:linux": "yarn compile && electron-builder --linux --dir -c.productName=LensDev",
|
||||||
"build:mac": "yarn compile && electron-builder --mac --dir -c.productName=LensDev",
|
"build:mac": "yarn compile && electron-builder --mac --dir -c.productName=LensDev",
|
||||||
"build:win": "yarn compile && electron-builder --win --dir -c.productName=LensDev",
|
"build:win": "yarn compile && electron-builder --win --dir -c.productName=LensDev",
|
||||||
"test": "jest spec/src",
|
"test": "jest spec/src $@",
|
||||||
"integration": "jest spec/integration",
|
"integration": "jest spec/integration $@",
|
||||||
"dist": "yarn compile && electron-builder -p onTag",
|
"dist": "yarn compile && electron-builder -p onTag",
|
||||||
"dist:win": "yarn compile && electron-builder -p onTag --x64 --ia32",
|
"dist:win": "yarn compile && electron-builder -p onTag --x64 --ia32",
|
||||||
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
|
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Restored from dashboard/client/utils/arrays.ts
|
// Moved from dashboard/client/utils/arrays.ts
|
||||||
/**
|
/**
|
||||||
* This function splits an array into two sub arrays on the first instance of
|
* This function splits an array into two sub arrays on the first instance of
|
||||||
* element (from the left). If the array does not contain the element. The
|
* element (from the left). If the array does not contain the element. The
|
||||||
|
|||||||
@ -0,0 +1,58 @@
|
|||||||
|
import { IKubeApiLinkBase, KubeApi } from "../kube-api";
|
||||||
|
|
||||||
|
interface ParseAPITest {
|
||||||
|
url: string;
|
||||||
|
expected: IKubeApiLinkBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests: ParseAPITest[] = [
|
||||||
|
{
|
||||||
|
url: "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27",
|
||||||
|
expected: {
|
||||||
|
apiBase: "/api/v1/pods",
|
||||||
|
apiPrefix: "/api",
|
||||||
|
apiGroup: "",
|
||||||
|
apiVersion: "v1",
|
||||||
|
apiVersionWithGroup: "v1",
|
||||||
|
namespace: "kube-system",
|
||||||
|
resource: "pods",
|
||||||
|
name: "coredns-6955765f44-v8p27"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "/apis/stable.example.com/foo1/crontabs",
|
||||||
|
expected: {
|
||||||
|
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
||||||
|
apiPrefix: "/apis",
|
||||||
|
apiGroup: "stable.example.com",
|
||||||
|
apiVersion: "foo1",
|
||||||
|
apiVersionWithGroup: "stable.example.com/foo1",
|
||||||
|
resource: "crontabs",
|
||||||
|
name: undefined,
|
||||||
|
namespace: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
||||||
|
expected: {
|
||||||
|
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
||||||
|
apiPrefix: "/apis",
|
||||||
|
apiGroup: "cluster.k8s.io",
|
||||||
|
apiVersion: "v1alpha1",
|
||||||
|
apiVersionWithGroup: "cluster.k8s.io/v1alpha1",
|
||||||
|
resource: "clusters",
|
||||||
|
name: undefined,
|
||||||
|
namespace: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
jest.mock('../kube-watch-api.ts', () => 'KubeWatchApi');
|
||||||
|
describe("parseAPI unit tests", () => {
|
||||||
|
for (const i in tests) {
|
||||||
|
const { url: tUrl, expected:tExpect} = tests[i];
|
||||||
|
test(`test #${parseInt(i)+1}`, () => {
|
||||||
|
expect(KubeApi.parseApi(tUrl)).toStrictEqual(tExpect);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -47,15 +47,13 @@ export class KubeApi<T extends KubeObject = any> {
|
|||||||
|
|
||||||
const [left, right, found] = splitArray(parts, "namespaces");
|
const [left, right, found] = splitArray(parts, "namespaces");
|
||||||
let apiGroup, apiVersion, namespace, resource, name;
|
let apiGroup, apiVersion, namespace, resource, name;
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
if (left.length == 0) {
|
if (left.length == 0) {
|
||||||
throw new Error(`invalid apiPath: ${apiPath}`)
|
throw new Error(`invalid apiPath: ${apiPath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiVersion = left.pop();
|
apiVersion = left.pop();
|
||||||
apiGroup = left.join("/");
|
apiGroup = left.join("/");
|
||||||
[namespace, resource, name] = right;
|
[namespace, resource = "namespaces", name] = right; // fix: "resource" is empty when "/api/v1/namespaces"
|
||||||
} else {
|
} else {
|
||||||
[apiGroup, apiVersion, resource] = left;
|
[apiGroup, apiVersion, resource] = left;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,21 +43,14 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
setQueryParams({ namespaces }, { replace: true })
|
setQueryParams({ namespaces }, { replace: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
protected loadItems(namespaces?: string[]) {
|
protected async loadItems(namespaces?: string[]) {
|
||||||
if (!isAllowedResource("namespaces")) {
|
if (!isAllowedResource("namespaces")) {
|
||||||
if (namespaces) {
|
if (namespaces) return namespaces.map(this.getDummyNamespace);
|
||||||
return Promise.all(namespaces.map(name => this.getDummyNamespace(name)))
|
return []
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new Promise<Namespace[]>(() => {
|
|
||||||
return []
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (namespaces) {
|
if (namespaces) {
|
||||||
return Promise.all(namespaces.map(name => this.api.get({ name })))
|
return Promise.all(namespaces.map(name => this.api.get({ name })))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return super.loadItems();
|
return super.loadItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,6 +143,7 @@ export class ThemeStore {
|
|||||||
// auto-apply colors to dom from active theme
|
// auto-apply colors to dom from active theme
|
||||||
reaction(() => this.activeTheme, this.onChange, {
|
reaction(() => this.activeTheme, this.onChange, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
|
delay: 150,
|
||||||
});
|
});
|
||||||
|
|
||||||
// apply theme from configuration
|
// apply theme from configuration
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user