diff --git a/dashboard/client/api/kube-object.ts b/dashboard/client/api/kube-object.ts index 2d7a7bf72a..52c037785d 100644 --- a/dashboard/client/api/kube-object.ts +++ b/dashboard/client/api/kube-object.ts @@ -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 [ diff --git a/dashboard/client/api/workload-kube-object.ts b/dashboard/client/api/workload-kube-object.ts index 087a5b2f7a..a32ccd99e9 100644 --- a/dashboard/client/api/workload-kube-object.ts +++ b/dashboard/client/api/workload-kube-object.ts @@ -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); diff --git a/dashboard/client/components/+workloads-pods/pod-details.tsx b/dashboard/client/components/+workloads-pods/pod-details.tsx index 073b890efe..549d5232f6 100644 --- a/dashboard/client/components/+workloads-pods/pod-details.tsx +++ b/dashboard/client/components/+workloads-pods/pod-details.tsx @@ -64,7 +64,6 @@ export class PodDetails extends React.Component { 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 { } } - {ownerRefs.length > 0 && - Controlled By}> - { - ownerRefs.map(ref => { - const { name, kind } = ref; - const ownerDetailsUrl = getDetailsUrl(lookupApiLink(ref, pod)); - return ( -

- {kind} {name} -

- ); - }) - } -
- } diff --git a/dashboard/client/components/kube-object/kube-object-meta.tsx b/dashboard/client/components/kube-object/kube-object-meta.tsx index 383fc9a842..d8a399a866 100644 --- a/dashboard/client/components/kube-object/kube-object-meta.tsx +++ b/dashboard/client/components/kube-object/kube-object-meta.tsx @@ -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 { } 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 ( <> Created} hidden={this.isHidden("creationTimestamp")}> @@ -59,6 +66,21 @@ export class KubeObjectMeta extends React.Component { labels={getFinalizers()} hidden={this.isHidden("finalizers")} /> + {ownerRefs && ownerRefs.length > 0 && + Controlled By} hidden={this.isHidden("ownerReferences")}> + { + ownerRefs.map(ref => { + const { name, kind } = ref; + const ownerDetailsUrl = getDetailsUrl(lookupApiLink(ref, object)); + return ( +

+ {kind} {name} +

+ ); + }) + } +
+ } ) }