1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use PartialDeep for patch type (#4420)

* Use PartialDeep for patch type.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Add test. Fix typing.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Fix lint.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2021-12-02 15:28:28 +02:00 committed by GitHub
parent f02018c1e7
commit 696986b7e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View File

@ -241,6 +241,24 @@ describe("KubeApi", () => {
{ op: "replace", path: "/spec/replicas", value: 2 }, { op: "replace", path: "/spec/replicas", value: 2 },
], "json"); ], "json");
}); });
it("allows deep partial patch", async () => {
expect.hasAssertions();
(fetch as any).mockResponse(async (request: Request) => {
expect(request.method).toEqual("PATCH");
expect(request.headers.get("content-type")).toMatch("merge-patch");
expect(request.body.toString()).toEqual(JSON.stringify({ metadata: { annotations: { provisioned: "true" }}}));
return {};
});
await api.patch(
{ name: "test", namespace: "default" },
{ metadata: { annotations: { provisioned: "true" }}},
"merge",
);
});
}); });
describe("delete", () => { describe("delete", () => {

View File

@ -526,7 +526,7 @@ export class KubeApi<T extends KubeObject> {
return parsed; return parsed;
} }
async patch(desc: ResourceDescriptor, data?: Partial<T> | Patch, strategy: KubeApiPatchType = "strategic"): Promise<T | null> { async patch(desc: ResourceDescriptor, data?: PartialKubeObject<T> | Patch, strategy: KubeApiPatchType = "strategic") {
await this.checkPreferredVersion(); await this.checkPreferredVersion();
const apiUrl = this.getUrl(desc); const apiUrl = this.getUrl(desc);
@ -541,7 +541,7 @@ export class KubeApi<T extends KubeObject> {
throw new Error(`PATCH request to ${apiUrl} returned an array: ${JSON.stringify(parsed)}`); throw new Error(`PATCH request to ${apiUrl} returned an array: ${JSON.stringify(parsed)}`);
} }
return parsed; return parsed as T | null;
} }
async delete({ propagationPolicy = "Background", ...desc }: DeleteResourceDescriptor) { async delete({ propagationPolicy = "Background", ...desc }: DeleteResourceDescriptor) {

View File

@ -49,7 +49,8 @@ export class Namespaces extends React.Component<Props> {
<KubeObjectListLayout <KubeObjectListLayout
isConfigurable isConfigurable
tableId="namespaces" tableId="namespaces"
className="Namespaces" store={namespaceStore} className="Namespaces"
store={namespaceStore}
sortingCallbacks={{ sortingCallbacks={{
[columnId.name]: ns => ns.getName(), [columnId.name]: ns => ns.getName(),
[columnId.labels]: ns => ns.getLabels(), [columnId.labels]: ns => ns.getLabels(),

View File

@ -92,7 +92,8 @@ export class Pods extends React.Component<Props> {
render() { render() {
return ( return (
<KubeObjectListLayout <KubeObjectListLayout
className="Pods" store={podsStore} className="Pods"
store={podsStore}
dependentStores={[eventStore]} // status icon component uses event store dependentStores={[eventStore]} // status icon component uses event store
tableId = "workloads_pods" tableId = "workloads_pods"
isConfigurable isConfigurable