mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
27 lines
858 B
TypeScript
27 lines
858 B
TypeScript
import jsYaml from "js-yaml"
|
|
import { KubeObject } from "../kube-object";
|
|
import { KubeJsonApiData } from "../kube-json-api";
|
|
import { apiKubeResourceApplier } from "../index";
|
|
import { apiManager } from "../api-manager";
|
|
|
|
export const resourceApplierApi = {
|
|
annotations: [
|
|
"kubectl.kubernetes.io/last-applied-configuration"
|
|
],
|
|
|
|
async update<D extends KubeObject>(resource: object | string): Promise<D> {
|
|
if (typeof resource === "string") {
|
|
resource = jsYaml.safeLoad(resource);
|
|
}
|
|
return apiKubeResourceApplier
|
|
.post<KubeJsonApiData[]>("/stack", { data: resource })
|
|
.then(data => {
|
|
const items = data.map(obj => {
|
|
const api = apiManager.getApi(obj.metadata.selfLink);
|
|
return new api.objectConstructor(obj);
|
|
});
|
|
return items.length === 1 ? items[0] : items;
|
|
});
|
|
}
|
|
};
|