mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Simplify requestPatchKubeResource impl
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
b90e04e02d
commit
bc149f0627
3 files changed
+22
-28
No files matched your search
+1
-1
@@ -205,7 +205,7 @@ export class EditResourceModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = await this.dependencies.callForPatchResource(this.resource, patches);
|
||||
const result = await this.dependencies.callForPatchResource(selfLink, patches);
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
this.dependencies.showErrorNotification((
|
||||
|
||||
+16
-22
@@ -4,42 +4,36 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import apiManagerInjectable from "../../../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import type { JsonPatch } from "../../../../../common/k8s-api/kube-object.store";
|
||||
import type { KubeObject } from "../../../../../common/k8s-api/kube-object";
|
||||
import assert from "assert";
|
||||
import { getErrorMessage } from "../../../../../common/utils/get-error-message";
|
||||
import apiKubeInjectable from "../../../../k8s/api-kube.injectable";
|
||||
import { patchTypeHeaders } from "../../../../../common/k8s-api/kube-api";
|
||||
|
||||
export type RequestPatchKubeResource = (
|
||||
item: KubeObject,
|
||||
patch: JsonPatch
|
||||
) => AsyncResult<{ name: string; kind: string }>;
|
||||
export type RequestPatchKubeResource = (selfLink: string, patch: JsonPatch) => AsyncResult<{ name: string; kind: string }>;
|
||||
|
||||
const requestPatchKubeResourceInjectable = getInjectable({
|
||||
id: "request-patch-kube-resource",
|
||||
instantiate: (di): RequestPatchKubeResource => {
|
||||
const apiManager = di.inject(apiManagerInjectable);
|
||||
|
||||
return async (item, patch) => {
|
||||
const store = apiManager.getStore(item.selfLink);
|
||||
|
||||
assert(store);
|
||||
|
||||
let kubeObject: KubeObject;
|
||||
const apiKube = di.inject(apiKubeInjectable);
|
||||
|
||||
return async (selfLink, patch) => {
|
||||
try {
|
||||
kubeObject = await store.patch(item, patch);
|
||||
} catch (e: any) {
|
||||
const kubeObject = await apiKube.patch(selfLink, { data: patch }, {
|
||||
headers: {
|
||||
"content-type": patchTypeHeaders.json,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
callWasSuccessful: true,
|
||||
response: { name: kubeObject.metadata.name, kind: kubeObject.kind },
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
callWasSuccessful: false,
|
||||
error: getErrorMessage(e),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
callWasSuccessful: true,
|
||||
response: { name: kubeObject.getName(), kind: kubeObject.kind },
|
||||
};
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user