mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into feature/command-palette
This commit is contained in:
commit
967fddc603
52 files changed
+974
-487
No files matched your search
@@ -36,6 +36,13 @@ describe("workspace store tests", () => {
|
||||
expect(ws.getById(WorkspaceStore.defaultId)).not.toBe(null);
|
||||
});
|
||||
|
||||
it("default workspace should be enabled", () => {
|
||||
const ws = WorkspaceStore.getInstance<WorkspaceStore>();
|
||||
|
||||
expect(ws.workspaces.size).toBe(1);
|
||||
expect(ws.getById(WorkspaceStore.defaultId).enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("cannot remove the default workspace", () => {
|
||||
const ws = WorkspaceStore.getInstance<WorkspaceStore>();
|
||||
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
import { getHostedCluster } from "./cluster-store";
|
||||
|
||||
export type KubeResource =
|
||||
"namespaces" | "nodes" | "events" | "resourcequotas" | "services" |
|
||||
"namespaces" | "nodes" | "events" | "resourcequotas" | "services" | "limitranges" |
|
||||
"secrets" | "configmaps" | "ingresses" | "networkpolicies" | "persistentvolumeclaims" | "persistentvolumes" | "storageclasses" |
|
||||
"pods" | "daemonsets" | "deployments" | "statefulsets" | "replicasets" | "jobs" | "cronjobs" |
|
||||
"endpoints" | "customresourcedefinitions" | "horizontalpodautoscalers" | "podsecuritypolicies" | "poddisruptionbudgets";
|
||||
@@ -23,6 +23,7 @@ export const apiResources: KubeApiResource[] = [
|
||||
{ resource: "horizontalpodautoscalers" },
|
||||
{ resource: "ingresses", group: "networking.k8s.io" },
|
||||
{ resource: "jobs", group: "batch" },
|
||||
{ resource: "limitranges" },
|
||||
{ resource: "namespaces" },
|
||||
{ resource: "networkpolicies", group: "networking.k8s.io" },
|
||||
{ resource: "nodes" },
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface UserPreferences {
|
||||
downloadBinariesPath?: string;
|
||||
kubectlBinariesPath?: string;
|
||||
openAtLogin?: boolean;
|
||||
hiddenTableColumns?: Record<string, string[]>
|
||||
}
|
||||
|
||||
export class UserStore extends BaseStore<UserStoreModel> {
|
||||
@@ -54,6 +55,7 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
||||
downloadMirror: "default",
|
||||
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
|
||||
openAtLogin: false,
|
||||
hiddenTableColumns: {},
|
||||
};
|
||||
|
||||
protected async handleOnLoad() {
|
||||
|
||||
@@ -58,14 +58,7 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
||||
* @observable
|
||||
*/
|
||||
@observable ownerRef?: string;
|
||||
/**
|
||||
* Is workspace enabled
|
||||
*
|
||||
* Workspaces that don't have ownerRef will be enabled by default. Workspaces with ownerRef need to explicitly enable a workspace.
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable enabled: boolean;
|
||||
|
||||
/**
|
||||
* Last active cluster id
|
||||
*
|
||||
@@ -73,6 +66,9 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
||||
*/
|
||||
@observable lastActiveClusterId?: ClusterId;
|
||||
|
||||
|
||||
@observable private _enabled: boolean;
|
||||
|
||||
constructor(data: WorkspaceModel) {
|
||||
Object.assign(this, data);
|
||||
|
||||
@@ -83,6 +79,21 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is workspace enabled
|
||||
*
|
||||
* Workspaces that don't have ownerRef will be enabled by default. Workspaces with ownerRef need to explicitly enable a workspace.
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
get enabled(): boolean {
|
||||
return !this.isManaged || this._enabled;
|
||||
}
|
||||
|
||||
set enabled(enabled: boolean) {
|
||||
this._enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is workspace managed by an extension
|
||||
*/
|
||||
@@ -134,10 +145,18 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
||||
static readonly defaultId: WorkspaceId = "default";
|
||||
private static stateRequestChannel = "workspace:states";
|
||||
|
||||
@observable currentWorkspaceId = WorkspaceStore.defaultId;
|
||||
@observable workspaces = observable.map<WorkspaceId, Workspace>();
|
||||
|
||||
private constructor() {
|
||||
super({
|
||||
configName: "lens-workspace-store",
|
||||
});
|
||||
|
||||
this.workspaces.set(WorkspaceStore.defaultId, new Workspace({
|
||||
id: WorkspaceStore.defaultId,
|
||||
name: "default"
|
||||
}));
|
||||
}
|
||||
|
||||
async load() {
|
||||
@@ -186,15 +205,6 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
||||
ipcRenderer.removeAllListeners("workspace:state");
|
||||
}
|
||||
|
||||
@observable currentWorkspaceId = WorkspaceStore.defaultId;
|
||||
|
||||
@observable workspaces = observable.map<WorkspaceId, Workspace>({
|
||||
[WorkspaceStore.defaultId]: new Workspace({
|
||||
id: WorkspaceStore.defaultId,
|
||||
name: "default"
|
||||
})
|
||||
});
|
||||
|
||||
@computed get currentWorkspace(): Workspace {
|
||||
return this.getById(this.currentWorkspaceId);
|
||||
}
|
||||
|
||||
@@ -38,4 +38,4 @@ export * from "../../renderer/components/+events/kube-event-details";
|
||||
// specific exports
|
||||
export * from "../../renderer/components/status-brick";
|
||||
export { terminalStore, createTerminalTab } from "../../renderer/components/dock/terminal.store";
|
||||
export { createPodLogsTab } from "../../renderer/components/dock/pod-logs.store";
|
||||
export { createPodLogsTab } from "../../renderer/components/dock/log.store";
|
||||
@@ -14,6 +14,7 @@ export { ConfigMap, configMapApi } from "../../renderer/api/endpoints";
|
||||
export { Secret, secretsApi, ISecretRef } from "../../renderer/api/endpoints";
|
||||
export { ReplicaSet, replicaSetApi } from "../../renderer/api/endpoints";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../renderer/api/endpoints";
|
||||
export { LimitRange, limitRangeApi } from "../../renderer/api/endpoints";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../renderer/api/endpoints";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../renderer/api/endpoints";
|
||||
export { Service, serviceApi } from "../../renderer/api/endpoints";
|
||||
@@ -46,6 +47,7 @@ export type { ConfigMapsStore } from "../../renderer/components/+config-maps/con
|
||||
export type { SecretsStore } from "../../renderer/components/+config-secrets/secrets.store";
|
||||
export type { ReplicaSetStore } from "../../renderer/components/+workloads-replicasets/replicasets.store";
|
||||
export type { ResourceQuotasStore } from "../../renderer/components/+config-resource-quotas/resource-quotas.store";
|
||||
export type { LimitRangesStore } from "../../renderer/components/+config-limit-ranges/limit-ranges.store";
|
||||
export type { HPAStore } from "../../renderer/components/+config-autoscalers/hpa.store";
|
||||
export type { PodDisruptionBudgetsStore } from "../../renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store";
|
||||
export type { ServiceStore } from "../../renderer/components/+network-services/services.store";
|
||||
|
||||
@@ -14,7 +14,7 @@ export class ClusterManager extends Singleton {
|
||||
// auto-init clusters
|
||||
autorun(() => {
|
||||
clusterStore.enabledClustersList.forEach(cluster => {
|
||||
if (!cluster.initialized) {
|
||||
if (!cluster.initialized && !cluster.initializing) {
|
||||
logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta());
|
||||
cluster.init(port);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,14 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
whenInitialized = when(() => this.initialized);
|
||||
whenReady = when(() => this.ready);
|
||||
|
||||
/**
|
||||
* Is cluster object initializinng on-going
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable initializing = false;
|
||||
|
||||
|
||||
/**
|
||||
* Is cluster object initialized
|
||||
*
|
||||
@@ -273,6 +281,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
*/
|
||||
@action async init(port: number) {
|
||||
try {
|
||||
this.initializing = true;
|
||||
this.contextHandler = new ContextHandler(this);
|
||||
this.kubeconfigManager = await KubeconfigManager.create(this, this.contextHandler, port);
|
||||
this.kubeProxyUrl = `http://localhost:${port}${apiKubePrefix}`;
|
||||
@@ -287,6 +296,8 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
id: this.id,
|
||||
error: err,
|
||||
});
|
||||
} finally {
|
||||
this.initializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export class HelmChart {
|
||||
tillerVersion?: string;
|
||||
|
||||
getId() {
|
||||
return this.digest;
|
||||
return `${this.apiVersion}/${this.name}@${this.getAppVersion()}`;
|
||||
}
|
||||
|
||||
getName() {
|
||||
|
||||
@@ -14,6 +14,7 @@ export * from "./events.api";
|
||||
export * from "./hpa.api";
|
||||
export * from "./ingress.api";
|
||||
export * from "./job.api";
|
||||
export * from "./limit-range.api";
|
||||
export * from "./namespaces.api";
|
||||
export * from "./network-policy.api";
|
||||
export * from "./nodes.api";
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autobind } from "../../utils";
|
||||
|
||||
export enum LimitType {
|
||||
CONTAINER = "Container",
|
||||
POD = "Pod",
|
||||
PVC = "PersistentVolumeClaim",
|
||||
}
|
||||
|
||||
export enum Resource {
|
||||
MEMORY = "memory",
|
||||
CPU = "cpu",
|
||||
STORAGE = "storage",
|
||||
EPHEMERAL_STORAGE = "ephemeral-storage",
|
||||
}
|
||||
|
||||
export enum LimitPart {
|
||||
MAX = "max",
|
||||
MIN = "min",
|
||||
DEFAULT = "default",
|
||||
DEFAULT_REQUEST = "defaultRequest",
|
||||
MAX_LIMIT_REQUEST_RATIO = "maxLimitRequestRatio",
|
||||
}
|
||||
|
||||
type LimitRangeParts = Partial<Record<LimitPart, Record<string, string>>>;
|
||||
|
||||
export interface LimitRangeItem extends LimitRangeParts {
|
||||
type: string
|
||||
}
|
||||
|
||||
@autobind()
|
||||
export class LimitRange extends KubeObject {
|
||||
static kind = "LimitRange";
|
||||
static namespaced = true;
|
||||
static apiBase = "/api/v1/limitranges";
|
||||
|
||||
spec: {
|
||||
limits: LimitRangeItem[];
|
||||
};
|
||||
|
||||
getContainerLimits() {
|
||||
return this.spec.limits.filter(limit => limit.type === LimitType.CONTAINER);
|
||||
}
|
||||
|
||||
getPodLimits() {
|
||||
return this.spec.limits.filter(limit => limit.type === LimitType.POD);
|
||||
}
|
||||
|
||||
getPVCLimits() {
|
||||
return this.spec.limits.filter(limit => limit.type === LimitType.PVC);
|
||||
}
|
||||
}
|
||||
|
||||
export const limitRangeApi = new KubeApi({
|
||||
objectConstructor: LimitRange,
|
||||
});
|
||||
@@ -23,11 +23,13 @@ interface IWarning extends ItemObject {
|
||||
kind: string;
|
||||
message: string;
|
||||
selfLink: string;
|
||||
age: string | number;
|
||||
}
|
||||
|
||||
enum sortBy {
|
||||
type = "type",
|
||||
object = "object"
|
||||
object = "object",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
@observer
|
||||
@@ -35,6 +37,7 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
private sortCallbacks = {
|
||||
[sortBy.type]: (warning: IWarning) => warning.kind,
|
||||
[sortBy.object]: (warning: IWarning) => warning.getName(),
|
||||
[sortBy.age]: (warning: IWarning) => warning.age || "",
|
||||
};
|
||||
|
||||
@computed get warnings() {
|
||||
@@ -42,15 +45,16 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
|
||||
// Node bad conditions
|
||||
nodesStore.items.forEach(node => {
|
||||
const { kind, selfLink, getId, getName } = node;
|
||||
const { kind, selfLink, getId, getName, getAge } = node;
|
||||
|
||||
node.getWarningConditions().forEach(({ message }) => {
|
||||
warnings.push({
|
||||
kind,
|
||||
age: getAge(),
|
||||
getId,
|
||||
getName,
|
||||
selfLink,
|
||||
kind,
|
||||
message,
|
||||
selfLink,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -59,12 +63,13 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
const events = eventStore.getWarnings();
|
||||
|
||||
events.forEach(error => {
|
||||
const { message, involvedObject } = error;
|
||||
const { message, involvedObject, getAge } = error;
|
||||
const { uid, name, kind } = involvedObject;
|
||||
|
||||
warnings.push({
|
||||
getId: () => uid,
|
||||
getName: () => name,
|
||||
age: getAge(),
|
||||
message,
|
||||
kind,
|
||||
selfLink: lookupApiLink(involvedObject, error),
|
||||
@@ -78,7 +83,7 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
getTableRow(uid: string) {
|
||||
const { warnings } = this;
|
||||
const warning = warnings.find(warn => warn.getId() == uid);
|
||||
const { getId, getName, message, kind, selfLink } = warning;
|
||||
const { getId, getName, message, kind, selfLink, age } = warning;
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
@@ -96,6 +101,9 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
<TableCell className="kind">
|
||||
{kind}
|
||||
</TableCell>
|
||||
<TableCell className="age">
|
||||
{age}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
@@ -139,6 +147,7 @@ export class ClusterIssues extends React.Component<Props> {
|
||||
<TableCell className="message">Message</TableCell>
|
||||
<TableCell className="object" sortBy={sortBy.object}>Object</TableCell>
|
||||
<TableCell className="kind" sortBy={sortBy.type}>Type</TableCell>
|
||||
<TableCell className="timestamp" sortBy={sortBy.age}>Age</TableCell>
|
||||
</TableHead>
|
||||
</Table>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./limit-ranges";
|
||||
export * from "./limit-ranges.route";
|
||||
export * from "./limit-range-details";
|
||||
@@ -0,0 +1,12 @@
|
||||
.LimitRangeDetails {
|
||||
|
||||
.DrawerItem {
|
||||
> .name {
|
||||
font-weight: $font-weight-normal;
|
||||
padding-left: 4px;
|
||||
}
|
||||
.DrawerItem {
|
||||
padding-top: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import "./limit-range-details.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { KubeObjectDetailsProps } from "../kube-object";
|
||||
import { LimitPart, LimitRange, LimitRangeItem, Resource } from "../../api/endpoints/limit-range.api";
|
||||
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { DrawerItem } from "../drawer/drawer-item";
|
||||
import { Badge } from "../badge";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<LimitRange> {
|
||||
}
|
||||
|
||||
function renderLimit(limit: LimitRangeItem, part: LimitPart, resource: Resource) {
|
||||
|
||||
const resourceLimit = limit[part]?.[resource];
|
||||
|
||||
if (!resourceLimit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <Badge label={`${part}:${resourceLimit}`}/>;
|
||||
}
|
||||
|
||||
function renderResourceLimits(limit: LimitRangeItem, resource: Resource) {
|
||||
return (
|
||||
<React.Fragment key={limit.type + resource}>
|
||||
{renderLimit(limit, LimitPart.MIN, resource)}
|
||||
{renderLimit(limit, LimitPart.MAX, resource)}
|
||||
{renderLimit(limit, LimitPart.DEFAULT, resource)}
|
||||
{renderLimit(limit, LimitPart.DEFAULT_REQUEST, resource)}
|
||||
{renderLimit(limit, LimitPart.MAX_LIMIT_REQUEST_RATIO, resource)}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
function renderLimitDetails(limits: LimitRangeItem[], resources: Resource[]) {
|
||||
|
||||
return resources.map(resource =>
|
||||
<DrawerItem key={resource} name={resource}>
|
||||
{
|
||||
limits.map(limit =>
|
||||
renderResourceLimits(limit, resource)
|
||||
)
|
||||
}
|
||||
</DrawerItem>
|
||||
);
|
||||
}
|
||||
|
||||
@observer
|
||||
export class LimitRangeDetails extends React.Component<Props> {
|
||||
render() {
|
||||
const { object: limitRange } = this.props;
|
||||
|
||||
if (!limitRange) return null;
|
||||
const containerLimits = limitRange.getContainerLimits();
|
||||
const podLimits = limitRange.getPodLimits();
|
||||
const pvcLimits = limitRange.getPVCLimits();
|
||||
|
||||
return (
|
||||
<div className="LimitRangeDetails">
|
||||
<KubeObjectMeta object={limitRange}/>
|
||||
|
||||
{containerLimits.length > 0 &&
|
||||
<DrawerItem name={`Container Limits`} labelsOnly>
|
||||
{
|
||||
renderLimitDetails(containerLimits, [Resource.CPU, Resource.MEMORY, Resource.EPHEMERAL_STORAGE])
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
{podLimits.length > 0 &&
|
||||
<DrawerItem name={`Pod Limits`} labelsOnly>
|
||||
{
|
||||
renderLimitDetails(podLimits, [Resource.CPU, Resource.MEMORY, Resource.EPHEMERAL_STORAGE])
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
{pvcLimits.length > 0 &&
|
||||
<DrawerItem name={`Persistent Volume Claim Limits`} labelsOnly>
|
||||
{
|
||||
renderLimitDetails(pvcLimits, [Resource.STORAGE])
|
||||
}
|
||||
</DrawerItem>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
kubeObjectDetailRegistry.add({
|
||||
kind: "LimitRange",
|
||||
apiVersions: ["v1"],
|
||||
components: {
|
||||
Details: (props) => <LimitRangeDetails {...props} />
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { RouteProps } from "react-router";
|
||||
import { buildURL } from "../../../common/utils/buildUrl";
|
||||
|
||||
export const limitRangesRoute: RouteProps = {
|
||||
path: "/limitranges"
|
||||
};
|
||||
|
||||
export interface LimitRangeRouteParams {
|
||||
}
|
||||
|
||||
export const limitRangeURL = buildURL<LimitRangeRouteParams>(limitRangesRoute.path);
|
||||
@@ -0,0 +1,7 @@
|
||||
.LimitRanges {
|
||||
.TableCell {
|
||||
&.warning {
|
||||
@include table-cell-warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { autobind } from "../../../common/utils/autobind";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { apiManager } from "../../api/api-manager";
|
||||
import { LimitRange, limitRangeApi } from "../../api/endpoints/limit-range.api";
|
||||
|
||||
@autobind()
|
||||
export class LimitRangesStore extends KubeObjectStore<LimitRange> {
|
||||
api = limitRangeApi;
|
||||
}
|
||||
|
||||
export const limitRangeStore = new LimitRangesStore();
|
||||
apiManager.registerStore(limitRangeStore);
|
||||
@@ -0,0 +1,53 @@
|
||||
import "./limit-ranges.scss";
|
||||
|
||||
import { RouteComponentProps } from "react-router";
|
||||
import { observer } from "mobx-react";
|
||||
import { KubeObjectListLayout } from "../kube-object/kube-object-list-layout";
|
||||
import { limitRangeStore } from "./limit-ranges.store";
|
||||
import { LimitRangeRouteParams } from "./limit-ranges.route";
|
||||
import React from "react";
|
||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||
import { LimitRange } from "../../api/endpoints/limit-range.api";
|
||||
|
||||
enum sortBy {
|
||||
name = "name",
|
||||
namespace = "namespace",
|
||||
age = "age",
|
||||
}
|
||||
|
||||
interface Props extends RouteComponentProps<LimitRangeRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class LimitRanges extends React.Component<Props> {
|
||||
render() {
|
||||
return (
|
||||
<KubeObjectListLayout
|
||||
className="LimitRanges"
|
||||
store={limitRangeStore}
|
||||
sortingCallbacks={{
|
||||
[sortBy.name]: (item: LimitRange) => item.getName(),
|
||||
[sortBy.namespace]: (item: LimitRange) => item.getNs(),
|
||||
[sortBy.age]: (item: LimitRange) => item.metadata.creationTimestamp,
|
||||
}}
|
||||
searchFilters={[
|
||||
(item: LimitRange) => item.getName(),
|
||||
(item: LimitRange) => item.getNs(),
|
||||
]}
|
||||
renderHeaderTitle={"Limit Ranges"}
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: sortBy.name },
|
||||
{ className: "warning" },
|
||||
{ title: "Namespace", className: "namespace", sortBy: sortBy.namespace },
|
||||
{ title: "Age", className: "age", sortBy: sortBy.age },
|
||||
]}
|
||||
renderTableContents={(limitRange: LimitRange) => [
|
||||
limitRange.getName(),
|
||||
<KubeObjectStatusIcon key="icon" object={limitRange}/>,
|
||||
limitRange.getNs(),
|
||||
limitRange.getAge(),
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { resourceQuotaRoute, ResourceQuotas, resourceQuotaURL } from "../+config
|
||||
import { pdbRoute, pdbURL, PodDisruptionBudgets } from "../+config-pod-disruption-budgets";
|
||||
import { HorizontalPodAutoscalers, hpaRoute, hpaURL } from "../+config-autoscalers";
|
||||
import { isAllowedResource } from "../../../common/rbac";
|
||||
import { LimitRanges, limitRangesRoute, limitRangeURL } from "../+config-limit-ranges";
|
||||
|
||||
@observer
|
||||
export class Config extends React.Component {
|
||||
@@ -42,6 +43,15 @@ export class Config extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
if (isAllowedResource("limitranges")) {
|
||||
routes.push({
|
||||
title: "Limit Ranges",
|
||||
component: LimitRanges,
|
||||
url: limitRangeURL({ query }),
|
||||
routePath: limitRangesRoute.path.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
if (isAllowedResource("horizontalpodautoscalers")) {
|
||||
routes.push({
|
||||
title: "HPA",
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Spinner } from "../spinner";
|
||||
import { resourceQuotaStore } from "../+config-resource-quotas/resource-quotas.store";
|
||||
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
|
||||
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
|
||||
import { limitRangeStore } from "../+config-limit-ranges/limit-ranges.store";
|
||||
|
||||
interface Props extends KubeObjectDetailsProps<Namespace> {
|
||||
}
|
||||
@@ -24,8 +25,15 @@ export class NamespaceDetails extends React.Component<Props> {
|
||||
return resourceQuotaStore.getAllByNs(namespace);
|
||||
}
|
||||
|
||||
@computed get limitranges() {
|
||||
const namespace = this.props.object.getName();
|
||||
|
||||
return limitRangeStore.getAllByNs(namespace);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
resourceQuotaStore.loadAll();
|
||||
limitRangeStore.loadAll();
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -52,6 +60,16 @@ export class NamespaceDetails extends React.Component<Props> {
|
||||
);
|
||||
})}
|
||||
</DrawerItem>
|
||||
<DrawerItem name={`Limit Ranges`}>
|
||||
{!this.limitranges && limitRangeStore.isLoading && <Spinner/>}
|
||||
{this.limitranges.map(limitrange => {
|
||||
return (
|
||||
<Link key={limitrange.getId()} to={getDetailsUrl(limitrange.selfLink)}>
|
||||
{limitrange.getName()}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</DrawerItem>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ export class Pods extends React.Component<Props> {
|
||||
<KubeObjectListLayout
|
||||
className="Pods" store={podsStore}
|
||||
dependentStores={[volumeClaimStore, eventStore]}
|
||||
tableId = "workloads_pods"
|
||||
isConfigurable
|
||||
sortingCallbacks={{
|
||||
[sortBy.name]: (pod: Pod) => pod.getName(),
|
||||
[sortBy.namespace]: (pod: Pod) => pod.getNs(),
|
||||
@@ -94,7 +96,7 @@ export class Pods extends React.Component<Props> {
|
||||
renderHeaderTitle="Pods"
|
||||
renderTableHeader={[
|
||||
{ title: "Name", className: "name", sortBy: sortBy.name },
|
||||
{ className: "warning" },
|
||||
{ className: "warning", showWithColumn: "name" },
|
||||
{ title: "Namespace", className: "namespace", sortBy: sortBy.namespace },
|
||||
{ title: "Containers", className: "containers", sortBy: sortBy.containers },
|
||||
{ title: "Restarts", className: "restarts", sortBy: sortBy.restarts },
|
||||
|
||||
@@ -30,7 +30,7 @@ export class Checkbox extends React.PureComponent<CheckboxProps> {
|
||||
|
||||
render() {
|
||||
const { label, inline, className, value, theme, children, ...inputProps } = this.props;
|
||||
const componentClass = cssNames("Checkbox flex", className, {
|
||||
const componentClass = cssNames("Checkbox flex align-center", className, {
|
||||
inline,
|
||||
checked: value,
|
||||
disabled: this.props.disabled,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { DockTab } from "./dock-tab";
|
||||
import { IDockTab } from "./dock.store";
|
||||
import { isEditResourceTab } from "./edit-resource.store";
|
||||
import { isInstallChartTab } from "./install-chart.store";
|
||||
import { isPodLogsTab } from "./pod-logs.store";
|
||||
import { isLogsTab } from "./log.store";
|
||||
import { TerminalTab } from "./terminal-tab";
|
||||
import { isTerminalTab } from "./terminal.store";
|
||||
import { isUpgradeChartTab } from "./upgrade-chart.store";
|
||||
@@ -33,7 +33,7 @@ export const DockTabs = ({ tabs, autoFocus, selectedTab, onChangeTab }: Props) =
|
||||
return <DockTab value={tab} icon={<Icon svg="install" />} />;
|
||||
}
|
||||
|
||||
if (isPodLogsTab(tab)) {
|
||||
if (isLogsTab(tab)) {
|
||||
return <DockTab value={tab} icon="subject" />;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,8 +16,8 @@ import { EditResource } from "./edit-resource";
|
||||
import { isEditResourceTab } from "./edit-resource.store";
|
||||
import { InstallChart } from "./install-chart";
|
||||
import { isInstallChartTab } from "./install-chart.store";
|
||||
import { PodLogs } from "./pod-logs";
|
||||
import { isPodLogsTab } from "./pod-logs.store";
|
||||
import { Logs } from "./logs";
|
||||
import { isLogsTab } from "./log.store";
|
||||
import { TerminalWindow } from "./terminal-window";
|
||||
import { createTerminalTab, isTerminalTab } from "./terminal.store";
|
||||
import { UpgradeChart } from "./upgrade-chart";
|
||||
@@ -64,7 +64,7 @@ export class Dock extends React.Component<Props> {
|
||||
{isInstallChartTab(tab) && <InstallChart tab={tab} />}
|
||||
{isUpgradeChartTab(tab) && <UpgradeChart tab={tab} />}
|
||||
{isTerminalTab(tab) && <TerminalWindow tab={tab} />}
|
||||
{isPodLogsTab(tab) && <PodLogs tab={tab} />}
|
||||
{isLogsTab(tab) && <Logs tab={tab} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
@include hidden-scrollbar;
|
||||
|
||||
background: $dockInfoBackground;
|
||||
border-bottom: 1px solid $dockInfoBorderColor;
|
||||
padding: $padding $padding * 2;
|
||||
flex-shrink: 0;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
.LogControls {
|
||||
@include hidden-scrollbar;
|
||||
|
||||
background: $dockInfoBackground;
|
||||
padding: $padding $padding * 2;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import "./log-controls.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
import { Pod } from "../../api/endpoints";
|
||||
import { cssNames, saveFileDialog } from "../../utils";
|
||||
import { IPodLogsData, podLogsStore } from "./log.store";
|
||||
import { Checkbox } from "../checkbox";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
interface Props {
|
||||
tabData: IPodLogsData
|
||||
logs: string[]
|
||||
save: (data: Partial<IPodLogsData>) => void
|
||||
reload: () => void
|
||||
}
|
||||
|
||||
export const LogControls = observer((props: Props) => {
|
||||
const { tabData, save, reload, logs } = props;
|
||||
const { showTimestamps, previous } = tabData;
|
||||
const since = logs.length ? podLogsStore.getTimestamps(logs[0]) : null;
|
||||
const pod = new Pod(tabData.pod);
|
||||
|
||||
const toggleTimestamps = () => {
|
||||
save({ showTimestamps: !showTimestamps });
|
||||
};
|
||||
|
||||
const togglePrevious = () => {
|
||||
save({ previous: !previous });
|
||||
reload();
|
||||
};
|
||||
|
||||
const downloadLogs = () => {
|
||||
const fileName = pod.getName();
|
||||
const logsToDownload = showTimestamps ? logs : podLogsStore.logsWithoutTimestamps;
|
||||
|
||||
saveFileDialog(`${fileName}.log`, logsToDownload.join("\n"), "text/plain");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cssNames("LogControls flex gaps align-center justify-space-between wrap")}>
|
||||
<div className="time-range">
|
||||
{since && `Logs from ${new Date(since[0]).toLocaleString()}`}
|
||||
</div>
|
||||
<div className="flex gaps align-center">
|
||||
<Checkbox
|
||||
label="Show timestamps"
|
||||
value={showTimestamps}
|
||||
onChange={toggleTimestamps}
|
||||
className="show-timestamps"
|
||||
/>
|
||||
<Checkbox
|
||||
label="Show previous terminated container"
|
||||
value={previous}
|
||||
onChange={togglePrevious}
|
||||
className="show-previous"
|
||||
/>
|
||||
<Icon
|
||||
material="get_app"
|
||||
onClick={downloadLogs}
|
||||
tooltip="Download"
|
||||
className="download-icon"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
.PodLogList {
|
||||
.LogList {
|
||||
--overlay-bg: #8cc474b8;
|
||||
--overlay-active-bg: orange;
|
||||
|
||||
+10
-6
@@ -1,4 +1,4 @@
|
||||
import "./pod-log-list.scss";
|
||||
import "./log-list.scss";
|
||||
|
||||
import React from "react";
|
||||
import AnsiUp from "ansi_up";
|
||||
@@ -14,7 +14,7 @@ import { Button } from "../button";
|
||||
import { Icon } from "../icon";
|
||||
import { Spinner } from "../spinner";
|
||||
import { VirtualList } from "../virtual-list";
|
||||
import { podLogsStore } from "./pod-logs.store";
|
||||
import { podLogsStore } from "./log.store";
|
||||
|
||||
interface Props {
|
||||
logs: string[]
|
||||
@@ -26,7 +26,7 @@ interface Props {
|
||||
const colorConverter = new AnsiUp();
|
||||
|
||||
@observer
|
||||
export class PodLogList extends React.Component<Props> {
|
||||
export class LogList extends React.Component<Props> {
|
||||
@observable isJumpButtonVisible = false;
|
||||
@observable isLastLineVisible = true;
|
||||
|
||||
@@ -206,19 +206,23 @@ export class PodLogList extends React.Component<Props> {
|
||||
const rowHeights = new Array(this.logs.length).fill(this.lineHeight);
|
||||
|
||||
if (isInitLoading) {
|
||||
return <Spinner center/>;
|
||||
return (
|
||||
<div className="LogList flex box grow align-center justify-center">
|
||||
<Spinner center/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.logs.length) {
|
||||
return (
|
||||
<div className="PodLogList flex box grow align-center justify-center">
|
||||
<div className="LogList flex box grow align-center justify-center">
|
||||
There are no logs available for container
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cssNames("PodLogList flex", { isLoading })}>
|
||||
<div className={cssNames("LogList flex", { isLoading })}>
|
||||
<VirtualList
|
||||
items={this.logs}
|
||||
rowHeights={rowHeights}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
.PodLogControls {
|
||||
.LogResourceSelector {
|
||||
.Select {
|
||||
min-width: 150px;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import "./log-resource-selector.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
import { IPodContainer, Pod } from "../../api/endpoints";
|
||||
import { Badge } from "../badge";
|
||||
import { Select, SelectOption } from "../select";
|
||||
import { IPodLogsData } from "./log.store";
|
||||
|
||||
interface Props {
|
||||
tabData: IPodLogsData
|
||||
save: (data: Partial<IPodLogsData>) => void
|
||||
reload: () => void
|
||||
}
|
||||
|
||||
export const LogResourceSelector = observer((props: Props) => {
|
||||
const { tabData, save, reload } = props;
|
||||
const { selectedContainer, containers, initContainers } = tabData;
|
||||
const pod = new Pod(tabData.pod);
|
||||
|
||||
const onContainerChange = (option: SelectOption) => {
|
||||
const { containers, initContainers } = tabData;
|
||||
|
||||
save({
|
||||
selectedContainer: containers
|
||||
.concat(initContainers)
|
||||
.find(container => container.name === option.value)
|
||||
});
|
||||
reload();
|
||||
};
|
||||
|
||||
const getSelectOptions = (containers: IPodContainer[]) => {
|
||||
return containers.map(container => {
|
||||
return {
|
||||
value: container.name,
|
||||
label: container.name
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const containerSelectOptions = [
|
||||
{
|
||||
label: `Containers`,
|
||||
options: getSelectOptions(containers)
|
||||
},
|
||||
{
|
||||
label: `Init Containers`,
|
||||
options: getSelectOptions(initContainers),
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="LogResourceSelector flex gaps align-center">
|
||||
<span>Namespace</span> <Badge label={pod.getNs()}/>
|
||||
<span>Pod</span> <Badge label={pod.getName()}/>
|
||||
<span>Container</span>
|
||||
<Select
|
||||
options={containerSelectOptions}
|
||||
value={{ label: selectedContainer.name, value: selectedContainer.name }}
|
||||
onChange={onContainerChange}
|
||||
autoConvertOptions={false}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
+5
-2
@@ -1,10 +1,13 @@
|
||||
.PodLogsSearch {
|
||||
.LogSearch {
|
||||
.SearchInput {
|
||||
min-width: 150px;
|
||||
width: 150px;
|
||||
|
||||
.find-count {
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
label {
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-9
@@ -1,4 +1,4 @@
|
||||
import "./pod-log-search.scss";
|
||||
import "./log-search.scss";
|
||||
|
||||
import React, { useEffect } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
@@ -16,7 +16,7 @@ interface Props extends PodLogSearchProps {
|
||||
logs: string[]
|
||||
}
|
||||
|
||||
export const PodLogSearch = observer((props: Props) => {
|
||||
export const LogSearch = observer((props: Props) => {
|
||||
const { logs, onSearch, toPrevOverlay, toNextOverlay } = props;
|
||||
const { setNextOverlayActive, setPrevOverlayActive, searchQuery, occurrences, activeFind, totalFinds } = searchStore;
|
||||
const jumpDisabled = !searchQuery || !occurrences.length;
|
||||
@@ -57,11 +57,11 @@ export const PodLogSearch = observer((props: Props) => {
|
||||
}, [logs]);
|
||||
|
||||
return (
|
||||
<div className="PodLogsSearch flex box grow justify-flex-end gaps align-center">
|
||||
<div className="LogSearch flex box grow justify-flex-end gaps align-center">
|
||||
<SearchInput
|
||||
value={searchQuery}
|
||||
onChange={setSearch}
|
||||
showClearIcon={false}
|
||||
showClearIcon={true}
|
||||
contentRight={totalFinds > 0 && findCounts}
|
||||
onClear={onClear}
|
||||
onKeyDown={onKeyDown}
|
||||
@@ -78,11 +78,6 @@ export const PodLogSearch = observer((props: Props) => {
|
||||
onClick={onNextOverlay}
|
||||
disabled={jumpDisabled}
|
||||
/>
|
||||
<Icon
|
||||
material="close"
|
||||
tooltip={`Clear`}
|
||||
onClick={onClear}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
+4
-4
@@ -21,7 +21,7 @@ type PodLogLine = string;
|
||||
export const logRange = 500;
|
||||
|
||||
@autobind()
|
||||
export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
||||
export class LogStore extends DockTabStore<IPodLogsData> {
|
||||
private refresher = interval(10, () => {
|
||||
const id = dockStore.selectedTabId;
|
||||
|
||||
@@ -39,7 +39,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
||||
autorun(() => {
|
||||
const { selectedTab, isOpen } = dockStore;
|
||||
|
||||
if (isPodLogsTab(selectedTab) && isOpen) {
|
||||
if (isLogsTab(selectedTab) && isOpen) {
|
||||
this.refresher.start();
|
||||
} else {
|
||||
this.refresher.stop();
|
||||
@@ -203,7 +203,7 @@ export class PodLogsStore extends DockTabStore<IPodLogsData> {
|
||||
}
|
||||
}
|
||||
|
||||
export const podLogsStore = new PodLogsStore();
|
||||
export const podLogsStore = new LogStore();
|
||||
|
||||
export function createPodLogsTab(data: IPodLogsData, tabParams: Partial<IDockTab> = {}) {
|
||||
const podId = data.pod.getId();
|
||||
@@ -227,6 +227,6 @@ export function createPodLogsTab(data: IPodLogsData, tabParams: Partial<IDockTab
|
||||
return tab;
|
||||
}
|
||||
|
||||
export function isPodLogsTab(tab: IDockTab) {
|
||||
export function isLogsTab(tab: IDockTab) {
|
||||
return tab && tab.kind === TabKind.POD_LOGS;
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import { searchStore } from "../../../common/search-store";
|
||||
import { autobind } from "../../utils";
|
||||
import { IDockTab } from "./dock.store";
|
||||
import { InfoPanel } from "./info-panel";
|
||||
import { PodLogControls } from "./pod-log-controls";
|
||||
import { PodLogList } from "./pod-log-list";
|
||||
import { IPodLogsData, podLogsStore } from "./pod-logs.store";
|
||||
import { LogResourceSelector } from "./log-resource-selector";
|
||||
import { LogList } from "./log-list";
|
||||
import { IPodLogsData, podLogsStore } from "./log.store";
|
||||
import { LogSearch } from "./log-search";
|
||||
import { LogControls } from "./log-controls";
|
||||
|
||||
interface Props {
|
||||
className?: string
|
||||
@@ -16,10 +18,10 @@ interface Props {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class PodLogs extends React.Component<Props> {
|
||||
export class Logs extends React.Component<Props> {
|
||||
@observable isLoading = true;
|
||||
|
||||
private logListElement = React.createRef<PodLogList>(); // A reference for VirtualList component
|
||||
private logListElement = React.createRef<LogList>(); // A reference for VirtualList component
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this,
|
||||
@@ -79,39 +81,55 @@ export class PodLogs extends React.Component<Props> {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
render() {
|
||||
renderResourceSelector() {
|
||||
const logs = podLogsStore.logs;
|
||||
|
||||
const searchLogs = this.tabData.showTimestamps ? logs : podLogsStore.logsWithoutTimestamps;
|
||||
const controls = (
|
||||
<PodLogControls
|
||||
ready={!this.isLoading}
|
||||
tabId={this.tabId}
|
||||
tabData={this.tabData}
|
||||
logs={logs}
|
||||
save={this.save}
|
||||
reload={this.reload}
|
||||
onSearch={this.onSearch}
|
||||
toPrevOverlay={this.toOverlay}
|
||||
toNextOverlay={this.toOverlay}
|
||||
/>
|
||||
<div className="flex gaps">
|
||||
<LogResourceSelector
|
||||
tabData={this.tabData}
|
||||
save={this.save}
|
||||
reload={this.reload}
|
||||
/>
|
||||
<LogSearch
|
||||
onSearch={this.onSearch}
|
||||
logs={searchLogs}
|
||||
toPrevOverlay={this.toOverlay}
|
||||
toNextOverlay={this.toOverlay}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<InfoPanel
|
||||
tabId={this.props.tab.id}
|
||||
controls={controls}
|
||||
showSubmitClose={false}
|
||||
showButtons={false}
|
||||
showStatusPanel={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const logs = podLogsStore.logs;
|
||||
|
||||
return (
|
||||
<div className="PodLogs flex column">
|
||||
<InfoPanel
|
||||
tabId={this.props.tab.id}
|
||||
controls={controls}
|
||||
showSubmitClose={false}
|
||||
showButtons={false}
|
||||
showStatusPanel={false}
|
||||
/>
|
||||
<PodLogList
|
||||
{this.renderResourceSelector()}
|
||||
<LogList
|
||||
logs={logs}
|
||||
id={this.tabId}
|
||||
isLoading={this.isLoading}
|
||||
load={this.load}
|
||||
ref={this.logListElement}
|
||||
/>
|
||||
<LogControls
|
||||
logs={logs}
|
||||
tabData={this.tabData}
|
||||
save={this.save}
|
||||
reload={this.reload}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import "./pod-log-controls.scss";
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { IPodLogsData, podLogsStore } from "./pod-logs.store";
|
||||
import { Select, SelectOption } from "../select";
|
||||
import { Badge } from "../badge";
|
||||
import { Icon } from "../icon";
|
||||
import { cssNames, saveFileDialog } from "../../utils";
|
||||
import { Pod } from "../../api/endpoints";
|
||||
import { PodLogSearch, PodLogSearchProps } from "./pod-log-search";
|
||||
|
||||
interface Props extends PodLogSearchProps {
|
||||
ready: boolean
|
||||
tabId: string
|
||||
tabData: IPodLogsData
|
||||
logs: string[]
|
||||
save: (data: Partial<IPodLogsData>) => void
|
||||
reload: () => void
|
||||
onSearch: (query: string) => void
|
||||
}
|
||||
|
||||
export const PodLogControls = observer((props: Props) => {
|
||||
const { tabData, save, reload, logs } = props;
|
||||
const { selectedContainer, showTimestamps, previous } = tabData;
|
||||
const since = logs.length ? podLogsStore.getTimestamps(logs[0]) : null;
|
||||
const pod = new Pod(tabData.pod);
|
||||
|
||||
const toggleTimestamps = () => {
|
||||
save({ showTimestamps: !showTimestamps });
|
||||
};
|
||||
|
||||
const togglePrevious = () => {
|
||||
save({ previous: !previous });
|
||||
reload();
|
||||
};
|
||||
|
||||
const downloadLogs = () => {
|
||||
const fileName = selectedContainer ? selectedContainer.name : pod.getName();
|
||||
const logsToDownload = showTimestamps ? logs : podLogsStore.logsWithoutTimestamps;
|
||||
|
||||
saveFileDialog(`${fileName}.log`, logsToDownload.join("\n"), "text/plain");
|
||||
};
|
||||
|
||||
const onContainerChange = (option: SelectOption) => {
|
||||
const { containers, initContainers } = tabData;
|
||||
|
||||
save({
|
||||
selectedContainer: containers
|
||||
.concat(initContainers)
|
||||
.find(container => container.name === option.value)
|
||||
});
|
||||
reload();
|
||||
};
|
||||
|
||||
const containerSelectOptions = () => {
|
||||
const { containers, initContainers } = tabData;
|
||||
|
||||
return [
|
||||
{
|
||||
label: `Containers`,
|
||||
options: containers.map(container => {
|
||||
return { value: container.name };
|
||||
}),
|
||||
},
|
||||
{
|
||||
label: `Init Containers`,
|
||||
options: initContainers.map(container => {
|
||||
return { value: container.name };
|
||||
}),
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
const formatOptionLabel = (option: SelectOption) => {
|
||||
const { value, label } = option;
|
||||
|
||||
return label || <><Icon small material="view_carousel"/> {value}</>;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="PodLogControls flex gaps align-center">
|
||||
<span>Pod:</span> <Badge label={pod.getName()}/>
|
||||
<span>Namespace:</span> <Badge label={pod.getNs()}/>
|
||||
<span>Container</span>
|
||||
<Select
|
||||
options={containerSelectOptions()}
|
||||
value={{ value: selectedContainer.name }}
|
||||
formatOptionLabel={formatOptionLabel}
|
||||
onChange={onContainerChange}
|
||||
autoConvertOptions={false}
|
||||
/>
|
||||
<div className="time-range">
|
||||
{since && (
|
||||
<>
|
||||
Since{" "}
|
||||
<b>{new Date(since[0]).toLocaleString()}</b>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex box grow gaps align-center">
|
||||
<Icon
|
||||
material="av_timer"
|
||||
onClick={toggleTimestamps}
|
||||
className={cssNames("timestamps-icon", { active: showTimestamps })}
|
||||
tooltip={`${showTimestamps ? `Hide` : `Show`} timestamps`}
|
||||
/>
|
||||
<Icon
|
||||
material="history"
|
||||
onClick={togglePrevious}
|
||||
className={cssNames("undo-icon", { active: previous })}
|
||||
tooltip={(previous ? `Show current logs` : `Show previous terminated container logs`)}
|
||||
/>
|
||||
<Icon
|
||||
material="get_app"
|
||||
onClick={downloadLogs}
|
||||
tooltip={`Save`}
|
||||
className="download-icon"
|
||||
/>
|
||||
<PodLogSearch
|
||||
{...props}
|
||||
logs={showTimestamps ? logs : podLogsStore.logsWithoutTimestamps}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import "./item-list-layout.scss";
|
||||
import "./table-menu.scss";
|
||||
import groupBy from "lodash/groupBy";
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
@@ -18,6 +19,11 @@ import { PageFiltersList } from "./page-filters-list";
|
||||
import { PageFiltersSelect } from "./page-filters-select";
|
||||
import { NamespaceSelectFilter } from "../+namespaces/namespace-select";
|
||||
import { themeStore } from "../../theme.store";
|
||||
import { MenuActions} from "../menu/menu-actions";
|
||||
import { MenuItem } from "../menu";
|
||||
import { Checkbox } from "../checkbox";
|
||||
import { userStore } from "../../../common/user-store";
|
||||
import logger from "../../../main/logger";
|
||||
|
||||
// todo: refactor, split to small re-usable components
|
||||
|
||||
@@ -32,6 +38,7 @@ interface IHeaderPlaceholders {
|
||||
}
|
||||
|
||||
export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
|
||||
tableId?: string;
|
||||
className: IClassName;
|
||||
store: ItemStore<T>;
|
||||
dependentStores?: ItemStore[];
|
||||
@@ -50,6 +57,7 @@ export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
|
||||
isReady?: boolean; // show loading indicator while not ready
|
||||
isSelectable?: boolean; // show checkbox in rows for selecting items
|
||||
isSearchable?: boolean; // apply search-filter & add search-input
|
||||
isConfigurable?: boolean;
|
||||
copyClassNameFromHeadCells?: boolean;
|
||||
sortingCallbacks?: { [sortBy: string]: TableSortCallback };
|
||||
tableProps?: Partial<TableProps>; // low-level table configuration
|
||||
@@ -74,6 +82,7 @@ const defaultProps: Partial<ItemListLayoutProps> = {
|
||||
showHeader: true,
|
||||
isSearchable: true,
|
||||
isSelectable: true,
|
||||
isConfigurable: false,
|
||||
copyClassNameFromHeadCells: true,
|
||||
dependentStores: [],
|
||||
filterItems: [],
|
||||
@@ -89,7 +98,7 @@ interface ItemListLayoutUserSettings {
|
||||
@observer
|
||||
export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
static defaultProps = defaultProps as object;
|
||||
|
||||
@observable hiddenColumnNames = new Set<string>();
|
||||
@observable isUnmounting = false;
|
||||
|
||||
// default user settings (ui show-hide tweaks mostly)
|
||||
@@ -111,7 +120,10 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
const { store, dependentStores, isClusterScoped } = this.props;
|
||||
const { store, dependentStores, isClusterScoped, tableId } = this.props;
|
||||
|
||||
if (this.canBeConfigured) this.hiddenColumnNames = new Set(userStore.preferences?.hiddenTableColumns?.[tableId]);
|
||||
|
||||
const stores = [store, ...dependentStores];
|
||||
|
||||
if (!isClusterScoped) stores.push(namespaceStore);
|
||||
@@ -216,6 +228,42 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
return this.applyFilters(filterItems, allItems);
|
||||
}
|
||||
|
||||
updateColumnFilter(checkboxValue: boolean, columnName: string) {
|
||||
if (checkboxValue){
|
||||
this.hiddenColumnNames.delete(columnName);
|
||||
} else {
|
||||
this.hiddenColumnNames.add(columnName);
|
||||
}
|
||||
|
||||
if (this.canBeConfigured) {
|
||||
userStore.preferences.hiddenTableColumns[this.props.tableId] = Array.from(this.hiddenColumnNames);
|
||||
}
|
||||
}
|
||||
|
||||
columnIsVisible(index: number): boolean {
|
||||
const {renderTableHeader} = this.props;
|
||||
|
||||
if (!this.canBeConfigured) return true;
|
||||
|
||||
return !this.hiddenColumnNames.has(renderTableHeader[index].showWithColumn ?? renderTableHeader[index].className);
|
||||
}
|
||||
|
||||
get canBeConfigured(): boolean {
|
||||
const { isConfigurable, tableId, renderTableHeader } = this.props;
|
||||
|
||||
if (!isConfigurable || !tableId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!renderTableHeader?.every(({ className }) => className)) {
|
||||
logger.warning("[ItemObjectList]: cannot configure an object list without all headers being identifiable");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@autobind()
|
||||
getRow(uid: string) {
|
||||
const {
|
||||
@@ -259,7 +307,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
}
|
||||
}
|
||||
|
||||
return <TableCell key={index} {...cellProps} />;
|
||||
return this.columnIsVisible(index) ? <TableCell key={index} {...cellProps} /> : null;
|
||||
})
|
||||
}
|
||||
{renderItemMenu && (
|
||||
@@ -431,14 +479,19 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
onClick={prevDefault(() => store.toggleSelectionAll(items))}
|
||||
/>
|
||||
)}
|
||||
{renderTableHeader.map((cellProps, index) => <TableCell key={index} {...cellProps} />)}
|
||||
{renderItemMenu && <TableCell className="menu" />}
|
||||
{renderTableHeader.map((cellProps, index) => this.columnIsVisible(index) ? <TableCell key={index} {...cellProps} /> : null)}
|
||||
{ renderItemMenu &&
|
||||
<TableCell className="menu" >
|
||||
{this.canBeConfigured && this.renderColumnMenu()}
|
||||
</TableCell>
|
||||
}
|
||||
</TableHead>
|
||||
)}
|
||||
{
|
||||
!virtual && items.map(item => this.getRow(item.getId()))
|
||||
}
|
||||
</Table>
|
||||
|
||||
)}
|
||||
<AddRemoveButtons
|
||||
onRemove={selectedItems.length ? removeItemsDialog : null}
|
||||
@@ -449,6 +502,29 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
);
|
||||
}
|
||||
|
||||
renderColumnMenu() {
|
||||
const { renderTableHeader} = this.props;
|
||||
|
||||
return (
|
||||
<MenuActions
|
||||
toolbar = {false}
|
||||
autoCloseOnSelect = {false}
|
||||
className={cssNames("KubeObjectMenu")}
|
||||
>
|
||||
{renderTableHeader.map((cellProps, index) => (
|
||||
!cellProps.showWithColumn &&
|
||||
<MenuItem key={index} className="input">
|
||||
<Checkbox label = {cellProps.title ?? `<${cellProps.className}>`}
|
||||
className = "MenuCheckbox"
|
||||
value ={!this.hiddenColumnNames.has(cellProps.className)}
|
||||
onChange = {(v) => this.updateColumnFilter(v, cellProps.className)}
|
||||
/>
|
||||
</MenuItem>
|
||||
))}
|
||||
</MenuActions>
|
||||
);
|
||||
}
|
||||
|
||||
renderFooter() {
|
||||
if (this.props.renderFooter) {
|
||||
return this.props.renderFooter(this);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.MenuCheckbox {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import isString from "lodash/isString";
|
||||
export interface MenuActionsProps extends Partial<MenuProps> {
|
||||
className?: string;
|
||||
toolbar?: boolean; // display menu as toolbar with icons
|
||||
autoCloseOnSelect?: boolean;
|
||||
triggerIcon?: string | IconProps | React.ReactNode;
|
||||
removeConfirmationMessage?: React.ReactNode | (() => React.ReactNode);
|
||||
updateAction?(): void;
|
||||
@@ -80,7 +81,7 @@ export class MenuActions extends React.Component<MenuActionsProps> {
|
||||
|
||||
render() {
|
||||
const {
|
||||
className, toolbar, children, updateAction, removeAction, triggerIcon, removeConfirmationMessage,
|
||||
className, toolbar, autoCloseOnSelect, children, updateAction, removeAction, triggerIcon, removeConfirmationMessage,
|
||||
...menuProps
|
||||
} = this.props;
|
||||
const menuClassName = cssNames("MenuActions flex", className, {
|
||||
@@ -98,7 +99,7 @@ export class MenuActions extends React.Component<MenuActionsProps> {
|
||||
className={menuClassName}
|
||||
usePortal={autoClose}
|
||||
closeOnScroll={autoClose}
|
||||
closeOnClickItem={autoClose}
|
||||
closeOnClickItem={autoCloseOnSelect ?? autoClose }
|
||||
closeOnClickOutside={autoClose}
|
||||
{...menuProps}
|
||||
>
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
|
||||
isChecked?: boolean; // mark checkbox as checked or not
|
||||
renderBoolean?: boolean; // show "true" or "false" for all of the children elements are "typeof boolean"
|
||||
sortBy?: TableSortBy; // column name, must be same as key in sortable object <Table sortable={}/>
|
||||
showWithColumn?: string // className of another column, if it is not empty the current column is not shown in the filter menu, visibility of this one is the same as a specified column, applicable to headers only
|
||||
_sorting?: Partial<TableSortParams>; // <Table> sorting state, don't use this prop outside (!)
|
||||
_sort?(sortBy: TableSortBy): void; // <Table> sort function, don't use this prop outside (!)
|
||||
_nowrap?: boolean; // indicator, might come from parent <TableHead>, don't use this prop outside (!)
|
||||
@@ -63,7 +64,7 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { className, checkbox, isChecked, sortBy, _sort, _sorting, _nowrap, children, title, renderBoolean: displayBoolean, ...cellProps } = this.props;
|
||||
const { className, checkbox, isChecked, sortBy, _sort, _sorting, _nowrap, children, title, renderBoolean: displayBoolean, showWithColumn, ...cellProps } = this.props;
|
||||
const classNames = cssNames("TableCell", className, {
|
||||
checkbox,
|
||||
nowrap: _nowrap,
|
||||
|
||||
@@ -25,4 +25,5 @@ export const ResourceNames: Record<KubeResource, string> = {
|
||||
"horizontalpodautoscalers": "Horizontal Pod Autoscalers",
|
||||
"podsecuritypolicies": "Pod Security Policies",
|
||||
"poddisruptionbudgets": "Pod Disruption Budgets",
|
||||
"limitranges": "Limit Ranges",
|
||||
};
|
||||
Reference in new issue
Block a user