Skip to content

Commit

Permalink
Merge pull request #2142 from pcbailey/feature-generate-meaningful-sn…
Browse files Browse the repository at this point in the history
…apshot-names

CNV-46589: Auto-generate meaningful snapshot names
  • Loading branch information
openshift-merge-bot[bot] authored Aug 21, 2024
2 parents 708fff9 + 9f6f9d7 commit dc7d852
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/utils/components/SnapshotModal/SnapshotModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import {
V1beta1VirtualMachineSnapshot,
V1VirtualMachine,
} from '@kubevirt-ui/kubevirt-api/kubevirt';
import { generateSnapshotName } from '@kubevirt-utils/components/SnapshotModal/utils/utils';
import TabModal from '@kubevirt-utils/components/TabModal/TabModal';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { buildOwnerReference } from '@kubevirt-utils/resources/shared';
import { getVolumeSnapshotStatuses } from '@kubevirt-utils/resources/vm';
import { generatePrettyName } from '@kubevirt-utils/utils/utils';
import { k8sCreate } from '@openshift-console/dynamic-plugin-sdk';
import { Form, FormGroup, TextArea, TextInput } from '@patternfly/react-core';

import { deadlineUnits } from '../../../views/virtualmachines/details/tabs/snapshots/utils/consts';
import { deadlineUnits } from '@virtualmachines/details/tabs/snapshots/utils/consts';
import {
getEmptyVMSnapshotResource,
getVolumeSnapshotStatusesPartition,
} from '../../../views/virtualmachines/details/tabs/snapshots/utils/helpers';
import { printableVMStatus } from '../../../views/virtualmachines/utils';
} from '@virtualmachines/details/tabs/snapshots/utils/helpers';
import { printableVMStatus } from '@virtualmachines/utils';

import SupportedVolumesAlert from './alerts/SupportedVolumesAlert';
import UnsupportedVolumesAlert from './alerts/UnsupportedVolumesAlert';
Expand All @@ -33,7 +32,7 @@ type SnapshotModalProps = {

const SnapshotModal: FC<SnapshotModalProps> = ({ isOpen, onClose, vm }) => {
const { t } = useKubevirtTranslation();
const [snapshotName, setSnapshotName] = useState<string>(generatePrettyName('snapshot'));
const [snapshotName, setSnapshotName] = useState<string>(generateSnapshotName(vm));
const [description, setDescription] = useState<string>(undefined);
const [deadline, setDeadline] = useState<string>(undefined);
const [deadlineUnit, setDeadlineUnit] = useState<deadlineUnits>(deadlineUnits.Seconds);
Expand Down
11 changes: 11 additions & 0 deletions src/utils/components/SnapshotModal/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { format } from 'date-fns';

import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { getName } from '@kubevirt-utils/resources/shared';

export const generateSnapshotName = (vm: V1VirtualMachine) => {
const date = new Date();
const formattedDate = format(date, 'yyyyMMdd-kkmmss');

return `${getName(vm)}-snapshot-${formattedDate}`;
};

0 comments on commit dc7d852

Please sign in to comment.