Merge remote-tracking branch 'origin/master' into monaco_editor_refactoring

# Conflicts:
#	src/common/user-store/preferences-helpers.ts
#	src/common/user-store/user-store.ts
This commit is contained in:
Roman committed 2021-10-14 11:34:56 +03:00
commit f80dda3c59
14 files changed
+234 -175

No files matched your search

+16 -6
View File
@@ -56,6 +56,21 @@ export interface INodeMetrics<T = IMetrics> {
fsSize: T;
}
export interface NodeTaint {
key: string;
value?: string;
effect: string;
timeAdded: string;
}
export function formatNodeTaint(taint: NodeTaint): string {
if (taint.value) {
return `${taint.key}=${taint.value}:${taint.effect}`;
}
return `${taint.key}:${taint.effect}`;
}
export interface Node {
spec: {
podCIDR?: string;
@@ -65,12 +80,7 @@ export interface Node {
* @deprecated see https://issues.k8s.io/61966
*/
externalID?: string;
taints?: {
key: string;
value: string;
effect: string;
timeAdded: string;
}[];
taints?: NodeTaint[];
unschedulable?: boolean;
};
status: {
+4 -4
View File
@@ -23,9 +23,10 @@ import moment from "moment-timezone";
import path from "path";
import os from "os";
import { ThemeStore } from "../../renderer/theme.store";
import { ObservableToggleSet } from "../utils";
import { getAppVersion, ObservableToggleSet } from "../utils";
import type { editor } from "monaco-editor";
import merge from "lodash/merge";
import { SemVer } from "semver";
export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
filePath: string;
@@ -259,9 +260,8 @@ const editorConfiguration: PreferenceDescription<EditorConfiguration, EditorConf
},
};
const defaultUpdateChannel = "latest";
const updateChannels = new Map([
[defaultUpdateChannel, {
["latest", {
label: "Stable"
}],
["beta", {
@@ -271,6 +271,7 @@ const updateChannels = new Map([
label: "Alpha"
}],
]);
const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
const updateChannel: PreferenceDescription<string> = {
fromStore(val) {
@@ -317,7 +318,6 @@ export const DESCRIPTORS = {
};
export const CONSTANTS = {
defaultUpdateChannel,
updateChannels,
defaultEditorConfig,
};
+3 -5
View File
@@ -20,7 +20,7 @@
*/
import { app, ipcMain } from "electron";
import semver from "semver";
import semver, { SemVer } from "semver";
import { action, computed, makeObservable, observable, reaction } from "mobx";
import { BaseStore } from "../base-store";
import migrations, { fileNameMigration } from "../../migrations/user-store";
@@ -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 { CONSTANTS, DESCRIPTORS, EditorConfiguration, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
import { CONSTANTS, DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel, EditorConfiguration } from "./preferences-helpers";
import logger from "../../main/logger";
import { getPath } from "../utils/getPath";
@@ -105,9 +105,7 @@ 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;
}
readonly isAllowedToDowngrade = new SemVer(getAppVersion()).prerelease[0] !== "latest";
startMainReactions() {
// track telemetry availability
+4 -5
View File
@@ -29,7 +29,6 @@ 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;
export function isAutoUpdateEnabled() {
@@ -59,13 +58,13 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
return;
}
const us = UserStore.getInstance();
const userStore = UserStore.getInstance();
autoUpdater.logger = logger;
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.channel = us.updateChannel;
autoUpdater.allowDowngrade = us.isAllowedToDowngrade;
autoUpdater.channel = userStore.updateChannel;
autoUpdater.allowDowngrade = userStore.isAllowedToDowngrade;
autoUpdater
.on("update-available", (info: UpdateInfo) => {
@@ -109,7 +108,7 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
}
})
.on("update-not-available", () => {
const nextChannel = nextUpdateChannel(updateChannel, autoUpdater.channel);
const nextChannel = nextUpdateChannel(userStore.updateChannel, autoUpdater.channel);
logger.info(`${AutoUpdateLogPrefix}: update not available from ${autoUpdater.channel}, will check ${nextChannel} channel next`);
@@ -33,17 +33,17 @@ describe("nextUpdateChannel", () => {
expect(nextUpdateChannel("latest", "alpha")).toEqual("beta");
});
it("returns rc if current channel is beta", () => {
expect(nextUpdateChannel("alpha", "beta")).toEqual("rc");
expect(nextUpdateChannel("beta", "beta")).toEqual("rc");
expect(nextUpdateChannel("rc", "beta")).toEqual("rc");
expect(nextUpdateChannel("latest", "beta")).toEqual("rc");
it("returns latest if current channel is beta", () => {
expect(nextUpdateChannel("alpha", "beta")).toEqual("latest");
expect(nextUpdateChannel("beta", "beta")).toEqual("latest");
expect(nextUpdateChannel("rc", "beta")).toEqual("latest");
expect(nextUpdateChannel("latest", "beta")).toEqual("latest");
});
it("returns latest if current channel is rc", () => {
expect(nextUpdateChannel("alpha", "rc")).toEqual("latest");
expect(nextUpdateChannel("beta", "rc")).toEqual("latest");
expect(nextUpdateChannel("rc", "rc")).toEqual("latest");
it("returns default if current channel is unknown", () => {
expect(nextUpdateChannel("alpha", "rc")).toEqual("alpha");
expect(nextUpdateChannel("beta", "rc")).toEqual("beta");
expect(nextUpdateChannel("rc", "rc")).toEqual("rc");
expect(nextUpdateChannel("latest", "rc")).toEqual("latest");
});
});
+13 -8
View File
@@ -19,14 +19,19 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Compute the next update channel from the current updating channel
* @param defaultChannel The default (initial) channel to check
* @param channel The current channel that did not have a new version associated with it
* @returns The channel name of the next release version
*/
export function nextUpdateChannel(defaultChannel: string, channel: string): string {
if (channel === "alpha") {
return "beta";
} else if (channel === "beta") {
return "rc";
} else if (channel === "rc") {
return "latest";
} else {
return defaultChannel;
switch (channel) {
case "alpha":
return "beta";
case "beta":
return "latest"; // there is no RC currently
default:
return defaultChannel;
}
}
@@ -30,7 +30,7 @@ import { Badge } from "../badge";
import { ResourceMetrics } from "../resource-metrics";
import { podsStore } from "../+workloads-pods/pods.store";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../../common/k8s-api/endpoints";
import { formatNodeTaint, getMetricsByNodeNames, IClusterMetrics, Node } from "../../../common/k8s-api/endpoints";
import { NodeCharts } from "./node-charts";
import { makeObservable, observable, reaction } from "mobx";
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
@@ -132,11 +132,7 @@ export class NodeDetails extends React.Component<Props> {
/>
{taints.length > 0 && (
<DrawerItem name="Taints" labelsOnly>
{
taints.map(({ key, effect, value }) => (
<Badge key={key} label={`${key}=${value}:${effect}`} />
))
}
{taints.map(taint => <Badge key={taint.key} label={formatNodeTaint(taint)} />)}
</DrawerItem>
)}
{conditions &&
+4 -3
View File
@@ -27,7 +27,7 @@ import { cssNames, interval } from "../../utils";
import { TabLayout } from "../layout/tab-layout";
import { nodesStore } from "./nodes.store";
import { KubeObjectListLayout } from "../kube-object-list-layout";
import { getMetricsForAllNodes, INodeMetrics, Node } from "../../../common/k8s-api/endpoints/nodes.api";
import { formatNodeTaint, getMetricsForAllNodes, INodeMetrics, Node } from "../../../common/k8s-api/endpoints/nodes.api";
import { LineProgress } from "../line-progress";
import { bytesToUnits } from "../../../common/utils/convertMemory";
import { Tooltip, TooltipPosition } from "../tooltip";
@@ -227,6 +227,7 @@ export class Nodes extends React.Component<Props> {
]}
renderTableContents={node => {
const tooltipId = `node-taints-${node.getId()}`;
const taints = node.getTaints();
return [
<Badge flat key="name" label={node.getName()} tooltip={node.getName()} />,
@@ -235,9 +236,9 @@ export class Nodes extends React.Component<Props> {
this.renderMemoryUsage(node),
this.renderDiskUsage(node),
<>
<span id={tooltipId}>{node.getTaints().length}</span>
<span id={tooltipId}>{taints.length}</span>
<Tooltip targetId={tooltipId} tooltipOnParentHover={true} style={{ whiteSpace: "pre-line" }}>
{node.getTaints().map(({ key, value, effect }) => `${key}=${value}:${effect}`).join("\n")}
{taints.map(formatNodeTaint).join("\n")}
</Tooltip>
</>,
node.getRoleLabels(),
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { formatNodeTaint } from "../../../common/k8s-api/endpoints";
describe("formatNodeTaint tests", () => {
it("should use value if defined", () => {
expect(formatNodeTaint({
effect: "Foo",
key: "hello",
timeAdded: "pre",
value: "a"
})).toBe("hello=a:Foo");
});
it("should not use value if not defined", () => {
expect(formatNodeTaint({
effect: "Foo",
key: "hello",
timeAdded: "pre",
})).toBe("hello:Foo");
});
});
@@ -25,7 +25,7 @@
grid-template-rows: var(--main-layout-header);
grid-template-areas: "title controls";
background-color: var(--layoutBackground);
z-index: 1;
z-index: 2;
width: 100%;
grid-area: topbar;
}