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

Use propagationPolicy=Background by default for delete (#4337)

This commit is contained in:
Jari Kolehmainen 2021-11-15 15:29:22 +02:00 committed by GitHub
parent 4292968f82
commit 882f216368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 11 deletions

View File

@ -234,4 +234,40 @@ describe("KubeApi", () => {
], "json");
});
});
describe("delete", () => {
let api: TestKubeApi;
beforeEach(() => {
api = new TestKubeApi({
request,
objectConstructor: TestKubeObject,
});
});
it("sends correct request", async () => {
expect.hasAssertions();
(fetch as any).mockResponse(async (request: Request) => {
console.log(request.url);
expect(request.method).toEqual("DELETE");
expect(request.url).toEqual("http://127.0.0.1:9999/api-kube/api/v1/namespaces/default/pods/foo?propagationPolicy=Background");
return {};
});
await api.delete({ name: "foo", namespace: "default" });
});
it("allows to change propagationPolicy", async () => {
expect.hasAssertions();
(fetch as any).mockResponse(async (request: Request) => {
expect(request.method).toEqual("DELETE");
expect(request.url).toMatch("propagationPolicy=Orphan");
return {};
});
await api.delete({ name: "foo", namespace: "default", propagationPolicy: "Orphan" });
});
});
});

View File

@ -24,7 +24,6 @@ import { autoBind } from "../../utils";
import { IAffinity, WorkloadKubeObject } from "../workload-kube-object";
import { KubeApi } from "../kube-api";
import { metricsApi } from "./metrics.api";
import type { JsonApiParams } from "../json-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { IPodContainer, IPodMetrics } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
@ -121,14 +120,6 @@ export class Job extends WorkloadKubeObject {
return [...containers].map(container => container.image);
}
delete() {
const params: JsonApiParams = {
query: { propagationPolicy: "Background" },
};
return super.delete(params);
}
}
export class JobApi extends KubeApi<Job> {

View File

@ -98,6 +98,8 @@ export interface ILocalKubeApiConfig {
}
}
export type PropagationPolicy = undefined | "Orphan" | "Foreground" | "Background";
/**
* @deprecated
*/
@ -502,11 +504,16 @@ export class KubeApi<T extends KubeObject> {
return parsed;
}
async delete({ name = "", namespace = "default" }) {
async delete({ name = "", namespace = "default", propagationPolicy = "Background" }: { name: string, namespace: string, propagationPolicy?: PropagationPolicy }) {
await this.checkPreferredVersion();
const apiUrl = this.getUrl({ namespace, name });
const reqInit = {
query: {
propagationPolicy,
},
};
return this.request.del(apiUrl);
return this.request.del(apiUrl, reqInit);
}
getWatchUrl(namespace = "", query: IKubeApiQueryParams = {}) {