mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-24 01:20:49 +08:00
* 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>
180 lines
4.9 KiB
JavaScript
180 lines
4.9 KiB
JavaScript
import { get, clone } from '@shell/utils/object';
|
|
import { findBy } from '@shell/utils/array';
|
|
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
|
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
|
import { _CREATE } from '@shell/config/query-params';
|
|
import { HCI } from '../types';
|
|
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
|
|
import { BACKUP_TYPE } from '../config/types';
|
|
import HarvesterResource from './harvester';
|
|
|
|
export default class HciVmBackup extends HarvesterResource {
|
|
detailPageHeaderActionOverride(realMode) {
|
|
const route = this.currentRoute();
|
|
|
|
if (realMode === _CREATE) {
|
|
return route.params.resource === HCI.BACKUP ? this.t('harvester.backup.title') : this.t('harvester.vmSnapshot.title');
|
|
}
|
|
}
|
|
|
|
get detailLocation() {
|
|
const detailLocation = clone(this._detailLocation);
|
|
|
|
detailLocation.params.resource = HCI.BACKUP;
|
|
|
|
return detailLocation;
|
|
}
|
|
|
|
get disableResourceDetailDrawerConfigTab() {
|
|
return true;
|
|
}
|
|
|
|
get doneOverride() {
|
|
const route = this.currentRoute();
|
|
const detailLocation = clone(this._detailLocation);
|
|
|
|
delete detailLocation.params.namespace;
|
|
delete detailLocation.params.id;
|
|
detailLocation.params.resource = route.params.resource;
|
|
detailLocation.name = `${ HARVESTER_PRODUCT }-c-cluster-resource`;
|
|
|
|
return detailLocation;
|
|
}
|
|
|
|
get parentNameOverride() {
|
|
const route = this.currentRoute();
|
|
|
|
return this.$rootGetters['i18n/t'](`typeLabel."${ route.params.resource }"`, { count: 1 })?.trim();
|
|
}
|
|
|
|
get parentLocationOverride() {
|
|
return this.doneOverride;
|
|
}
|
|
|
|
get _availableActions() {
|
|
const toFilter = ['goToEdit', 'cloneYaml', 'goToClone', 'download'];
|
|
|
|
const out = super._availableActions.filter((action) => {
|
|
if (!toFilter.includes(action.action)) {
|
|
return action;
|
|
}
|
|
});
|
|
|
|
const schema = this.$getters['schemaFor'](HCI.VM);
|
|
let canCreateVM = true;
|
|
|
|
if ( schema && !schema?.collectionMethods.find((x) => ['post'].includes(x.toLowerCase())) ) {
|
|
canCreateVM = false;
|
|
}
|
|
|
|
return [
|
|
{
|
|
action: 'restoreExistingVM',
|
|
enabled: canCreateVM && this.attachVmExisting && this?.status?.readyToUse,
|
|
icon: 'icons icon-refresh',
|
|
label: this.t('harvester.action.restoreExistingVM'),
|
|
},
|
|
{
|
|
action: 'restoreNewVM',
|
|
enabled: canCreateVM && this?.status?.readyToUse,
|
|
icon: 'icons icon-backup',
|
|
label: this.t('harvester.action.restoreNewVM'),
|
|
},
|
|
...out
|
|
];
|
|
}
|
|
|
|
restoreExistingVM(resource = this) {
|
|
const router = this.currentRouter();
|
|
const targetResource = resource.spec.type === BACKUP_TYPE.SNAPSHOT ? HCI.VM_SNAPSHOT : HCI.BACKUP;
|
|
|
|
router.push({
|
|
name: `${ HARVESTER_PRODUCT }-c-cluster-resource-create`,
|
|
params: { resource: targetResource },
|
|
query: {
|
|
restoreMode: 'existing',
|
|
resourceName: resource.name,
|
|
}
|
|
});
|
|
}
|
|
|
|
restoreNewVM(resource = this) {
|
|
const router = this.currentRouter();
|
|
const targetResource = resource.spec.type === BACKUP_TYPE.SNAPSHOT ? HCI.VM_SNAPSHOT : HCI.BACKUP;
|
|
|
|
router.push({
|
|
name: `${ HARVESTER_PRODUCT }-c-cluster-resource-create`,
|
|
params: { resource: targetResource },
|
|
query: {
|
|
restoreMode: 'new',
|
|
resourceName: resource.name,
|
|
}
|
|
});
|
|
}
|
|
|
|
get state() {
|
|
let out = 'Pending';
|
|
const conditions = get(this, 'status.conditions');
|
|
const isProgress = findBy(conditions, 'type', 'InProgress')?.status === 'True';
|
|
const isReady = findBy(conditions, 'type', 'Ready')?.status === 'True';
|
|
|
|
if (this?.status?.readyToUse) {
|
|
out = 'Ready';
|
|
} else if (isProgress) {
|
|
out = 'Progressing';
|
|
} else if (!isReady) {
|
|
out = 'error';
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
get stateColor() {
|
|
const state = this.state;
|
|
|
|
return colorForState(state);
|
|
}
|
|
|
|
get sourceSchedule() {
|
|
return this.metadata?.annotations?.[HCI_ANNOTATIONS.SVM_BACKUP_ID];
|
|
}
|
|
|
|
get attachVM() {
|
|
return this.spec.source.name;
|
|
}
|
|
|
|
get backupTypeLabel() {
|
|
return this.t(`harvester.backup.type.${ this.spec?.type || BACKUP_TYPE.BACKUP }`);
|
|
}
|
|
|
|
get backupContentName() {
|
|
return this?.status?.virtualMachineBackupContentName || '';
|
|
}
|
|
|
|
get backupProgress() {
|
|
return {
|
|
type: BACKUP_TYPE.BACKUP,
|
|
percentage: this.status?.progress === undefined && !this.status?.readyToUse ? 0 : this.status?.progress,
|
|
details: { volumes: this.status?.volumeBackups }
|
|
};
|
|
}
|
|
|
|
get backupTarget() {
|
|
return this?.status?.backupTarget?.endpoint || '';
|
|
}
|
|
|
|
get attachVmExisting() {
|
|
const vmList = this.$rootGetters['harvester/all'](HCI.VM);
|
|
|
|
return !!vmList.find( (V) => V.metadata.name === this.attachVM);
|
|
}
|
|
|
|
remove() {
|
|
const opt = { ...arguments };
|
|
|
|
opt.params = { propagationPolicy: 'Foreground' };
|
|
|
|
return this._remove(opt);
|
|
}
|
|
}
|