1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Show object reference for all objects (#399)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-06-04 14:46:43 +03:00 committed by GitHub
parent 00defdd631
commit 65900e728d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 35 deletions

View File

@ -27,6 +27,14 @@ export interface IKubeObjectMetadata {
annotations?: {
[annotation: string]: string;
};
ownerReferences?: {
apiVersion: string;
kind: string;
name: string;
uid: string;
controller: boolean;
blockOwnerDeletion: boolean;
}[];
}
export type IKubeMetaField = keyof KubeObject["metadata"];
@ -113,6 +121,14 @@ export class KubeObject implements ItemObject {
})
}
getOwnerRefs() {
const refs = this.metadata.ownerReferences || [];
return refs.map(ownerRef => ({
...ownerRef,
namespace: this.getNs(),
}))
}
getSearchFields() {
const { getName, getId, getNs, getAnnotations, getLabels } = this
return [

View File

@ -47,28 +47,10 @@ export interface IAffinity {
}
export class WorkloadKubeObject extends KubeObject {
metadata: IKubeObjectMetadata & {
ownerReferences?: {
apiVersion: string;
kind: string;
name: string;
uid: string;
controller: boolean;
blockOwnerDeletion: boolean;
}[];
}
// fixme: add type
spec: any;
getOwnerRefs() {
const refs = this.metadata.ownerReferences || [];
return refs.map(ownerRef => ({
...ownerRef,
namespace: this.getNs(),
}))
}
getSelectors(): string[] {
const selector = this.spec.selector;
return KubeObject.stringifyLabels(selector ? selector.matchLabels : null);

View File

@ -64,7 +64,6 @@ export class PodDetails extends React.Component<Props> {
const { status, spec } = pod;
const { conditions, podIP } = status;
const { nodeName } = spec;
const ownerRefs = pod.getOwnerRefs();
const nodeSelector = pod.getNodeSelectors();
const volumes = pod.getVolumes();
const labels = pod.getLabels();
@ -123,21 +122,6 @@ export class PodDetails extends React.Component<Props> {
}
</DrawerItem>
}
{ownerRefs.length > 0 &&
<DrawerItem name={<Trans>Controlled By</Trans>}>
{
ownerRefs.map(ref => {
const { name, kind } = ref;
const ownerDetailsUrl = getDetailsUrl(lookupApiLink(ref, pod));
return (
<p key={name}>
{kind} <Link to={ownerDetailsUrl}>{name}</Link>
</p>
);
})
}
</DrawerItem>
}
<PodDetailsTolerations workload={pod}/>
<PodDetailsAffinities workload={pod}/>

View File

@ -2,6 +2,10 @@ import React from "react";
import { Trans } from "@lingui/macro";
import { IKubeMetaField, KubeObject } from "../../api/kube-object";
import { DrawerItem, DrawerItemLabels } from "../drawer";
import { WorkloadKubeObject } from "../../api/workload-kube-object";
import { getDetailsUrl } from "../../navigation";
import { lookupApiLink } from "../../api/kube-api";
import { Link } from "react-router-dom";
export interface Props {
object: KubeObject;
@ -19,11 +23,14 @@ export class KubeObjectMeta extends React.Component<Props> {
}
render() {
const object = this.props.object
const {
getName, getNs, getLabels, getResourceVersion, selfLink,
getAnnotations, getFinalizers, getId, getAge,
metadata: { creationTimestamp },
} = this.props.object;
} = object;
const ownerRefs = object.getOwnerRefs();
return (
<>
<DrawerItem name={<Trans>Created</Trans>} hidden={this.isHidden("creationTimestamp")}>
@ -59,6 +66,21 @@ export class KubeObjectMeta extends React.Component<Props> {
labels={getFinalizers()}
hidden={this.isHidden("finalizers")}
/>
{ownerRefs && ownerRefs.length > 0 &&
<DrawerItem name={<Trans>Controlled By</Trans>} hidden={this.isHidden("ownerReferences")}>
{
ownerRefs.map(ref => {
const { name, kind } = ref;
const ownerDetailsUrl = getDetailsUrl(lookupApiLink(ref, object));
return (
<p key={name}>
{kind} <Link to={ownerDetailsUrl}>{name}</Link>
</p>
);
})
}
</DrawerItem>
}
</>
)
}