mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-26 10:30:54 +08:00
feat: add Restic and Kopia VM backups (#1226)
* feat: add Restic and Kopia VM backups Add a type to Take Backup so VMs on third-party storage or Longhorn v2 can be backed up to S3. Native stays on the backup action, which has no type field. Restic and Kopia create the VirtualMachineBackup directly. Types a VM can't use stay in the dropdown, disabled, with the reason. Treat Restic and Kopia as remote backups in the restore routes, the schedule filter and the snapshot list. Show the type in the backup list. Add a form for the third-party-backup-config setting and the Kopia garbage collection option on the backup target, and stop resetting virtualHostedStyle when the backup target form opens. All of it sits behind a v1.10 feature flag. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: refine Take Backup for NFS targets and non-admin users Hide Take Backup on VMs that only have the snapshot action when the backup target is known not to be S3. Nothing can back those VMs up there, so they match the menu on main again. Only block Restic and Kopia on a backup target type the user can read. Non-admin users can't read the backup-target setting, so they were always told an S3 target was required. The webhook still decides. List why a type is unavailable under the Type select. Disabled options can't be reached by keyboard, so the reasons inside them were hidden from screen readers. Fall back to the default when third-party-backup-config doesn't parse, like the other settings forms, instead of showing a parse error banner. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: tighten Take Backup and backup config inputs after review - Offer Take Backup without the backup action only on VMs whose volumes Restic and Kopia support. The snapshot action isn't gated on a backup target, so users who can't read backup-target saw the menu on every VM. - Take the third-party-backup-config sizes in MiB, so a bare number is no longer saved as bytes. - Merge csi-driver-config value and default like the backend does, with the default's entries winning. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * feat: add the Restic and Kopia switch to the backup target The backend now rejects Restic and Kopia backups unless the S3 backup target has thirdPartyBackupEnabled set, and it is off by default. While it is on, every save of the target needs the repository password. - Add an "Enable Restic and Kopia Backups" checkbox to the S3 backup target form, dropped on NFS like Kopia garbage collection. - Show a required Repository Password field while the switch is on, and drop the password when the switch is off or the target is NFS, where the backend rejects it. - When the target is readable and the switch is off, Restic and Kopia are unavailable with a reason, after any volume reason, and Take Backup follows the same rule. - Rename the feature flag getter in the form and the dialog so it isn't confused with the setting field. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> * fix: offer Kopia garbage collection only while Restic and Kopia are on The backend removes the Kopia maintenance jobs whenever Restic and Kopia are turned off, so the option could be saved as on while nothing ran. Show it only while the switch is ticked, and drop it from the setting when the switch is turned off, like the repository password. Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com> --------- Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
This commit is contained in:
1 parent
1b562cec41
commit
0a49829658
19 files changed
+1142
-72
No files matched your search
@@ -2,7 +2,7 @@ import { load } from 'js-yaml';
|
||||
import { omitBy, pickBy } from 'lodash';
|
||||
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
|
||||
import { colorForState, stateSort } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { POD, NODE, PVC } from '@shell/config/types';
|
||||
import { POD, NODE, PV, PVC } from '@shell/config/types';
|
||||
import { FilterArgs, PaginationParamFilter } from '@shell/types/store/pagination.types';
|
||||
import { findBy } from '@shell/utils/array';
|
||||
import { parseSi } from '@shell/utils/units';
|
||||
@@ -16,7 +16,7 @@ import { HCI } from '../types';
|
||||
import HarvesterResource from './harvester';
|
||||
import { getVmCPUMemoryValues } from '../utils/cpuMemory';
|
||||
import { sharedComputed } from '../utils/shared-computed';
|
||||
import { isBackupTargetSettingUnavailable } from '../utils/setting';
|
||||
import { getBackupTarget, isBackupTargetSettingUnavailable } from '../utils/setting';
|
||||
|
||||
export const OFF = 'Off';
|
||||
|
||||
@@ -202,7 +202,7 @@ export default class VirtVm extends HarvesterResource {
|
||||
},
|
||||
{
|
||||
action: 'backupVM',
|
||||
enabled: !!this.actions?.backup && !this.isBackupTargetUnavailable,
|
||||
enabled: this.canTakeBackup && !this.isBackupTargetUnavailable,
|
||||
icon: 'icon icon-backup',
|
||||
label: this.t('harvester.action.backup')
|
||||
},
|
||||
@@ -976,7 +976,7 @@ export default class VirtVm extends HarvesterResource {
|
||||
const backup = this.$getters['byId'](HCI.BACKUP, backupId);
|
||||
|
||||
// Snapshots and backups are told apart by spec.type
|
||||
res.fromSnapshot = !!backup && backup.spec?.type !== BACKUP_TYPE.BACKUP;
|
||||
res.fromSnapshot = !!backup && backup.spec?.type === BACKUP_TYPE.SNAPSHOT;
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -1396,6 +1396,123 @@ export default class VirtVm extends HarvesterResource {
|
||||
return this.$rootGetters['harvester-common/getFeatureEnabled']('hotplugCdRom');
|
||||
}
|
||||
|
||||
get thirdPartyBackupFeatureEnabled() {
|
||||
return this.$rootGetters['harvester-common/getFeatureEnabled']('thirdPartyVMBackup');
|
||||
}
|
||||
|
||||
// The backend drops the backup action on Longhorn v2 and CDI volumes, which Restic and Kopia can still protect on S3.
|
||||
// Without it, offer the menu only on VMs whose volumes Restic and Kopia support, as the snapshot action isn't gated on a target
|
||||
get canTakeBackup() {
|
||||
return !!this.actions?.backup || (this.thirdPartyBackupFeatureEnabled && !!this.actions?.snapshot && !this.dataMoverBackupUnavailableReason);
|
||||
}
|
||||
|
||||
// Only users who can read backup-target know its type and whether it allows Restic and Kopia, for everyone else the webhook decides
|
||||
get isBackupTargetNotS3() {
|
||||
const { type } = getBackupTarget(this.$rootGetters['harvester/byId'](HCI.SETTING, 'backup-target'));
|
||||
|
||||
return !!type && type !== 's3';
|
||||
}
|
||||
|
||||
// The backend rejects Restic and Kopia until thirdPartyBackupEnabled is set on the S3 target
|
||||
get isThirdPartyBackupOffOnTarget() {
|
||||
const { type, thirdPartyBackupEnabled } = getBackupTarget(this.$rootGetters['harvester/byId'](HCI.SETTING, 'backup-target'));
|
||||
|
||||
return type === 's3' && !thirdPartyBackupEnabled;
|
||||
}
|
||||
|
||||
async fetchBackupTypeRequirements() {
|
||||
const claimNames = this.spec.template.spec.volumes?.map((v) => v.persistentVolumeClaim?.claimName).filter((v) => !!v) || [];
|
||||
|
||||
// Each rule is enforced by the webhook too, so a resource this user can't read must not block the dialog
|
||||
await Promise.allSettled([
|
||||
...claimNames.map((name) => this.$dispatch('find', { type: PVC, id: `${ this.metadata.namespace }/${ name }` })),
|
||||
this.$dispatch('find', { type: HCI.SETTING, id: 'backup-target' }),
|
||||
this.$dispatch('find', { type: HCI.SETTING, id: 'csi-driver-config' }),
|
||||
]);
|
||||
|
||||
await Promise.allSettled(
|
||||
this.volumes.filter((pvc) => pvc.spec?.volumeName).map((pvc) => this.$dispatch('find', { type: PV, id: pvc.spec.volumeName }))
|
||||
);
|
||||
}
|
||||
|
||||
get backupTypeOptions() {
|
||||
const nativeReason = this.nativeBackupUnavailableReason;
|
||||
const dataMoverReason = this.dataMoverBackupUnavailableReason;
|
||||
|
||||
return [BACKUP_TYPE.BACKUP, BACKUP_TYPE.RESTIC, BACKUP_TYPE.KOPIA].map((value) => {
|
||||
const unavailableReason = value === BACKUP_TYPE.BACKUP ? nativeReason : dataMoverReason;
|
||||
|
||||
return {
|
||||
value,
|
||||
label: this.t(`harvester.backup.type.${ value }`),
|
||||
disabled: !!unavailableReason,
|
||||
unavailableReason,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
get nativeBackupUnavailableReason() {
|
||||
if (!this.actions?.backup) {
|
||||
const longhornV2 = this.longhornV2Volumes[0];
|
||||
const cdi = this.volumes.find((pvc) => pvc.isCreatedForDataVolume);
|
||||
|
||||
if (longhornV2) {
|
||||
return this.t('harvester.backup.typeUnavailable.longhornV2', { volume: longhornV2.name });
|
||||
}
|
||||
|
||||
return cdi ? this.t('harvester.backup.typeUnavailable.cdi', { volume: cdi.name }) : this.t('harvester.backup.typeUnavailable.native');
|
||||
}
|
||||
|
||||
const driver = this.driverMissingSnapshotClass('backupVolumeSnapshotClassName');
|
||||
|
||||
return driver ? this.t('harvester.backup.typeUnavailable.noBackupSnapshotClass', { driver }) : undefined;
|
||||
}
|
||||
|
||||
get dataMoverBackupUnavailableReason() {
|
||||
if (this.isBackupTargetNotS3) {
|
||||
return this.t('harvester.backup.typeUnavailable.requiresS3');
|
||||
}
|
||||
|
||||
const filesystem = this.volumes.find((pvc) => !pvc.isBlockVolume);
|
||||
|
||||
if (filesystem) {
|
||||
return this.t('harvester.backup.typeUnavailable.requiresBlock', { volume: filesystem.name });
|
||||
}
|
||||
|
||||
const longhornV1 = this.volumes.find((pvc) => pvc.isLonghornV1);
|
||||
|
||||
if (longhornV1) {
|
||||
return this.t('harvester.backup.typeUnavailable.longhornV1', { volume: longhornV1.name });
|
||||
}
|
||||
|
||||
if (!this.actions?.snapshot) {
|
||||
const driver = this.driverMissingSnapshotClass('volumeSnapshotClassName');
|
||||
|
||||
return driver ? this.t('harvester.backup.typeUnavailable.noSnapshotClass', { driver }) : this.t('harvester.backup.typeUnavailable.snapshot');
|
||||
}
|
||||
|
||||
// Last, so a reason that turning it on wouldn't fix is shown first
|
||||
if (this.isThirdPartyBackupOffOnTarget) {
|
||||
return this.t('harvester.backup.typeUnavailable.thirdPartyBackupOff');
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
driverMissingSnapshotClass(classKey) {
|
||||
const setting = this.$rootGetters['harvester/byId'](HCI.SETTING, 'csi-driver-config');
|
||||
let config;
|
||||
|
||||
// Like the backend's LoadCSIDriverConfig: value adds drivers, the default's entries win
|
||||
try {
|
||||
config = { ...JSON.parse(setting?.value || '{}'), ...JSON.parse(setting?.default) };
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.volumes.map((pvc) => pvc.volumeProvider).find((driver) => driver && !config[driver]?.[classKey]);
|
||||
}
|
||||
|
||||
get isBackupTargetUnavailable() {
|
||||
const backupTargetSetting = this.$rootGetters['harvester/byId'](HCI.SETTING, 'backup-target');
|
||||
|
||||
|
||||
Reference in new issue
Block a user