From a341b1b44f3b1be8f717b3f20ba81e54647cf4bf Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 21 Mar 2022 08:30:28 -0400 Subject: [PATCH] Spread out impl Signed-off-by: Sebastian Malton --- .../details/volumes/variant.tsx | 289 ++++++++++++++++-- .../details/volumes/variants.tsx | 80 ----- 2 files changed, 265 insertions(+), 104 deletions(-) delete mode 100644 src/renderer/components/+workloads-pods/details/volumes/variants.tsx diff --git a/src/renderer/components/+workloads-pods/details/volumes/variant.tsx b/src/renderer/components/+workloads-pods/details/volumes/variant.tsx index ec74068538..290e16ae0b 100644 --- a/src/renderer/components/+workloads-pods/details/volumes/variant.tsx +++ b/src/renderer/components/+workloads-pods/details/volumes/variant.tsx @@ -5,10 +5,38 @@ import React from "react"; import type { Pod, PodVolume, PodVolumeKind } from "../../../../../common/k8s-api/endpoints"; -import { entries } from "../../../../utils"; import { DrawerItem } from "../../../drawer"; import { Icon } from "../../../icon"; -import getVolumeVariantComponent from "./variants"; +import { AwsElasticBlockStore } from "./variants/aws-elastic-block-store"; +import { AzureDisk } from "./variants/azure-disk"; +import { AzureFile } from "./variants/azure-file"; +import { CephFs } from "./variants/ceph-fs"; +import { Cinder } from "./variants/cinder"; +import { ConfigMap } from "./variants/config-map"; +import { ContainerStorageInterface } from "./variants/container-storage-interface"; +import { DownwardApi } from "./variants/downward-api"; +import { EmptyDir } from "./variants/empty-dir"; +import { Ephemeral } from "./variants/ephemeral"; +import { FiberChannel } from "./variants/fiber-channel"; +import { FlexVolume } from "./variants/flex-volume"; +import { Flocker } from "./variants/flocker"; +import { GcePersistentDisk } from "./variants/gce-persistent-disk"; +import { GitRepo } from "./variants/git-repo"; +import { GlusterFs } from "./variants/gluster-fs"; +import { HostPath } from "./variants/host-path"; +import { IScsi } from "./variants/i-scsi"; +import { Local } from "./variants/local"; +import { NetworkFs } from "./variants/network-fs"; +import { PersistentVolumeClaim } from "./variants/persistent-volume-claim"; +import { PhotonPersistentDisk } from "./variants/photon-persistent-disk"; +import { PortworxVolume } from "./variants/portworx-volume"; +import { Projected } from "./variants/projected"; +import { Quobyte } from "./variants/quobyte"; +import { RadosBlockDevice } from "./variants/rados-block-device"; +import { ScaleIo } from "./variants/scale-io"; +import { Secret } from "./variants/secret"; +import { StorageOs } from "./variants/storage-os"; +import { VsphereVolume } from "./variants/vsphere-volume"; const deprecatedVolumeTypes = new Set([ "flocker", @@ -22,29 +50,242 @@ interface VolumeVarientProps { volume: PodVolume; } -export function VolumeVarient({ pod, volume }: VolumeVarientProps) { - for (const [kind, variant] of entries(volume)) { - if (kind === "name") { - continue; // This key is not a kind field - } +interface VolumeVarientRender { + kind: PodVolumeKind; + element: JSX.Element; +} - if (!variant || typeof variant !== "object") { - continue; - } - - const isDeprecated = deprecatedVolumeTypes.has(kind); - const VolumeVariantComponent = getVolumeVariantComponent(kind); - - return ( - <> - - {kind} - {isDeprecated && } - - - - ); +function renderVolumeVarient({ pod, volume }: VolumeVarientProps): VolumeVarientRender | null { + if (volume.awsElasticBlockStore) { + return { + kind: "awsElasticBlockStore", + element: , + }; } - return

Error! Unknown pod volume kind

; + if (volume.azureDisk) { + return { + kind: "azureDisk", + element: , + }; + } + + if (volume.azureFile) { + return { + kind: "azureFile", + element: , + }; + } + + if (volume.cephfs) { + return { + kind: "cephfs", + element: , + }; + } + + if (volume.cinder) { + return { + kind: "cinder", + element: , + }; + } + + if (volume.configMap) { + return { + kind: "configMap", + element: , + }; + } + + if (volume.csi) { + return { + kind: "csi", + element: , + }; + } + + if (volume.downwardAPI) { + return { + kind: "downwardAPI", + element: , + }; + } + + if (volume.emptyDir) { + return { + kind: "emptyDir", + element: , + }; + } + + if (volume.ephemeral) { + return { + kind: "ephemeral", + element: , + }; + } + + if (volume.fc) { + return { + kind: "fc", + element: , + }; + } + + if (volume.flexVolume) { + return { + kind: "flexVolume", + element: , + }; + } + + if (volume.flocker) { + return { + kind: "flocker", + element: , + }; + } + + if (volume.gcePersistentDisk) { + return { + kind: "gcePersistentDisk", + element: , + }; + } + + if (volume.gitRepo) { + return { + kind: "gitRepo", + element: , + }; + } + + if (volume.glusterfs) { + return { + kind: "glusterfs", + element: , + }; + } + + if (volume.hostPath) { + return { + kind: "hostPath", + element: , + }; + } + + if (volume.iscsi) { + return { + kind: "iscsi", + element: , + }; + } + + if (volume.local) { + return { + kind: "local", + element: , + }; + } + + if (volume.nfs) { + return { + kind: "nfs", + element: , + }; + } + + if (volume.persistentVolumeClaim) { + return { + kind: "persistentVolumeClaim", + element: , + }; + } + + if (volume.photonPersistentDisk) { + return { + kind: "photonPersistentDisk", + element: , + }; + } + + if (volume.portworxVolume) { + return { + kind: "portworxVolume", + element: , + }; + } + + if (volume.projected) { + return { + kind: "projected", + element: , + }; + } + + if (volume.quobyte) { + return { + kind: "quobyte", + element: , + }; + } + + if (volume.rbd) { + return { + kind: "rbd", + element: , + }; + } + + if (volume.scaleIO) { + return { + kind: "scaleIO", + element: , + }; + } + + if (volume.secret) { + return { + kind: "secret", + element: , + }; + } + + if (volume.storageos) { + return { + kind: "storageos", + element: , + }; + } + + if (volume.vsphereVolume) { + return { + kind: "vsphereVolume", + element: , + }; + } + + return null; +} + +export function VolumeVarient(props: VolumeVarientProps) { + const result = renderVolumeVarient(props); + + if (!result) { + return

Error! Unknown pod volume kind

; + } + + const { kind, element } = result; + const isDeprecated = deprecatedVolumeTypes.has(kind); + + return ( + <> + + {kind} + {isDeprecated && } + + {element} + + ); } diff --git a/src/renderer/components/+workloads-pods/details/volumes/variants.tsx b/src/renderer/components/+workloads-pods/details/volumes/variants.tsx deleted file mode 100644 index 7ff3f0427a..0000000000 --- a/src/renderer/components/+workloads-pods/details/volumes/variants.tsx +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import React from "react"; -import type { PodVolumeKind, PodVolumeVariants } from "../../../../../common/k8s-api/endpoints"; -import type { VolumeVariantComponent } from "./variant-helpers"; -import { AwsElasticBlockStore } from "./variants/aws-elastic-block-store"; -import { AzureDisk } from "./variants/azure-disk"; -import { AzureFile } from "./variants/azure-file"; -import { CephFs } from "./variants/ceph-fs"; -import { Cinder } from "./variants/cinder"; -import { ConfigMap } from "./variants/config-map"; -import { ContainerStorageInterface } from "./variants/container-storage-interface"; -import { DownwardApi } from "./variants/downward-api"; -import { EmptyDir } from "./variants/empty-dir"; -import { Ephemeral } from "./variants/ephemeral"; -import { FiberChannel } from "./variants/fiber-channel"; -import { FlexVolume } from "./variants/flex-volume"; -import { Flocker } from "./variants/flocker"; -import { GcePersistentDisk } from "./variants/gce-persistent-disk"; -import { GitRepo } from "./variants/git-repo"; -import { GlusterFs } from "./variants/gluster-fs"; -import { HostPath } from "./variants/host-path"; -import { IScsi } from "./variants/i-scsi"; -import { Local } from "./variants/local"; -import { NetworkFs } from "./variants/network-fs"; -import { PersistentVolumeClaim } from "./variants/persistent-volume-claim"; -import { PhotonPersistentDisk } from "./variants/photon-persistent-disk"; -import { PortworxVolume } from "./variants/portworx-volume"; -import { Projected } from "./variants/projected"; -import { Quobyte } from "./variants/quobyte"; -import { RadosBlockDevice } from "./variants/rados-block-device"; -import { ScaleIo } from "./variants/scale-io"; -import { Secret } from "./variants/secret"; -import { StorageOs } from "./variants/storage-os"; -import { VsphereVolume } from "./variants/vsphere-volume"; - -const variantComponents = new Map>([ - ["awsElasticBlockStore", AwsElasticBlockStore], - ["azureDisk", AzureDisk], - ["azureFile", AzureFile], - ["cephfs", CephFs], - ["cinder", Cinder], - ["configMap", ConfigMap], - ["csi", ContainerStorageInterface], - ["downwardAPI", DownwardApi], - ["emptyDir", EmptyDir], - ["ephemeral", Ephemeral], - ["fc", FiberChannel], - ["flexVolume", FlexVolume], - ["flocker", Flocker], - ["gcePersistentDisk", GcePersistentDisk], - ["gitRepo", GitRepo], - ["glusterfs", GlusterFs], - ["hostPath", HostPath], - ["iscsi", IScsi], - ["local", Local], - ["nfs", NetworkFs], - ["persistentVolumeClaim", PersistentVolumeClaim], - ["photonPersistentDisk", PhotonPersistentDisk], - ["portworxVolume", PortworxVolume], - ["projected", Projected], - ["quobyte", Quobyte], - ["rbd", RadosBlockDevice], - ["scaleIO", ScaleIo], - ["secret", Secret], - ["storageos", StorageOs], - ["vsphereVolume", VsphereVolume], -]); - - -export default function getVolumeVariantComponent(kind: PodVolumeKind) { - const NotSupported: VolumeVariantComponent = ( - () =>

Variant {kind} is not yet supported

- ); - - return variantComponents.get(kind) ?? NotSupported; -}