Merge branch 'master' into feature/catalog

This commit is contained in:
Jari Kolehmainen committed 2021-04-06 10:45:21 +03:00
commit 92c1d73700
24 files changed
+229 -188

No files matched your search

+2 -1
View File
@@ -511,7 +511,8 @@ export class Cluster implements ClusterModel, ClusterState {
timeout: 0,
resolveWithFullResponse: false,
json: true,
qs: queryParams,
method: "POST",
form: queryParams,
});
}
+7 -6
View File
@@ -26,7 +26,7 @@ export class NodeShellSession extends ShellSession {
if (this.createNodeShellPod(this.podId, this.nodeName)) {
await this.waitForRunningPod(this.podId).catch(() => {
this.exit(1001);
this.exitAndClean(1001);
});
}
args = ["exec", "-i", "-t", "-n", "kube-system", this.podId, "--", "sh", "-c", "((clear && bash) || (clear && ash) || (clear && sh))"];
@@ -49,11 +49,14 @@ export class NodeShellSession extends ShellSession {
appEventBus.emit({name: "node-shell", action: "open"});
}
protected exit(code = 1000) {
protected exitAndClean(code = 1000) {
if (this.podId) {
this.deleteNodeShellPod();
}
super.exit(code);
if (code != 1000) {
this.sendResponse("Error occurred. ");
}
}
protected async createNodeShellPod(podId: string, nodeName: string) {
@@ -65,6 +68,7 @@ export class NodeShellSession extends ShellSession {
namespace: "kube-system"
},
spec: {
nodeName,
restartPolicy: "Never",
terminationGracePeriodSeconds: 0,
hostPID: true,
@@ -82,9 +86,6 @@ export class NodeShellSession extends ShellSession {
command: ["nsenter"],
args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"]
}],
nodeSelector: {
"kubernetes.io/hostname": nodeName
}
}
} as k8s.V1Pod;
+1 -7
View File
@@ -19,7 +19,6 @@ import { filesystemProvisionerStore } from "../main/extension-filesystem";
import { App } from "./components/app";
import { LensApp } from "./lens-app";
import { themeStore } from "./theme.store";
import { NonceProvider as StyleCache } from "react-select";
/**
* If this is a development buid, wait a second to attach
@@ -79,14 +78,9 @@ export async function bootstrap(App: AppComponent) {
window.location.href = "about:blank";
}
});
const cacheProps = { nonce: "lens", cacheKey: "lens" };
render(<>
{isMac && <div id="draggable-top" />}
<StyleCache {...cacheProps}>
<App />
</StyleCache>
<App />
</>, rootElem);
}
@@ -134,6 +134,7 @@ export class ClusterIssues extends React.Component<Props> {
<>Warnings: {warnings.length}</>
</SubHeader>
<Table
tableId="cluster_issues"
items={warnings}
virtual
selectable
@@ -1,41 +0,0 @@
.NamespaceSelectFilter {
.Select {
&__placeholder {
width: 100%;
white-space: nowrap;
overflow: scroll!important;
text-overflow: unset!important;
margin-left: -8px;
padding-left: 8px;
margin-right: -8px;
padding-right: 8px;
&::-webkit-scrollbar {
display: none;
}
}
&__value-container {
position: relative;
&::before, &::after {
content: ' ';
position: absolute;
z-index: 20;
display: block;
width: 8px;
height: var(--font-size);
}
&::before {
left: 0px;
background: linear-gradient(to right, var(--contentColor) 0px, transparent);
}
&::after {
right: 0px;
background: linear-gradient(to left, var(--contentColor) 0px, transparent);
}
}
}
}
@@ -2,7 +2,7 @@ import "./namespace-select.scss";
import React from "react";
import { observer } from "mobx-react";
import { components, OptionTypeBase, PlaceholderProps } from "react-select";
import { components, PlaceholderProps } from "react-select";
import { Icon } from "../icon";
import { FilterIcon } from "../item-object-list/filter-icon";
@@ -11,7 +11,7 @@ import { SelectOption } from "../select";
import { NamespaceSelect } from "./namespace-select";
import { namespaceStore } from "./namespace.store";
const Placeholder = observer((props: PlaceholderProps<OptionTypeBase, boolean>) => {
const Placeholder = observer((props: PlaceholderProps<any>) => {
const getPlaceholder = (): React.ReactNode => {
const namespaces = namespaceStore.contextNamespaces;
@@ -71,7 +71,6 @@ export class NamespaceSelectFilter extends React.Component {
placeholder={""}
onChange={this.onChange}
formatOptionLabel={this.formatOptionLabel}
className="NamespaceSelectFilter"
/>
);
}
@@ -23,6 +23,22 @@
.NamespaceSelect {
@include namespaceSelectCommon;
.Select {
&__placeholder {
width: 100%;
white-space: nowrap;
overflow: scroll;
margin-left: -8px;
padding-left: 8px;
margin-right: -8px;
padding-right: 8px;
&::-webkit-scrollbar {
display: none;
}
}
}
}
.NamespaceSelectMenu {
@@ -1,4 +1,4 @@
import "./namespace-select-filter.scss";
import "./namespace-select.scss";
import React from "react";
import { computed } from "mobx";
@@ -8,6 +8,7 @@ import { cssNames } from "../../utils";
import { Icon } from "../icon";
import { namespaceStore } from "./namespace.store";
import { kubeWatchApi } from "../../api/kube-watch-api";
import { components, ValueContainerProps } from "react-select";
interface Props extends SelectProps {
showIcons?: boolean;
@@ -21,6 +22,16 @@ const defaultProps: Partial<Props> = {
showClusterOption: false,
};
function GradientValueContainer<T>({children, ...rest}: ValueContainerProps<T>) {
return (
<components.ValueContainer {...rest}>
<div className="GradientValueContainer front" />
{children}
<div className="GradientValueContainer back" />
</components.ValueContainer>
);
}
@observer
export class NamespaceSelect extends React.Component<Props> {
static defaultProps = defaultProps as object;
@@ -66,6 +77,8 @@ export class NamespaceSelect extends React.Component<Props> {
render() {
const { className, showIcons, customizeOptions, components = {}, ...selectProps } = this.props;
components.ValueContainer ??= GradientValueContainer;
return (
<Select
className={cssNames("NamespaceSelect", className)}
@@ -5,7 +5,7 @@ import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
import { createPageParam } from "../../navigation";
import { apiManager } from "../../api/api-manager";
const selectedNamespaces = createStorage<string[]>("selected_namespaces");
const selectedNamespaces = createStorage<string[] | undefined>("selected_namespaces", undefined);
export const namespaceUrlParam = createPageParam<string[]>({
name: "namespaces",
@@ -20,7 +20,7 @@ export class PodSecurityPolicies extends React.Component {
return (
<KubeObjectListLayout
isConfigurable
tableId="access_roles"
tableId="access_pod_security_policies"
className="PodSecurityPolicies"
isClusterScoped={true}
store={podSecurityPoliciesStore}
@@ -64,6 +64,7 @@ export class VolumeDetailsList extends React.Component<Props> {
<div className="VolumeDetailsList flex column">
<DrawerTitle title="Persistent Volumes"/>
<Table
tableId="storage_volume_details_list"
items={persistentVolumes}
selectable
virtual={virtual}
@@ -135,6 +135,7 @@ export class PodDetailsList extends React.Component<Props> {
<div className="PodDetailsList flex column">
{showTitle && <DrawerTitle title="Pods"/>}
<Table
tableId="workloads_pod_details_list"
items={pods}
selectable
virtual={virtual}
@@ -43,6 +43,7 @@ const getTableRow = (toleration: IToleration) => {
export function PodTolerations({ tolerations }: Props) {
return (
<Table
tableId="workloads_pod_tolerations"
selectable
scrollable={false}
sortable={sortingCallbacks}
@@ -81,6 +81,6 @@ export class DockTabStore<T> {
reset() {
this.data.clear();
this.storage?.clear();
this.storage?.reset();
}
}
@@ -413,7 +413,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
renderList() {
const {
store, hasDetailsView, addRemoveButtons = {}, virtual, sortingCallbacks, detailsItem,
tableProps = {},
tableProps = {}, tableId
} = this.props;
const { isReady, removeItemsDialog, items } = this;
const { selectedItems } = store;
@@ -426,6 +426,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
)}
{isReady && (
<Table
tableId={tableId}
virtual={virtual}
selectable={hasDetailsView}
sortable={sortingCallbacks}
+15 -15
View File
@@ -6,29 +6,23 @@ import React, { ReactNode } from "react";
import { computed } from "mobx";
import { observer } from "mobx-react";
import { autobind, cssNames } from "../../utils";
import ReactSelect, { components } from "react-select";
import Creatable from "react-select/creatable";
import ReactSelect, { ActionMeta, components, Props as ReactSelectProps, Styles } from "react-select";
import Creatable, { CreatableProps } from "react-select/creatable";
import { themeStore } from "../../theme.store";
import type { ActionMeta, GroupTypeBase, OptionTypeBase, Props as ReactSelectProps, Styles as ReactSelectStyles } from "react-select";
const { Menu } = components;
type OptionType = { label: string; value: string };
type GroupType = GroupTypeBase<OptionType>;
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
label: ReactNode;
options: T[];
}
export interface SelectOption<T = any> {
value?: T;
value: T;
label?: React.ReactNode;
}
export interface SelectProps<T = any> extends ReactSelectProps<OptionTypeBase, boolean> {
options?: ReadonlyArray<OptionType | GroupType | unknown>;
export interface SelectProps<T = any> extends ReactSelectProps<T>, CreatableProps<T> {
value?: T;
themeName?: "dark" | "light" | "outlined";
menuClass?: string;
@@ -49,7 +43,7 @@ export class Select extends React.Component<SelectProps> {
return this.props.themeName || themeStore.activeTheme.type;
}
private styles: ReactSelectStyles<OptionTypeBase, boolean> = {
private styles: Styles = {
menuPortal: styles => ({
...styles,
zIndex: "auto"
@@ -74,10 +68,16 @@ export class Select extends React.Component<SelectProps> {
return this.options.find(opt => opt === value || opt.value === value);
}
@computed get options(): readonly SelectOption[] {
return this.props.options.map(opt => {
return this.isValidOption(opt) ? opt : { value: opt, label: String(opt) };
});
@computed get options(): SelectOption[] {
const { autoConvertOptions, options } = this.props;
if (autoConvertOptions && Array.isArray(options)) {
return options.map(opt => {
return this.isValidOption(opt) ? opt : { value: opt, label: String(opt) };
});
}
return options as SelectOption[];
}
@autobind()
@@ -0,0 +1,22 @@
import { createStorage } from "../../utils";
import { TableSortParams } from "./table";
export interface TableStorageModel {
sortParams: {
[tableId: string]: Partial<TableSortParams>;
}
}
export const tableStorage = createStorage<TableStorageModel>("table_settings", {
sortParams: {}
});
export function getSortParams(tableId: string): Partial<TableSortParams> {
return tableStorage.get().sortParams[tableId];
}
export function setSortParams(tableId: string, sortParams: Partial<TableSortParams>) {
tableStorage.merge(draft => {
draft.sortParams[tableId] = sortParams;
});
}
+15 -9
View File
@@ -3,7 +3,6 @@ import "./table.scss";
import React from "react";
import { orderBy } from "lodash";
import { observer } from "mobx-react";
import { observable } from "mobx";
import { autobind, cssNames, noop } from "../../utils";
import { TableRow, TableRowElem, TableRowProps } from "./table-row";
import { TableHead, TableHeadElem, TableHeadProps } from "./table-head";
@@ -11,6 +10,8 @@ import { TableCellElem } from "./table-cell";
import { VirtualList } from "../virtual-list";
import { createPageParam } from "../../navigation";
import { ItemObject } from "../../item.store";
import { getSortParams, setSortParams } from "./table.storage";
import { computed } from "mobx";
export type TableSortBy = string;
export type TableOrderBy = "asc" | "desc" | string;
@@ -19,6 +20,7 @@ export type TableSortCallback<D = any> = (data: D) => string | number | (string
export type TableSortCallbacks = { [columnId: string]: TableSortCallback };
export interface TableProps extends React.DOMAttributes<HTMLDivElement> {
tableId?: string;
items?: ItemObject[]; // Raw items data
className?: string;
autoSize?: boolean; // Setup auto-sizing for all columns (flex: 1 0)
@@ -62,13 +64,17 @@ export class Table extends React.Component<TableProps> {
sortSyncWithUrl: true,
};
@observable sortParams: Partial<TableSortParams> = Object.assign(
this.props.sortSyncWithUrl ? {
sortBy: sortByUrlParam.get(),
orderBy: orderByUrlParam.get(),
} : {},
this.props.sortByDefault,
);
componentDidMount() {
const { sortable, tableId } = this.props;
if (sortable && !tableId) {
console.error("[Table]: sorted table requires props.tableId to be specified");
}
}
@computed get sortParams() {
return Object.assign({}, this.props.sortByDefault, getSortParams(this.props.tableId));
}
renderHead() {
const { sortable, children } = this.props;
@@ -113,7 +119,7 @@ export class Table extends React.Component<TableProps> {
@autobind()
protected onSort({ sortBy, orderBy }: TableSortParams) {
this.sortParams = { sortBy, orderBy };
setSortParams(this.props.tableId, { sortBy, orderBy });
const { sortSyncWithUrl, onSort } = this.props;
if (sortSyncWithUrl) {
+1 -1
View File
@@ -2,7 +2,7 @@ import { useState } from "react";
import { createStorage } from "../utils";
import { CreateObservableOptions } from "mobx/lib/api/observable";
export function useStorage<T>(key: string, initialValue?: T, options?: CreateObservableOptions) {
export function useStorage<T>(key: string, initialValue: T, options?: CreateObservableOptions) {
const storage = createStorage(key, initialValue, options);
const [storageValue, setStorageValue] = useState(storage.get());
const setValue = (value: T) => {
@@ -142,17 +142,6 @@ describe("renderer/utils/StorageHelper", () => {
}));
expect(storageHelper.get()).toEqual({ ...storageHelperDefaultValue, message: "updated3" });
});
it("clears data in storage", () => {
storageHelper.init();
expect(storageHelper.get()).toBeTruthy();
storageHelper.clear();
expect(storageHelper.get()).toBeFalsy();
expect(storageMock[storageKey]).toBeUndefined();
expect(storageAdapter.removeItem).toHaveBeenCalledWith(storageHelper.key);
});
});
describe("data in storage-helper is observable (mobx)", () => {
+1 -1
View File
@@ -14,7 +14,7 @@ let initialized = false;
const loaded = observable.box(false);
const storage = observable.map<string/* key */, any /* serializable */>();
export function createStorage<T>(key: string, defaultValue?: T, observableOptions?: CreateObservableOptions) {
export function createStorage<T>(key: string, defaultValue: T, observableOptions?: CreateObservableOptions) {
const clusterId = getHostedClusterId();
const savingFolder = path.resolve((app || remote.app).getPath("userData"), "lens-local-storage");
const jsonFilePath = path.resolve(savingFolder, `${clusterId ?? "app"}.json`);
+7 -6
View File
@@ -21,7 +21,7 @@ export interface StorageHelperOptions<T> {
autoInit?: boolean; // start preloading data immediately, default: true
observable?: CreateObservableOptions;
storage: StorageAdapter<T>;
defaultValue?: T;
defaultValue: T;
}
export class StorageHelper<T> {
@@ -133,17 +133,18 @@ export class StorageHelper<T> {
}
set(value: T) {
this.data.set(value);
if (value == null) {
// This cannot use recursion because defaultValue might be null or undefined
this.data.set(this.defaultValue);
} else {
this.data.set(value);
}
}
reset() {
this.set(this.defaultValue);
}
clear() {
this.data.set(null);
}
merge(value: Partial<T> | ((draft: Draft<T>) => Partial<T> | void)) {
const nextValue = produce(this.get(), (state: Draft<T>) => {
const newValue = isFunction(value) ? value(state) : value;