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

Fix create resource tab not working

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-08-11 10:41:54 -04:00
parent 0591c27b3c
commit 2478136635
2 changed files with 9 additions and 7 deletions

View File

@ -4,7 +4,6 @@
*/
import type { Cluster } from "../common/cluster/cluster";
import type { KubernetesObject } from "@kubernetes/client-node";
import { exec } from "child_process";
import fs from "fs-extra";
import * as yaml from "js-yaml";
@ -15,6 +14,7 @@ import { appEventBus } from "../common/app-event-bus/event-bus";
import { isChildProcessError } from "../common/utils";
import type { Patch } from "rfc6902";
import { promiseExecFile } from "../common/utils/promise-exec";
import type { KubernetesObject } from "@kubernetes/client-node";
export class ResourceApplier {
constructor(protected cluster: Cluster) {}
@ -65,7 +65,9 @@ export class ResourceApplier {
async create(resource: string): Promise<string> {
appEventBus.emit({ name: "resource", action: "apply" });
return this.kubectlApply(yaml.dump(this.sanitizeObject(resource)));
console.log({ resource });
return this.kubectlApply(this.sanitizeObject(resource));
}
protected async kubectlApply(content: string): Promise<string> {
@ -148,13 +150,13 @@ export class ResourceApplier {
});
}
protected sanitizeObject(resource: KubernetesObject | any) {
const res = JSON.parse(JSON.stringify(resource));
protected sanitizeObject(resource: string) {
const res = yaml.load(resource) as Partial<KubernetesObject> & { status?: object };
delete res.status;
delete res.metadata?.resourceVersion;
delete res.metadata?.annotations["kubectl.kubernetes.io/last-applied-configuration"];
delete res.metadata?.annotations?.["kubectl.kubernetes.io/last-applied-configuration"];
return res;
return yaml.dump(res);
}
}

View File

@ -9,7 +9,7 @@ import { payloadValidatedClusterRoute } from "../../router/route";
import Joi from "joi";
const createResourceRouteInjectable = getRouteInjectable({
id: "apply-resource-route",
id: "create-resource-route",
instantiate: () => payloadValidatedClusterRoute({
method: "post",