mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add eslint rule padding-line-between-statements (#1593)
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
7b77f18376
commit
dcf253e7d5
401 files changed
+2018
-40
No files matched your search
@@ -25,12 +25,14 @@ export const ContainerEnvironment = observer((props: Props) => {
|
||||
autorun(() => {
|
||||
env && env.forEach(variable => {
|
||||
const { valueFrom } = variable;
|
||||
|
||||
if (valueFrom && valueFrom.configMapKeyRef) {
|
||||
configMapsStore.load({ name: valueFrom.configMapKeyRef.name, namespace });
|
||||
}
|
||||
});
|
||||
envFrom && envFrom.forEach(item => {
|
||||
const { configMapRef } = item;
|
||||
|
||||
if (configMapRef && configMapRef.name) {
|
||||
configMapsStore.load({ name: configMapRef.name, namespace });
|
||||
}
|
||||
@@ -49,12 +51,16 @@ export const ContainerEnvironment = observer((props: Props) => {
|
||||
if (value) {
|
||||
secretValue = value;
|
||||
}
|
||||
|
||||
if (valueFrom) {
|
||||
const { fieldRef, secretKeyRef, configMapKeyRef } = valueFrom;
|
||||
|
||||
if (fieldRef) {
|
||||
const { apiVersion, fieldPath } = fieldRef;
|
||||
|
||||
secretValue = `fieldRef(${apiVersion}:${fieldPath})`;
|
||||
}
|
||||
|
||||
if (secretKeyRef) {
|
||||
secretValue = (
|
||||
<SecretKey
|
||||
@@ -63,9 +69,11 @@ export const ContainerEnvironment = observer((props: Props) => {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (configMapKeyRef) {
|
||||
const { name, key } = configMapKeyRef;
|
||||
const configMap = configMapsStore.getByName(name, namespace);
|
||||
|
||||
secretValue = configMap ?
|
||||
configMap.data[key] :
|
||||
`configMapKeyRef(${name}${key})`;
|
||||
@@ -84,13 +92,16 @@ export const ContainerEnvironment = observer((props: Props) => {
|
||||
const envVars = envFrom.map(vars => {
|
||||
if (!vars.configMapRef || !vars.configMapRef.name) return;
|
||||
const configMap = configMapsStore.getByName(vars.configMapRef.name, namespace);
|
||||
|
||||
if (!configMap) return;
|
||||
|
||||
return Object.entries(configMap.data).map(([name, value]) => (
|
||||
<div className="variable" key={name}>
|
||||
<span className="var-name">{name}</span>: {value}
|
||||
</div>
|
||||
));
|
||||
});
|
||||
|
||||
return _.flatten(envVars);
|
||||
};
|
||||
|
||||
@@ -119,6 +130,7 @@ const SecretKey = (props: SecretKeyProps) => {
|
||||
evt.preventDefault();
|
||||
setLoading(true);
|
||||
const secret = await secretsStore.load({ name, namespace });
|
||||
|
||||
setLoading(false);
|
||||
setSecret(secret);
|
||||
};
|
||||
|
||||
@@ -26,7 +26,9 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
|
||||
async portForward() {
|
||||
const { pod, port } = this.props;
|
||||
|
||||
this.waiting = true;
|
||||
|
||||
try {
|
||||
await apiBase.post(`/pods/${pod.getNs()}/pod/${pod.getName()}/port-forward/${port.containerPort}`, {});
|
||||
} catch(error) {
|
||||
@@ -40,6 +42,7 @@ export class PodContainerPort extends React.Component<Props> {
|
||||
const { port } = this.props;
|
||||
const { name, containerPort, protocol } = port;
|
||||
const text = `${name ? `${name}: ` : ""}${containerPort}/${protocol}`;
|
||||
|
||||
return (
|
||||
<div className={cssNames("PodContainerPort", { waiting: this.waiting })}>
|
||||
<span title={_i18n._(t`Open in a browser`)} onClick={() => this.portForward() }>
|
||||
|
||||
@@ -15,7 +15,9 @@ export class PodDetailsAffinities extends React.Component<Props> {
|
||||
const { workload } = this.props;
|
||||
const affinitiesNum = workload.getAffinityNumber();
|
||||
const affinities = workload.getAffinity();
|
||||
|
||||
if (!affinitiesNum) return null;
|
||||
|
||||
return (
|
||||
<DrawerItem name={<Trans>Affinities</Trans>} className="PodDetailsAffinities">
|
||||
<DrawerParamToggler label={affinitiesNum}>
|
||||
|
||||
@@ -24,6 +24,7 @@ export class PodDetailsContainer extends React.Component<Props> {
|
||||
|
||||
renderStatus(state: string, status: IPodContainerStatus) {
|
||||
const ready = status ? status.ready : "";
|
||||
|
||||
return (
|
||||
<span className={cssNames("status", state)}>
|
||||
{state}{ready ? `, ${_i18n._(t`ready`)}` : ""}
|
||||
@@ -47,6 +48,7 @@ export class PodDetailsContainer extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const { pod, container, metrics } = this.props;
|
||||
|
||||
if (!pod || !container) return null;
|
||||
const { name, image, imagePullPolicy, ports, volumeMounts, command, args } = container;
|
||||
const status = pod.getContainerStatuses().find(status => status.name === container.name);
|
||||
@@ -61,6 +63,7 @@ export class PodDetailsContainer extends React.Component<Props> {
|
||||
<Trans key="memory">Memory</Trans>,
|
||||
<Trans key="filesystem">Filesystem</Trans>,
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="PodDetailsContainer">
|
||||
<div className="pod-container-title">
|
||||
@@ -94,6 +97,7 @@ export class PodDetailsContainer extends React.Component<Props> {
|
||||
{
|
||||
ports.map((port) => {
|
||||
const key = `${container.name}-port-${port.containerPort}-${port.protocol}`;
|
||||
|
||||
return(
|
||||
<PodContainerPort pod={pod} port={port} key={key}/>
|
||||
);
|
||||
@@ -107,6 +111,7 @@ export class PodDetailsContainer extends React.Component<Props> {
|
||||
{
|
||||
volumeMounts.map(mount => {
|
||||
const { name, mountPath, readOnly } = mount;
|
||||
|
||||
return (
|
||||
<React.Fragment key={name + mountPath}>
|
||||
<span className="mount-path">{mountPath}</span>
|
||||
|
||||
@@ -68,10 +68,13 @@ export class PodDetailsList extends React.Component<Props> {
|
||||
const tooltip = (
|
||||
<p><Trans>CPU</Trans>: {Math.ceil(usage * 100) / maxCpu}%<br/>{usage.toFixed(3)}</p>
|
||||
);
|
||||
|
||||
if (!maxCpu) {
|
||||
if (parseFloat(value) === 0) return 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
return (
|
||||
<LineProgress
|
||||
max={maxCpu} value={usage}
|
||||
@@ -85,7 +88,9 @@ export class PodDetailsList extends React.Component<Props> {
|
||||
const tooltip = (
|
||||
<p><Trans>Memory</Trans>: {Math.ceil(usage * 100 / maxMemory)}%<br/>{bytesToUnits(usage, 3)}</p>
|
||||
);
|
||||
|
||||
if (!maxMemory) return usage ? bytesToUnits(usage) : 0;
|
||||
|
||||
return (
|
||||
<LineProgress
|
||||
max={maxMemory} value={usage}
|
||||
@@ -99,6 +104,7 @@ export class PodDetailsList extends React.Component<Props> {
|
||||
const { pods } = this.props;
|
||||
const pod = pods.find(pod => pod.getId() == uid);
|
||||
const metrics = podsStore.getPodKubeMetrics(pod);
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
key={pod.getId()}
|
||||
@@ -119,10 +125,12 @@ export class PodDetailsList extends React.Component<Props> {
|
||||
render() {
|
||||
const { pods, showTitle } = this.props;
|
||||
const virtual = pods.length > 100;
|
||||
|
||||
if (!pods.length && !podsStore.isLoaded) return (
|
||||
<div className="PodDetailsList flex justify-center"><Spinner/></div>
|
||||
);
|
||||
if (!pods.length) return null;
|
||||
|
||||
return (
|
||||
<div className="PodDetailsList flex column">
|
||||
{showTitle && <DrawerTitle title={<Trans>Pods</Trans>}/>}
|
||||
|
||||
@@ -18,6 +18,7 @@ export class PodDetailsSecrets extends Component<Props> {
|
||||
@disposeOnUnmount
|
||||
secretsLoader = autorun(async () => {
|
||||
const { pod } = this.props;
|
||||
|
||||
this.secrets = await Promise.all(
|
||||
pod.getSecrets().map(secretName => secretsApi.get({
|
||||
name: secretName,
|
||||
|
||||
@@ -11,8 +11,10 @@ interface Props {
|
||||
export class PodDetailsStatuses extends React.Component<Props> {
|
||||
render() {
|
||||
const { pods } = this.props;
|
||||
|
||||
if (!pods.length) return null;
|
||||
const statuses = countBy(pods.map(pod => pod.getStatus()));
|
||||
|
||||
return (
|
||||
<div className="PodDetailsStatuses">
|
||||
{
|
||||
|
||||
@@ -12,13 +12,16 @@ export class PodDetailsTolerations extends React.Component<Props> {
|
||||
render() {
|
||||
const { workload } = this.props;
|
||||
const tolerations = workload.getTolerations();
|
||||
|
||||
if (!tolerations.length) return null;
|
||||
|
||||
return (
|
||||
<DrawerItem name={<Trans>Tolerations</Trans>} className="PodDetailsTolerations">
|
||||
<DrawerParamToggler label={tolerations.length}>
|
||||
{
|
||||
tolerations.map((toleration, index) => {
|
||||
const { key, operator, effect, tolerationSeconds } = toleration;
|
||||
|
||||
return (
|
||||
<div className="toleration" key={index}>
|
||||
<DrawerItem name={<Trans>Key</Trans>}>{key}</DrawerItem>
|
||||
|
||||
@@ -54,11 +54,13 @@ export class PodDetails extends React.Component<Props> {
|
||||
@autobind()
|
||||
async loadMetrics() {
|
||||
const { object: pod } = this.props;
|
||||
|
||||
this.containerMetrics = await podsStore.loadContainerMetrics(pod);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { object: pod } = this.props;
|
||||
|
||||
if (!pod) return null;
|
||||
const { status, spec } = pod;
|
||||
const { conditions, podIP } = status;
|
||||
@@ -66,6 +68,7 @@ export class PodDetails extends React.Component<Props> {
|
||||
const nodeSelector = pod.getNodeSelectors();
|
||||
const volumes = pod.getVolumes();
|
||||
const metrics = podsStore.metrics;
|
||||
|
||||
return (
|
||||
<div className="PodDetails">
|
||||
<ResourceMetrics
|
||||
@@ -99,6 +102,7 @@ export class PodDetails extends React.Component<Props> {
|
||||
{
|
||||
conditions.map(condition => {
|
||||
const { type, status, lastTransitionTime } = condition;
|
||||
|
||||
return (
|
||||
<Badge
|
||||
key={type}
|
||||
@@ -142,6 +146,7 @@ export class PodDetails extends React.Component<Props> {
|
||||
pod.getContainers().map(container => {
|
||||
const { name } = container;
|
||||
const metrics = getItemMetrics(toJS(this.containerMetrics), name);
|
||||
|
||||
return (
|
||||
<PodDetailsContainer
|
||||
key={name}
|
||||
|
||||
@@ -24,20 +24,25 @@ export class PodsStore extends KubeObjectStore<Pod> {
|
||||
|
||||
async loadKubeMetrics(namespace?: string) {
|
||||
const metrics = await podMetricsApi.list({ namespace });
|
||||
|
||||
this.kubeMetrics.replace(metrics);
|
||||
}
|
||||
|
||||
getPodsByOwner(workload: WorkloadKubeObject): Pod[] {
|
||||
if (!workload) return [];
|
||||
|
||||
return this.items.filter(pod => {
|
||||
const owners = pod.getOwnerRefs();
|
||||
|
||||
if (!owners.length) return;
|
||||
|
||||
return owners.find(owner => owner.uid === workload.getId());
|
||||
});
|
||||
}
|
||||
|
||||
getPodsByNode(node: string) {
|
||||
if (!this.isLoaded) return [];
|
||||
|
||||
return this.items.filter(pod => pod.spec.nodeName === node);
|
||||
}
|
||||
|
||||
@@ -54,15 +59,19 @@ export class PodsStore extends KubeObjectStore<Pod> {
|
||||
metric.getNs() === pod.getNs()
|
||||
].every(v => v);
|
||||
});
|
||||
|
||||
if (!metrics) return empty;
|
||||
|
||||
return containers.reduce((total, container) => {
|
||||
const metric = metrics.containers.find(item => item.name == container.name);
|
||||
let cpu = "0";
|
||||
let memory = "0";
|
||||
|
||||
if (metric && metric.usage) {
|
||||
cpu = metric.usage.cpu || "0";
|
||||
memory = metric.usage.memory || "0";
|
||||
}
|
||||
|
||||
return {
|
||||
cpu: total.cpu + cpuUnitsToNumber(cpu),
|
||||
memory: total.memory + unitsToBytes(memory)
|
||||
|
||||
@@ -40,6 +40,7 @@ export class Pods extends React.Component<Props> {
|
||||
renderContainersStatus(pod: Pod) {
|
||||
return pod.getContainerStatuses().map(containerStatus => {
|
||||
const { name, state, ready } = containerStatus;
|
||||
|
||||
return (
|
||||
<Fragment key={name}>
|
||||
<StatusBrick
|
||||
@@ -109,6 +110,7 @@ export class Pods extends React.Component<Props> {
|
||||
pod.getOwnerRefs().map(ref => {
|
||||
const { kind, name } = ref;
|
||||
const detailsLink = getDetailsUrl(lookupApiLink(ref, pod));
|
||||
|
||||
return (
|
||||
<Link key={name} to={detailsLink} className="owner" onClick={stopPropagation}>
|
||||
{kind}
|
||||
|
||||
Reference in new issue
Block a user