Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFBUGS-330: Disables deletion for local client #1681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions packages/odf/components/storage-consumers/client-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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) => {
Expand All @@ -347,7 +361,7 @@ const StorageClientRow: React.FC<
break;
case 'clusterName':
data = `${obj?.status?.client?.clusterName || '-'} (${
obj?.status?.client?.clusterId || '-'
clientClusterId || '-'
})`;
break;
case 'storageQuota':
Expand Down Expand Up @@ -437,6 +451,13 @@ export const ClientListPage: React.FC<ClientListPageProps> = () => {
isList: true,
});

const [cv, cvLoaded, cvLoadError] = useK8sGet<ClusterVersionKind>(
ClusterVersionModel,
'version'
);

const localClusterId = cv?.spec?.clusterID;

const { odfNamespace, isNsSafe } = useODFNamespaceSelector();

const [csv, csvLoaded, csvLoadError] = useFetchCsv({
Expand Down Expand Up @@ -489,7 +510,7 @@ export const ClientListPage: React.FC<ClientListPageProps> = () => {
<ListPageBody>
<ListPageFilter
data={data}
loaded={loaded && csvLoaded}
loaded={loaded && csvLoaded && cvLoaded}
onFilterChange={onFilterChange}
hideColumnManagement={true}
rowFilters={rowFilters}
Expand All @@ -498,8 +519,8 @@ export const ClientListPage: React.FC<ClientListPageProps> = () => {
data={filteredData}
unfilteredData={storageClients}
loaded={loaded && csvLoaded}
loadError={loadError || csvLoadError}
rowData={{ currentVersion: serviceVersion }}
loadError={loadError || csvLoadError || cvLoadError}
rowData={{ currentVersion: serviceVersion, localClusterId }}
/>
</ListPageBody>
</>
Expand Down
15 changes: 15 additions & 0 deletions packages/shared/src/models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
57 changes: 57 additions & 0 deletions packages/shared/src/types/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading