mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge remote-tracking branch 'origin/master' into monaco_editor_refactoring
# Conflicts: # src/common/user-store/user-store.ts
This commit is contained in:
commit
e966c1149d
18 files changed
+366
-219
No files matched your search
@@ -20,92 +20,108 @@
|
||||
*/
|
||||
|
||||
import { CustomResourceDefinition } from "../endpoints";
|
||||
import type { KubeObjectMetadata } from "../kube-object";
|
||||
|
||||
describe("Crds", () => {
|
||||
describe("getVersion", () => {
|
||||
it("should get the first version name from the list of versions", () => {
|
||||
it("should throw if none of the versions are served", () => {
|
||||
const crd = new CustomResourceDefinition({
|
||||
apiVersion: "foo",
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {} as KubeObjectMetadata,
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "12345",
|
||||
uid: "12345",
|
||||
},
|
||||
spec: {
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
{
|
||||
name: "1234",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
crd.spec = {
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: false,
|
||||
storage: false,
|
||||
}
|
||||
]
|
||||
} as any;
|
||||
expect(() => crd.getVersion()).toThrowError("Failed to find a version for CustomResourceDefinition foo");
|
||||
});
|
||||
|
||||
it("should should get the version that is both served and stored", () => {
|
||||
const crd = new CustomResourceDefinition({
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "12345",
|
||||
uid: "12345",
|
||||
},
|
||||
spec: {
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: true,
|
||||
storage: true,
|
||||
},
|
||||
{
|
||||
name: "1234",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(crd.getVersion()).toBe("123");
|
||||
});
|
||||
|
||||
it("should get the first version name from the list of versions (length 2)", () => {
|
||||
it("should should get the version that is both served and stored even with version field", () => {
|
||||
const crd = new CustomResourceDefinition({
|
||||
apiVersion: "foo",
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {} as KubeObjectMetadata,
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "12345",
|
||||
uid: "12345",
|
||||
},
|
||||
spec: {
|
||||
version: "abc",
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: true,
|
||||
storage: true,
|
||||
},
|
||||
{
|
||||
name: "1234",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
crd.spec = {
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
{
|
||||
name: "1234",
|
||||
served: false,
|
||||
storage: false,
|
||||
}
|
||||
]
|
||||
} as any;
|
||||
|
||||
expect(crd.getVersion()).toBe("123");
|
||||
});
|
||||
|
||||
it("should get the first version name from the list of versions (length 2) even with version field", () => {
|
||||
it("should get the version name from the version field", () => {
|
||||
const crd = new CustomResourceDefinition({
|
||||
apiVersion: "foo",
|
||||
apiVersion: "apiextensions.k8s.io/v1beta1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {} as KubeObjectMetadata,
|
||||
metadata: {
|
||||
name: "foo",
|
||||
resourceVersion: "12345",
|
||||
uid: "12345",
|
||||
},
|
||||
spec: {
|
||||
version: "abc",
|
||||
}
|
||||
});
|
||||
|
||||
crd.spec = {
|
||||
version: "abc",
|
||||
versions: [
|
||||
{
|
||||
name: "123",
|
||||
served: false,
|
||||
storage: false,
|
||||
},
|
||||
{
|
||||
name: "1234",
|
||||
served: false,
|
||||
storage: false,
|
||||
}
|
||||
]
|
||||
} as any;
|
||||
|
||||
expect(crd.getVersion()).toBe("123");
|
||||
});
|
||||
|
||||
it("should get the first version name from the version field", () => {
|
||||
const crd = new CustomResourceDefinition({
|
||||
apiVersion: "foo",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {} as KubeObjectMetadata,
|
||||
});
|
||||
|
||||
crd.spec = {
|
||||
version: "abc"
|
||||
} as any;
|
||||
|
||||
expect(crd.getVersion()).toBe("abc");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeCreationError, KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { crdResourcesURL } from "../../routes";
|
||||
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
type AdditionalPrinterColumnsCommon = {
|
||||
name: string;
|
||||
@@ -39,10 +40,21 @@ type AdditionalPrinterColumnsV1Beta = AdditionalPrinterColumnsCommon & {
|
||||
JSONPath: string;
|
||||
};
|
||||
|
||||
export interface CRDVersion {
|
||||
name: string;
|
||||
served: boolean;
|
||||
storage: boolean;
|
||||
schema?: object; // required in v1 but not present in v1beta
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1[];
|
||||
}
|
||||
|
||||
export interface CustomResourceDefinition {
|
||||
spec: {
|
||||
group: string;
|
||||
version?: string; // deprecated in v1 api
|
||||
/**
|
||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
||||
*/
|
||||
version?: string;
|
||||
names: {
|
||||
plural: string;
|
||||
singular: string;
|
||||
@@ -50,19 +62,19 @@ export interface CustomResourceDefinition {
|
||||
listKind: string;
|
||||
};
|
||||
scope: "Namespaced" | "Cluster" | string;
|
||||
validation?: any;
|
||||
versions?: {
|
||||
name: string;
|
||||
served: boolean;
|
||||
storage: boolean;
|
||||
schema?: unknown; // required in v1 but not present in v1beta
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1[]
|
||||
}[];
|
||||
/**
|
||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
||||
*/
|
||||
validation?: object;
|
||||
versions?: CRDVersion[];
|
||||
conversion: {
|
||||
strategy?: string;
|
||||
webhook?: any;
|
||||
};
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[]; // removed in v1
|
||||
/**
|
||||
* @deprecated for apiextensions.k8s.io/v1 but used previously
|
||||
*/
|
||||
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[];
|
||||
};
|
||||
status: {
|
||||
conditions: {
|
||||
@@ -83,11 +95,23 @@ export interface CustomResourceDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
export interface CRDApiData extends KubeJsonApiData {
|
||||
spec: object; // TODO: make better
|
||||
}
|
||||
|
||||
export class CustomResourceDefinition extends KubeObject {
|
||||
static kind = "CustomResourceDefinition";
|
||||
static namespaced = false;
|
||||
static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions";
|
||||
|
||||
constructor(data: CRDApiData) {
|
||||
super(data);
|
||||
|
||||
if (!data.spec || typeof data.spec !== "object") {
|
||||
throw new KubeCreationError("Cannot create a CustomResourceDefinition from an object without spec", data);
|
||||
}
|
||||
}
|
||||
|
||||
getResourceUrl() {
|
||||
return crdResourcesURL({
|
||||
params: {
|
||||
@@ -125,9 +149,36 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
return this.spec.scope;
|
||||
}
|
||||
|
||||
getPreferedVersion(): CRDVersion {
|
||||
// Prefer the modern `versions` over the legacy `version`
|
||||
if (this.spec.versions) {
|
||||
for (const version of this.spec.versions) {
|
||||
/**
|
||||
* If the version is not served then 404 errors will occur
|
||||
* We should also prefer the storage version
|
||||
*/
|
||||
if (version.served && version.storage) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
} else if (this.spec.version) {
|
||||
const { additionalPrinterColumns: apc } = this.spec;
|
||||
const additionalPrinterColumns = apc?.map(({ JSONPath, ...apc}) => ({ ...apc, jsonPath: JSONPath }));
|
||||
|
||||
return {
|
||||
name: this.spec.version,
|
||||
served: true,
|
||||
storage: true,
|
||||
schema: this.spec.validation,
|
||||
additionalPrinterColumns,
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`Failed to find a version for CustomResourceDefinition ${this.metadata.name}`);
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
// v1 has removed the spec.version property, if it is present it must match the first version
|
||||
return this.spec.versions?.[0]?.name ?? this.spec.version;
|
||||
return this.getPreferedVersion().name;
|
||||
}
|
||||
|
||||
isNamespaced() {
|
||||
@@ -147,17 +198,14 @@ export class CustomResourceDefinition extends KubeObject {
|
||||
}
|
||||
|
||||
getPrinterColumns(ignorePriority = true): AdditionalPrinterColumnsV1[] {
|
||||
const columns = this.spec.versions?.find(a => this.getVersion() == a.name)?.additionalPrinterColumns
|
||||
?? this.spec.additionalPrinterColumns?.map(({ JSONPath, ...rest }) => ({ ...rest, jsonPath: JSONPath })) // map to V1 shape
|
||||
?? [];
|
||||
const columns = this.getPreferedVersion().additionalPrinterColumns ?? [];
|
||||
|
||||
return columns
|
||||
.filter(column => column.name != "Age")
|
||||
.filter(column => ignorePriority ? true : !column.priority);
|
||||
.filter(column => column.name != "Age" && (ignorePriority || !column.priority));
|
||||
}
|
||||
|
||||
getValidation() {
|
||||
return JSON.stringify(this.spec.validation ?? this.spec.versions?.[0]?.schema, null, 2);
|
||||
return JSON.stringify(this.getPreferedVersion().schema, null, 2);
|
||||
}
|
||||
|
||||
getConditions() {
|
||||
|
||||
@@ -27,8 +27,7 @@ import { stringify } from "querystring";
|
||||
import { EventEmitter } from "../../common/event-emitter";
|
||||
import logger from "../../common/logger";
|
||||
|
||||
export interface JsonApiData {
|
||||
}
|
||||
export interface JsonApiData {}
|
||||
|
||||
export interface JsonApiError {
|
||||
code?: number;
|
||||
|
||||
@@ -259,6 +259,32 @@ const editorConfiguration: PreferenceDescription<EditorConfiguration, EditorConf
|
||||
},
|
||||
};
|
||||
|
||||
const defaultUpdateChannel = "latest";
|
||||
const updateChannels = new Map([
|
||||
[defaultUpdateChannel, {
|
||||
label: "Stable"
|
||||
}],
|
||||
["beta", {
|
||||
label: "Beta"
|
||||
}],
|
||||
["alpha", {
|
||||
label: "Alpha"
|
||||
}],
|
||||
]);
|
||||
|
||||
const updateChannel: PreferenceDescription<string> = {
|
||||
fromStore(val) {
|
||||
return updateChannels.has(val) ? val : defaultUpdateChannel;
|
||||
},
|
||||
toStore(val) {
|
||||
if (!updateChannels.has(val) || val === defaultUpdateChannel) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
type PreferencesModelType<field extends keyof typeof DESCRIPTORS> = typeof DESCRIPTORS[field] extends PreferenceDescription<infer T, any> ? T : never;
|
||||
type UserStoreModelType<field extends keyof typeof DESCRIPTORS> = typeof DESCRIPTORS[field] extends PreferenceDescription<any, infer T> ? T : never;
|
||||
|
||||
@@ -287,4 +313,10 @@ export const DESCRIPTORS = {
|
||||
syncKubeconfigEntries,
|
||||
editorConfiguration,
|
||||
terminalCopyOnSelect,
|
||||
updateChannel,
|
||||
};
|
||||
|
||||
export const CONSTANTS = {
|
||||
defaultUpdateChannel,
|
||||
updateChannels,
|
||||
};
|
||||
@@ -29,7 +29,7 @@ import { kubeConfigDefaultPath } from "../kube-helpers";
|
||||
import { appEventBus } from "../event-bus";
|
||||
import path from "path";
|
||||
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
||||
import { defaultEditorConfig, DESCRIPTORS, EditorConfiguration, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
|
||||
import { defaultEditorConfig, DESCRIPTORS, EditorConfiguration, KubeconfigSyncValue, UserPreferencesModel, CONSTANTS } from "./preferences-helpers";
|
||||
import logger from "../../main/logger";
|
||||
import { getPath } from "../utils/getPath";
|
||||
|
||||
@@ -73,6 +73,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
@observable downloadBinariesPath?: string;
|
||||
@observable kubectlBinariesPath?: string;
|
||||
@observable terminalCopyOnSelect: boolean;
|
||||
@observable updateChannel?: string;
|
||||
|
||||
/**
|
||||
* Download kubectl binaries matching cluster version
|
||||
@@ -104,6 +105,10 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
||||
}
|
||||
|
||||
@computed get isAllowedToDowngrade(): boolean {
|
||||
return this.updateChannel !== CONSTANTS.defaultUpdateChannel;
|
||||
}
|
||||
|
||||
startMainReactions() {
|
||||
// track telemetry availability
|
||||
reaction(() => this.allowTelemetry, allowed => {
|
||||
@@ -194,6 +199,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
this.syncKubeconfigEntries.replace(DESCRIPTORS.syncKubeconfigEntries.fromStore(preferences?.syncKubeconfigEntries));
|
||||
this.editorConfiguration = DESCRIPTORS.editorConfiguration.fromStore(preferences?.editorConfiguration);
|
||||
this.terminalCopyOnSelect = DESCRIPTORS.terminalCopyOnSelect.fromStore(preferences?.terminalCopyOnSelect);
|
||||
this.updateChannel = DESCRIPTORS.updateChannel.fromStore(preferences?.updateChannel);
|
||||
}
|
||||
|
||||
toJSON(): UserStoreModel {
|
||||
@@ -216,6 +222,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
syncKubeconfigEntries: DESCRIPTORS.syncKubeconfigEntries.toStore(this.syncKubeconfigEntries),
|
||||
editorConfiguration: DESCRIPTORS.editorConfiguration.toStore(this.editorConfiguration),
|
||||
terminalCopyOnSelect: DESCRIPTORS.terminalCopyOnSelect.toStore(this.terminalCopyOnSelect),
|
||||
updateChannel: DESCRIPTORS.updateChannel.toStore(this.updateChannel),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMess
|
||||
import { once } from "lodash";
|
||||
import { ipcMain } from "electron";
|
||||
import { nextUpdateChannel } from "./utils/update-channel";
|
||||
import { UserStore } from "../common/user-store";
|
||||
|
||||
const updateChannel = autoUpdater.channel;
|
||||
let installVersion: null | string = null;
|
||||
@@ -58,9 +59,13 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
||||
return;
|
||||
}
|
||||
|
||||
const us = UserStore.getInstance();
|
||||
|
||||
autoUpdater.logger = logger;
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
autoUpdater.channel = us.updateChannel;
|
||||
autoUpdater.allowDowngrade = us.isAllowedToDowngrade;
|
||||
|
||||
autoUpdater
|
||||
.on("update-available", (info: UpdateInfo) => {
|
||||
|
||||
@@ -160,6 +160,10 @@ export class ClusterManager extends Singleton {
|
||||
return "connecting";
|
||||
}
|
||||
|
||||
if (entity?.status?.phase) {
|
||||
return entity.status.phase;
|
||||
}
|
||||
|
||||
return "disconnected";
|
||||
})();
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ export async function listReleases(pathToKubeconfig: string, namespace?: string)
|
||||
});
|
||||
|
||||
return output;
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ export async function installChart(chart: string, values: any, name: string | un
|
||||
namespace
|
||||
}
|
||||
};
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
} finally {
|
||||
await fse.unlink(fileName);
|
||||
}
|
||||
@@ -93,8 +93,8 @@ export async function upgradeRelease(name: string, chart: string, values: any, n
|
||||
log: stdout,
|
||||
release: getRelease(name, namespace, cluster)
|
||||
};
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
} finally {
|
||||
await fse.unlink(fileName);
|
||||
}
|
||||
@@ -111,8 +111,8 @@ export async function getRelease(name: string, namespace: string, cluster: Clust
|
||||
release.resources = await getResources(name, namespace, cluster);
|
||||
|
||||
return release;
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ export async function deleteRelease(name: string, namespace: string, pathToKubec
|
||||
const { stdout } = await promiseExec(`"${helm}" delete ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
||||
|
||||
return stdout;
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ export async function getValues(name: string, { namespace, all = false, pathToKu
|
||||
const { stdout } = await promiseExec(`"${helm}" get values ${name} ${all ? "--all" : ""} --output yaml --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
||||
|
||||
return stdout;
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ export async function getHistory(name: string, namespace: string, pathToKubeconf
|
||||
const { stdout } = await promiseExec(`"${helm}" history ${name} --output json --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
||||
|
||||
return JSON.parse(stdout);
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +161,8 @@ export async function rollback(name: string, namespace: string, revision: number
|
||||
const { stdout } = await promiseExec(`"${helm}" rollback ${name} ${revision} --namespace ${namespace} --kubeconfig ${pathToKubeconfig}`);
|
||||
|
||||
return stdout;
|
||||
} catch ({ stderr }) {
|
||||
throw stderr;
|
||||
} catch (error) {
|
||||
throw error?.stderr || error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export class HelmApiRoute {
|
||||
|
||||
respondJson(response, chart);
|
||||
} catch (error) {
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error getting chart", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export class HelmApiRoute {
|
||||
|
||||
respondJson(response, values);
|
||||
} catch (error) {
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error getting chart values", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result, 201);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error installing chart", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error updating chart", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error rolling back chart", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch(error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error listing release", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error getting release", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ export class HelmApiRoute {
|
||||
respondText(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error getting release values", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error getting release history", 422);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ export class HelmApiRoute {
|
||||
respondJson(response, result);
|
||||
} catch (error) {
|
||||
logger.debug(error);
|
||||
respondText(response, error, 422);
|
||||
respondText(response, error?.toString() || "Error deleting release", 422);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ import "./helm-chart-details.scss";
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { getChartDetails, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { observable, autorun, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { observable, makeObservable, reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { Drawer, DrawerItem } from "../drawer";
|
||||
import { boundMethod, stopPropagation } from "../../utils";
|
||||
import { MarkdownViewer } from "../markdown-viewer";
|
||||
@@ -64,20 +64,24 @@ export class HelmChartDetails extends Component<Props> {
|
||||
this.abortController?.abort();
|
||||
}
|
||||
|
||||
chartUpdater = autorun(() => {
|
||||
this.selectedChart = null;
|
||||
const { chart: { name, repo, version } } = this.props;
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
reaction(() => this.props.chart, async ({ name, repo, version }) => {
|
||||
try {
|
||||
const { readme, versions } = await getChartDetails(repo, name, { version });
|
||||
|
||||
getChartDetails(repo, name, { version })
|
||||
.then(result => {
|
||||
this.readme = result.readme;
|
||||
this.chartVersions = result.versions;
|
||||
this.selectedChart = result.versions[0];
|
||||
})
|
||||
.catch(error => {
|
||||
this.error = error;
|
||||
});
|
||||
});
|
||||
this.readme = readme;
|
||||
this.chartVersions = versions;
|
||||
this.selectedChart = versions[0];
|
||||
} catch (error) {
|
||||
this.error = error;
|
||||
this.selectedChart = null;
|
||||
}
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
async onVersionChange({ value: chart }: SelectOption<HelmChart>) {
|
||||
@@ -135,7 +139,7 @@ export class HelmChartDetails extends Component<Props> {
|
||||
value: chart,
|
||||
}))}
|
||||
isOptionDisabled={({ value: chart }) => chart.deprecated}
|
||||
value={selectedChart.getVersion()}
|
||||
value={selectedChart}
|
||||
onChange={onVersionChange}
|
||||
/>
|
||||
</DrawerItem>
|
||||
@@ -170,10 +174,6 @@ export class HelmChartDetails extends Component<Props> {
|
||||
}
|
||||
|
||||
renderContent() {
|
||||
if (!this.selectedChart) {
|
||||
return <Spinner center />;
|
||||
}
|
||||
|
||||
if (this.error) {
|
||||
return (
|
||||
<div className="box grow">
|
||||
@@ -182,6 +182,10 @@ export class HelmChartDetails extends Component<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.selectedChart) {
|
||||
return <Spinner center />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="box grow">
|
||||
{this.renderIntroduction()}
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.loading-error {
|
||||
color: red;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.status {
|
||||
@include release-status-bgs;
|
||||
}
|
||||
|
||||
@@ -55,12 +55,13 @@ interface Props {
|
||||
|
||||
@observer
|
||||
export class ReleaseDetails extends Component<Props> {
|
||||
@observable details: IReleaseDetails;
|
||||
@observable details: IReleaseDetails | null = null;
|
||||
@observable values = "";
|
||||
@observable valuesLoading = false;
|
||||
@observable showOnlyUserSuppliedValues = false;
|
||||
@observable saving = false;
|
||||
@observable releaseSecret: Secret;
|
||||
@observable error?: string = undefined;
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
@@ -95,9 +96,13 @@ export class ReleaseDetails extends Component<Props> {
|
||||
|
||||
async loadDetails() {
|
||||
const { release } = this.props;
|
||||
|
||||
this.details = null;
|
||||
this.details = await getRelease(release.getName(), release.getNs());
|
||||
|
||||
try {
|
||||
this.details = null;
|
||||
this.details = await getRelease(release.getName(), release.getNs());
|
||||
} catch (error) {
|
||||
this.error = `Failed to get release details: ${error}`;
|
||||
}
|
||||
}
|
||||
|
||||
async loadValues() {
|
||||
@@ -234,11 +239,18 @@ export class ReleaseDetails extends Component<Props> {
|
||||
|
||||
renderContent() {
|
||||
const { release } = this.props;
|
||||
const { details } = this;
|
||||
|
||||
if (!release) return null;
|
||||
|
||||
if (!details) {
|
||||
if (this.error) {
|
||||
return (
|
||||
<div className="loading-error">
|
||||
{this.error}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.details) {
|
||||
return <Spinner center/>;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ export class HelmReleaseMenu extends React.Component<Props> {
|
||||
{...menuProps}
|
||||
className={cssNames("HelmReleaseMenu", className)}
|
||||
removeAction={this.remove}
|
||||
removeConfirmationMessage={() => <p>Remove Helm Release <b>{release.name}</b>?</p>}
|
||||
>
|
||||
{this.renderContent()}
|
||||
</MenuActions>
|
||||
|
||||
@@ -29,11 +29,16 @@ import { Input } from "../input";
|
||||
import { isWindows } from "../../../common/vars";
|
||||
import { FormSwitch, Switcher } from "../switch";
|
||||
import moment from "moment-timezone";
|
||||
import { CONSTANTS } from "../../../common/user-store/preferences-helpers";
|
||||
|
||||
const timezoneOptions: SelectOption<string>[] = moment.tz.names().map(zone => ({
|
||||
label: zone,
|
||||
value: zone,
|
||||
}));
|
||||
const updateChannelOptions: SelectOption<string>[] = Array.from(
|
||||
CONSTANTS.updateChannels.entries(),
|
||||
([value, { label }]) => ({ value, label }),
|
||||
);
|
||||
|
||||
export const Application = observer(() => {
|
||||
const defaultShell = process.env.SHELL
|
||||
@@ -104,6 +109,18 @@ export const Application = observer(() => {
|
||||
|
||||
<hr />
|
||||
|
||||
<section id="update-channel">
|
||||
<SubTitle title="Update Channel"/>
|
||||
<Select
|
||||
options={updateChannelOptions}
|
||||
value={UserStore.getInstance().updateChannel}
|
||||
onChange={({ value }: SelectOption) => UserStore.getInstance().updateChannel = value}
|
||||
themeName="lens"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<hr />
|
||||
|
||||
<section id="locale">
|
||||
<SubTitle title="Locale Timezone" />
|
||||
<Select
|
||||
|
||||
@@ -28,6 +28,7 @@ import { StorageHelper } from "./storageHelper";
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import logger from "../../main/logger";
|
||||
import { getHostedClusterId, getPath } from "../../common/utils";
|
||||
import { isTestEnv } from "../../common/vars";
|
||||
|
||||
const storage = observable({
|
||||
initialized: false,
|
||||
@@ -62,7 +63,9 @@ export function createAppStorage<T>(key: string, defaultValue: T, clusterId?: st
|
||||
.then(data => storage.data = data)
|
||||
.catch(() => null) // ignore empty / non-existing / invalid json files
|
||||
.finally(() => {
|
||||
logger.info(`${logPrefix} loading finished for ${filePath}`);
|
||||
if (!isTestEnv) {
|
||||
logger.info(`${logPrefix} loading finished for ${filePath}`);
|
||||
}
|
||||
storage.loaded = true;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user