mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix getReleases returning inconsistent data types (#2924)
This commit is contained in:
parent
06612409ef
commit
043f411ad1
@ -22,7 +22,7 @@
|
|||||||
import * as tempy from "tempy";
|
import * as tempy from "tempy";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import * as yaml from "js-yaml";
|
import * as yaml from "js-yaml";
|
||||||
import { promiseExec} from "../promise-exec";
|
import { promiseExec } from "../promise-exec";
|
||||||
import { helmCli } from "./helm-cli";
|
import { helmCli } from "./helm-cli";
|
||||||
import type { Cluster } from "../cluster";
|
import type { Cluster } from "../cluster";
|
||||||
import { toCamelCase } from "../../common/utils/camelCase";
|
import { toCamelCase } from "../../common/utils/camelCase";
|
||||||
@ -39,7 +39,7 @@ export async function listReleases(pathToKubeconfig: string, namespace?: string)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
output.forEach((release: any, index: number) => {
|
output.forEach((release: any, index: number) => {
|
||||||
output[index] = toCamelCase(release);
|
output[index] = toCamelCase(release);
|
||||||
});
|
});
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -49,9 +49,9 @@ export async function listReleases(pathToKubeconfig: string, namespace?: string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function installChart(chart: string, values: any, name: string | undefined, namespace: string, version: string, pathToKubeconfig: string){
|
export async function installChart(chart: string, values: any, name: string | undefined, namespace: string, version: string, pathToKubeconfig: string) {
|
||||||
const helm = await helmCli.binaryPath();
|
const helm = await helmCli.binaryPath();
|
||||||
const fileName = tempy.file({name: "values.yaml"});
|
const fileName = tempy.file({ name: "values.yaml" });
|
||||||
|
|
||||||
await fse.writeFile(fileName, yaml.safeDump(values));
|
await fse.writeFile(fileName, yaml.safeDump(values));
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ export async function installChart(chart: string, values: any, name: string | un
|
|||||||
|
|
||||||
export async function upgradeRelease(name: string, chart: string, values: any, namespace: string, version: string, cluster: Cluster) {
|
export async function upgradeRelease(name: string, chart: string, values: any, namespace: string, version: string, cluster: Cluster) {
|
||||||
const helm = await helmCli.binaryPath();
|
const helm = await helmCli.binaryPath();
|
||||||
const fileName = tempy.file({name: "values.yaml"});
|
const fileName = tempy.file({ name: "values.yaml" });
|
||||||
|
|
||||||
await fse.writeFile(fileName, yaml.safeDump(values));
|
await fse.writeFile(fileName, yaml.safeDump(values));
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ export async function getRelease(name: string, namespace: string, cluster: Clust
|
|||||||
export async function deleteRelease(name: string, namespace: string, pathToKubeconfig: string) {
|
export async function deleteRelease(name: string, namespace: string, pathToKubeconfig: string) {
|
||||||
try {
|
try {
|
||||||
const helm = await helmCli.binaryPath();
|
const helm = await helmCli.binaryPath();
|
||||||
const { stdout } = await promiseExec(`"${helm}" delete ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
const { stdout } = await promiseExec(`"${helm}" delete ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
||||||
|
|
||||||
return stdout;
|
return stdout;
|
||||||
} catch ({ stderr }) {
|
} catch ({ stderr }) {
|
||||||
@ -173,8 +173,8 @@ async function getResources(name: string, namespace: string, cluster: Cluster) {
|
|||||||
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
||||||
const { stdout } = await promiseExec(`"${helm}" get manifest ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig} | "${kubectl}" get -n ${namespace} --kubeconfig ${pathToKubeconfig} -f - -o=json`);
|
const { stdout } = await promiseExec(`"${helm}" get manifest ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig} | "${kubectl}" get -n ${namespace} --kubeconfig ${pathToKubeconfig} -f - -o=json`);
|
||||||
|
|
||||||
return stdout;
|
return JSON.parse(stdout).items;
|
||||||
} catch {
|
} catch {
|
||||||
return { stdout: JSON.stringify({ items: [] }) };
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import type { ItemObject } from "../../item.store";
|
|||||||
import { KubeObject } from "../kube-object";
|
import { KubeObject } from "../kube-object";
|
||||||
import type { JsonApiData } from "../json-api";
|
import type { JsonApiData } from "../json-api";
|
||||||
import { buildURLPositional } from "../../../common/utils/buildUrl";
|
import { buildURLPositional } from "../../../common/utils/buildUrl";
|
||||||
|
import type { KubeJsonApiData } from "../kube-json-api";
|
||||||
|
|
||||||
interface IReleasePayload {
|
interface IReleasePayload {
|
||||||
name: string;
|
name: string;
|
||||||
@ -46,7 +47,7 @@ interface IReleasePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IReleaseRawDetails extends IReleasePayload {
|
interface IReleaseRawDetails extends IReleasePayload {
|
||||||
resources: string;
|
resources: KubeJsonApiData[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IReleaseDetails extends IReleasePayload {
|
export interface IReleaseDetails extends IReleasePayload {
|
||||||
@ -102,10 +103,8 @@ export async function listReleases(namespace?: string): Promise<HelmRelease[]> {
|
|||||||
|
|
||||||
export async function getRelease(name: string, namespace: string): Promise<IReleaseDetails> {
|
export async function getRelease(name: string, namespace: string): Promise<IReleaseDetails> {
|
||||||
const path = endpoint({ name, namespace });
|
const path = endpoint({ name, namespace });
|
||||||
|
const { resources: rawResources, ...details } = await apiBase.get<IReleaseRawDetails>(path);
|
||||||
const details = await apiBase.get<IReleaseRawDetails>(path);
|
const resources = rawResources.map(KubeObject.create);
|
||||||
const items: KubeObject[] = JSON.parse(details.resources).items;
|
|
||||||
const resources = items.map(item => KubeObject.create(item));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...details,
|
...details,
|
||||||
@ -194,7 +193,7 @@ export class HelmRelease implements ItemObject {
|
|||||||
getChart(withVersion = false) {
|
getChart(withVersion = false) {
|
||||||
let chart = this.chart;
|
let chart = this.chart;
|
||||||
|
|
||||||
if(!withVersion && this.getVersion() != "" ) {
|
if (!withVersion && this.getVersion() != "") {
|
||||||
const search = new RegExp(`-${this.getVersion()}`);
|
const search = new RegExp(`-${this.getVersion()}`);
|
||||||
|
|
||||||
chart = chart.replace(search, "");
|
chart = chart.replace(search, "");
|
||||||
|
|||||||
@ -97,7 +97,7 @@ export class KubeObject<Metadata extends IKubeObjectMetadata = IKubeObjectMetada
|
|||||||
status?: Status;
|
status?: Status;
|
||||||
spec?: Spec;
|
spec?: Spec;
|
||||||
|
|
||||||
static create(data: any) {
|
static create(data: KubeJsonApiData) {
|
||||||
return new KubeObject(data);
|
return new KubeObject(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ export class KubeObject<Metadata extends IKubeObjectMetadata = IKubeObjectMetada
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static isJsonApiDataList<T>(object: unknown, verifyItem:(val: unknown) => val is T): object is KubeJsonApiDataList<T> {
|
static isJsonApiDataList<T>(object: unknown, verifyItem: (val: unknown) => val is T): object is KubeJsonApiDataList<T> {
|
||||||
return (
|
return (
|
||||||
isObject(object)
|
isObject(object)
|
||||||
&& hasTypedProperty(object, "kind", isString)
|
&& hasTypedProperty(object, "kind", isString)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user