From a160e02c3d7209759b596b5584d1f46566a385f1 Mon Sep 17 00:00:00 2001 From: James Peach Date: Thu, 27 Apr 2023 05:44:15 +1000 Subject: [PATCH] Omit ManagedFields from the Kubernetes resource YAML display. (#17497) * Omit ManagedFields from the Kubernetes resource YAML display. The default for the Kubernetes CLI tooling is to omit the managed fields by default, since these are only present for internal machinery. For the Kubernetes resource YAML display, the managed fields take up a ton of space, but are never useful to operators who are interested in the details of their Kubernetes resources. This fixes #14177. Signed-off-by: James Peach * Add a control to toggle whether the managed fields display. So that managed fields can be used for debugging purposes, add a switch to toggle allow managed fields to display. This is off by default. Signed-off-by: James Peach --------- Signed-off-by: James Peach --- .changeset/fifty-laws-count.md | 5 ++ .../KubernetesDrawer/KubernetesDrawer.tsx | 60 +++++++++++++++---- 2 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 .changeset/fifty-laws-count.md diff --git a/.changeset/fifty-laws-count.md b/.changeset/fifty-laws-count.md new file mode 100644 index 0000000000..f20e41fc20 --- /dev/null +++ b/.changeset/fifty-laws-count.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes': patch +--- + +Omit managed fields in the Kubernetes resource YAML display. diff --git a/plugins/kubernetes/src/components/KubernetesDrawer/KubernetesDrawer.tsx b/plugins/kubernetes/src/components/KubernetesDrawer/KubernetesDrawer.tsx index 7e194c3ec2..9be30debf3 100644 --- a/plugins/kubernetes/src/components/KubernetesDrawer/KubernetesDrawer.tsx +++ b/plugins/kubernetes/src/components/KubernetesDrawer/KubernetesDrawer.tsx @@ -25,6 +25,7 @@ import { Drawer, Switch, FormControlLabel, + FormGroup, Grid, } from '@material-ui/core'; import Close from '@material-ui/icons/Close'; @@ -150,6 +151,11 @@ const KubernetesDrawerContent = ({ }: KubernetesDrawerContentProps) => { const [isYaml, setIsYaml] = useState(false); + // Toggle whether the Kubernetes resource managed fields should be shown in + // the YAML display. This toggle is only available when the YAML is being + // shown because managed fields are never visible in the structured display. + const [managedFields, setManagedFields] = useState(false); + const classes = useDrawerContentStyles(); const cluster = useContext(ClusterContext); const { clusterLink, errorMessage } = tryFormatClusterLink({ @@ -208,21 +214,49 @@ const KubernetesDrawerContent = ({ )} - { - setIsYaml(event.target.checked); - }} - name="YAML" - /> - } - label="YAML" - /> + + { + setIsYaml(event.target.checked); + }} + name="YAML" + /> + } + label="YAML" + /> + { + if (isYaml) { + setManagedFields(event.target.checked); + } + }} + name="Managed Fields" + /> + } + label="Managed Fields" + /> +
- {isYaml && } + {isYaml && ( + { + if (!managedFields) { + return key === 'managedFields' ? undefined : value; + } + return value; + }, + })} + /> + )} {!isYaml && (