Skip to content

Commit

Permalink
Add support for pre-provisioned snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Sep 18, 2020
1 parent b6ffd5a commit 288c8d2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ const menuActions = [RestorePVC, ...common];

const Details: React.FC<DetailsProps> = ({ obj }) => {
const { namespace } = obj.metadata || {};
const { persistentVolumeClaimName: pvcName } = obj.spec?.source || {};
const sourceKind = obj?.spec?.source?.persistentVolumeClaimName
? PersistentVolumeClaimModel.kind
: referenceForModel(VolumeSnapshotContentModel);
const sourceName =
obj?.spec?.source?.persistentVolumeClaimName ?? obj?.spec?.source?.volumeSnapshotContentName;
const size = obj.status?.restoreSize;
const sizeBase = convertToBaseValue(size);
const sizeMetrics = size ? humanizeBinaryBytes(sizeBase).string : '-';
const snapshotContent = obj?.status?.boundVolumeSnapshotContentName;
const snapshotClass = obj?.spec?.volumeSnapshotClassName;
return (
<div className="co-m-pane__body">
<SectionHeading text="Volume Snapshot Details" />
Expand All @@ -50,13 +55,13 @@ const Details: React.FC<DetailsProps> = ({ obj }) => {
<dd>{sizeMetrics}</dd>
</>
)}
<dt>Persistent Volume Claim</dt>
<dd data-test="details-item-value__PVC">
<ResourceLink
kind={PersistentVolumeClaimModel.kind}
name={pvcName}
namespace={namespace}
/>
<dt>
{sourceKind === PersistentVolumeClaimModel.kind
? 'Persistent Volume Claim'
: 'Volume Snapshot Content'}
</dt>
<dd>
<ResourceLink kind={sourceKind} name={sourceName} namespace={namespace} />
</dd>
{snapshotContent && (
<>
Expand All @@ -69,13 +74,17 @@ const Details: React.FC<DetailsProps> = ({ obj }) => {
</dd>
</>
)}
<dt>Volume Snapshot Class</dt>
<dd data-test="details-item-value__SC">
<ResourceLink
kind={referenceForModel(VolumeSnapshotClassModel)}
name={obj?.spec?.volumeSnapshotClassName}
/>
</dd>
{snapshotClass && (
<>
<dt>Volume Snapshot Class</dt>
<dd data-test="details-item-value__SC">
<ResourceLink
kind={referenceForModel(VolumeSnapshotClassModel)}
name={snapshotClass}
/>
</dd>
</>
)}
</dl>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const Header = (disableItems = {}) => () =>
props: { className: tableColumnClasses[3] },
},
{
title: 'PVC',
sortField: 'spec.source.persistentVolumeClaimName',
title: 'Source',
sortFunc: 'volumeSnapshotSource',
transforms: [sortable],
props: { className: tableColumnClasses[4] },
},
Expand Down Expand Up @@ -110,8 +110,13 @@ const Row: RowFunction<VolumeSnapshotKind> = ({ key, obj, style, index, customDa
const size = obj?.status?.restoreSize;
const sizeBase = convertToBaseValue(size);
const sizeMetrics = size ? humanizeBinaryBytes(sizeBase).string : '-';
const pvcName = obj?.spec?.source?.persistentVolumeClaimName;
const sourceKind = obj?.spec?.source?.persistentVolumeClaimName
? PersistentVolumeClaimModel.kind
: referenceForModel(VolumeSnapshotContentModel);
const sourceName =
obj?.spec?.source?.persistentVolumeClaimName ?? obj?.spec?.source?.volumeSnapshotContentName;
const snapshotContent = obj?.status?.boundVolumeSnapshotContentName;
const snapshotClass = obj?.spec?.volumeSnapshotClassName;
return (
<TableRow id={obj?.metadata?.uid} index={index} trKey={key} style={style}>
<TableData className={tableColumnClasses[0]}>
Expand All @@ -130,11 +135,7 @@ const Row: RowFunction<VolumeSnapshotKind> = ({ key, obj, style, index, customDa
<TableData className={tableColumnClasses[3]}>{sizeMetrics}</TableData>
{!customData?.disableItems?.PVC && (
<TableData className={tableColumnClasses[4]}>
<ResourceLink
kind={PersistentVolumeClaimModel.kind}
name={pvcName}
namespace={namespace}
/>
<ResourceLink kind={sourceKind} name={sourceName} namespace={namespace} />
</TableData>
)}
<TableData className={tableColumnClasses[5]}>
Expand All @@ -148,10 +149,14 @@ const Row: RowFunction<VolumeSnapshotKind> = ({ key, obj, style, index, customDa
)}
</TableData>
<TableData className={tableColumnClasses[6]}>
<ResourceLink
kind={referenceForModel(VolumeSnapshotClassModel)}
name={obj?.spec?.volumeSnapshotClassName}
/>
{snapshotClass ? (
<ResourceLink
kind={referenceForModel(VolumeSnapshotClassModel)}
name={obj?.spec?.volumeSnapshotClassName}
/>
) : (
'-'
)}
</TableData>
<TableData className={tableColumnClasses[7]}>
<Timestamp timestamp={creationTimestamp} />
Expand Down
4 changes: 4 additions & 0 deletions frontend/packages/console-shared/src/sorts/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export const snapshotSize = (snapshot: VolumeSnapshotKind): number => {
const size = snapshot?.status?.restoreSize;
return size ? convertToBaseValue(size) : 0;
};

export const snapshotSource = (snapshot: VolumeSnapshotKind): string =>
snapshot.spec?.source?.persistentVolumeClaimName ??
snapshot.spec?.source?.volumeSnapshotContentName;
2 changes: 2 additions & 0 deletions frontend/public/components/factory/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
nodeZone,
pvcUsed,
snapshotSize,
snapshotSource,
ALL_NAMESPACES_KEY,
} from '@console/shared';
import * as UIActions from '../../actions/ui';
Expand Down Expand Up @@ -166,6 +167,7 @@ const sorts = {
nodePods: (node: NodeKind): number => nodePods(node),
pvcUsed: (pvc: K8sResourceKind): number => pvcUsed(pvc),
volumeSnapshotSize: (snapshot: VolumeSnapshotKind): number => snapshotSize(snapshot),
volumeSnapshotSource: (snapshot: VolumeSnapshotKind): string => snapshotSource(snapshot),
};

const stateToProps = (
Expand Down

0 comments on commit 288c8d2

Please sign in to comment.