From 17f8f8fa4f9decded9e3529f23c8b7662aa9530e Mon Sep 17 00:00:00 2001 From: Bipul Adhikari Date: Thu, 14 Nov 2024 20:57:52 +0545 Subject: [PATCH] Disables deletion for local client Signed-off-by: Bipul Adhikari --- .../storage-consumers/client-list.tsx | 45 +++++++++++---- packages/shared/src/models/common.ts | 15 +++++ packages/shared/src/types/k8s.ts | 57 +++++++++++++++++++ 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/packages/odf/components/storage-consumers/client-list.tsx b/packages/odf/components/storage-consumers/client-list.tsx index 82027aafe..a1f6d7561 100644 --- a/packages/odf/components/storage-consumers/client-list.tsx +++ b/packages/odf/components/storage-consumers/client-list.tsx @@ -3,10 +3,15 @@ import { DiskSize as QuotaSize, diskSizeUnitOptions as QuotaSizeUnitOptions, } from '@odf/core/constants'; -import { GrayInfoCircleIcon, Kebab } from '@odf/shared'; +import { + ClusterVersionKind, + ClusterVersionModel, + GrayInfoCircleIcon, + Kebab, +} from '@odf/shared'; import { ODF_OPERATOR } from '@odf/shared/constants/common'; import { getTimeDifferenceInSeconds } from '@odf/shared/details-page/datetime'; -import { useFetchCsv } from '@odf/shared/hooks'; +import { useFetchCsv, useK8sGet } from '@odf/shared/hooks'; import { ModalKeys } from '@odf/shared/modals'; import { StorageConsumerKind } from '@odf/shared/types'; import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; @@ -309,9 +314,10 @@ const StorageClientRow: React.FC< StorageConsumerKind, { currentVersion: string; + localClusterId: string; } > -> = ({ obj, activeColumnIDs, rowData: { currentVersion } }) => { +> = ({ obj, activeColumnIDs, rowData: { currentVersion, localClusterId } }) => { const { t } = useCustomTranslation(); const [allowDeletion, setAllowDeletion] = React.useState(false); const DELETE_THRESHOLD = 300; // wait till 5 minutes before activating the delete button @@ -321,7 +327,8 @@ const StorageClientRow: React.FC< QuotaSizeUnitOptions[QuotaSize.Gi] ).string : t('Unlimited'); - + const clientClusterId = obj?.status?.client?.clusterId; + const isLocalClient = clientClusterId === localClusterId; React.useEffect(() => { const setter = () => { const timeDifference = getTimeDifferenceInSeconds( @@ -333,10 +340,17 @@ const StorageClientRow: React.FC< setAllowDeletion(false); } }; - setter(); - const id = setInterval(setter, 10000); - return () => clearInterval(id); - }, [allowDeletion, setAllowDeletion, obj?.status?.lastHeartbeat]); + if (!isLocalClient) { + setter(); + const id = setInterval(setter, 10000); + return () => clearInterval(id); + } + }, [ + allowDeletion, + setAllowDeletion, + obj?.status?.lastHeartbeat, + isLocalClient, + ]); return ( <> {tableColumns.map((tableColumn) => { @@ -347,7 +361,7 @@ const StorageClientRow: React.FC< break; case 'clusterName': data = `${obj?.status?.client?.clusterName || '-'} (${ - obj?.status?.client?.clusterId || '-' + clientClusterId || '-' })`; break; case 'storageQuota': @@ -437,6 +451,13 @@ export const ClientListPage: React.FC = () => { isList: true, }); + const [cv, cvLoaded, cvLoadError] = useK8sGet( + ClusterVersionModel, + 'version' + ); + + const localClusterId = cv?.spec?.clusterID; + const { odfNamespace, isNsSafe } = useODFNamespaceSelector(); const [csv, csvLoaded, csvLoadError] = useFetchCsv({ @@ -489,7 +510,7 @@ export const ClientListPage: React.FC = () => { = () => { data={filteredData} unfilteredData={storageClients} loaded={loaded && csvLoaded} - loadError={loadError || csvLoadError} - rowData={{ currentVersion: serviceVersion }} + loadError={loadError || csvLoadError || cvLoadError} + rowData={{ currentVersion: serviceVersion, localClusterId }} /> diff --git a/packages/shared/src/models/common.ts b/packages/shared/src/models/common.ts index 8462419bc..823140290 100644 --- a/packages/shared/src/models/common.ts +++ b/packages/shared/src/models/common.ts @@ -248,3 +248,18 @@ export const DaemonSetModel: K8sKind = { labelPlural: 'DaemonSets', labelPluralKey: 'DaemonSets', }; + +export const ClusterVersionModel: K8sModel = { + label: 'ClusterVersion', + labelKey: 'ClusterVersion', + labelPlural: 'ClusterVersions', + labelPluralKey: 'ClusterVersions', + apiVersion: 'v1', + apiGroup: 'config.openshift.io', + plural: 'clusterversions', + abbr: 'CV', + namespaced: false, + kind: 'ClusterVersion', + id: 'clusterversion', + crd: true, +}; diff --git a/packages/shared/src/types/k8s.ts b/packages/shared/src/types/k8s.ts index 1deec3e31..58f69da15 100644 --- a/packages/shared/src/types/k8s.ts +++ b/packages/shared/src/types/k8s.ts @@ -387,3 +387,60 @@ export type ApplicationKind = K8sResourceCommon & { phase: string; }; }; + +export type Release = { + version: string; + image: string; + url?: string; + channels?: string[]; +}; + +export type ConditionalUpdate = { + release: Release; + conditions: K8sResourceCondition[]; +}; + +export type UpdateHistory = { + state: 'Completed' | 'Partial'; + startedTime: string; + completionTime: string; + version: string; + image: string; + verified: boolean; +}; + +export enum ClusterVersionConditionType { + Available = 'Available', + Failing = 'Failing', + Progressing = 'Progressing', + RetrievedUpdates = 'RetrievedUpdates', + Invalid = 'Invalid', + Upgradeable = 'Upgradeable', + ReleaseAccepted = 'ReleaseAccepted', +} + +export type ClusterVersionCondition = { + type: keyof typeof ClusterVersionConditionType; +} & K8sResourceCondition; + +type ClusterVersionStatus = { + desired: Release; + history: UpdateHistory[]; + observedGeneration: number; + versionHash: string; + conditions?: ClusterVersionCondition[]; + availableUpdates: Release[]; + conditionalUpdates?: ConditionalUpdate[]; +}; + +type ClusterVersionSpec = { + channel: string; + clusterID: string; + desiredUpdate?: Release; + upstream?: string; +}; + +export type ClusterVersionKind = { + spec: ClusterVersionSpec; + status: ClusterVersionStatus; +} & K8sResourceCommon;