Skip to content

Commit

Permalink
Adding the ability to configure resource sets to `resources.cattle.io…
Browse files Browse the repository at this point in the history
….backup`

Fixes: #12997
  • Loading branch information
codyrancher committed Feb 27, 2025
1 parent 54c4223 commit 49ee1e1
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 16 deletions.
12 changes: 11 additions & 1 deletion shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,17 @@ asyncButton:
success: Generated
waiting: Generating…

backupRestoreOperator:
backupRestoreOperator:
backup:
label: Resource Set
description: The Resource Set determines which resources the backup-restore-operator collects in a backup
enableEncryptionWarning: 'Enabling encryption is highly recommended when using <b><i>Full Rancher backup resource set</i></b>, otherwise sensitive information will be backed up as plain-text. <a target="_blank" rel="noopener noreferrer nofollow" href="https://ranchermanager.docs.rancher.com/reference-guides/backup-restore-configuration/backup-configuration#resourcesets">Read more</a>.'
missingResourceSetWarning: The <b><i>{resourceSet}</i></b> resource set doesn't exist, it's possible it has been deleted. Please select a different option.
resourceSetOptions:
'rancher-resource-set': 'Default Rancher backup resource set'
'rancher-resource-set-full': 'Full Rancher backup resource set'
custom: Custom
customResourceSetLabel: Custom Resource Set
backupFilename: Backup Filename
deleteTimeout:
label: Delete Timeout
Expand Down
157 changes: 142 additions & 15 deletions shell/edit/resources.cattle.io.backup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NameNsDescription from '@shell/components/form/NameNsDescription';
import Loading from '@shell/components/Loading';
import S3 from '@shell/chart/rancher-backup/S3';
import { mapGetters } from 'vuex';
import { SECRET, BACKUP_RESTORE, CATALOG } from '@shell/config/types';
import { SECRET, BACKUP_RESTORE, CATALOG, COUNT } from '@shell/config/types';
import { allHash } from '@shell/utils/promise';
import { NAMESPACE, _VIEW, _CREATE } from '@shell/config/query-params';
import { sortBy } from '@shell/utils/sort';
Expand All @@ -20,6 +20,10 @@ import { formatEncryptionSecretNames } from '@shell/utils/formatter';
import { FilterArgs, PaginationParamFilter } from '@shell/types/store/pagination.types';
import { SECRET_TYPES } from '@shell/config/secret';
const DEFAULT_RANCHER_BACKUP_RESOURCE_SET_ID = 'rancher-resource-set';
const FULL_RANCHER_BACKUP_RESOURCE_SET_ID = 'rancher-resource-set-full';
const CUSTOM_RESOURCE_SET_ID = 'custom';
export default {
components: {
Expand Down Expand Up @@ -50,18 +54,38 @@ export default {
async fetch() {
const hash = await allHash({
catalog: this.$store.dispatch('catalog/load'),
resourceSet: this.$store.dispatch('cluster/find', { type: BACKUP_RESTORE.RESOURCE_SET, id: this.value?.spec?.resourceSetName || 'rancher-resource-set' }),
apps: this.$store.dispatch('cluster/findAll', { type: CATALOG.APP })
catalog: this.$store.dispatch('catalog/load'),
allResourceSets: this.$store.dispatch('cluster/findAll', { type: BACKUP_RESTORE.RESOURCE_SET }),
apps: this.$store.dispatch('cluster/findAll', { type: CATALOG.APP })
});
this.apps = hash.apps;
this.resourceSet = hash.resourceSet;
this.allResourceSets = hash.allResourceSets;
const BRORelease = this.apps.filter((release) => get(release, 'spec.name') === 'rancher-backup')[0];
this.chartNamespace = BRORelease?.spec.namespace || '';
if (!this.value.spec.resourceSetName) {
this.value.spec.resourceSetName = DEFAULT_RANCHER_BACKUP_RESOURCE_SET_ID;
}
const computeResourceSetSelection = () => {
if (!this.value?.spec?.resourceSetName) {
const defaults = this.defaultExistingResourceSetOptionIds;
if (defaults.length > 0) {
return defaults[0];
}
return this.allResourceSets[0].id;
}
return this.defaultResourceSetOptionIds.includes(this.value?.spec?.resourceSetName) ? this.value?.spec?.resourceSetName : CUSTOM_RESOURCE_SET_ID;
};
this.resourceSetSelection = computeResourceSetSelection();
if (this.$store.getters[`cluster/paginationEnabled`](SECRET)) {
const findPageArgs = { // Of type ActionFindPageArgs
namespaced: this.chartNamespace,
Expand Down Expand Up @@ -105,17 +129,25 @@ export default {
s3 = this.value.spec.storageLocation.s3;
}
const counts = this.$store.getters[`cluster/all`](COUNT);
const defaultResourceSetOptionIds = [DEFAULT_RANCHER_BACKUP_RESOURCE_SET_ID, FULL_RANCHER_BACKUP_RESOURCE_SET_ID];
return {
secrets: [],
resourceSet: null,
secrets: [],
resourceSetCounts: counts?.[0]?.counts?.[BACKUP_RESTORE.RESOURCE_SET]?.summary?.count,
defaultResourceSetOptionIds,
allResourceSets: [],
resourceSetSelection: null,
s3,
storageSource,
useEncryption,
apps: [],
apps: [],
setSchedule,
name: this.value?.metadata?.name,
fvFormRuleSets: [{
path: 'metadata.name', rules: ['dnsLabel', 'noUpperCase'], translationKey: 'nameNsDescription.name.label'
name: this.value?.metadata?.name,
fvFormRuleSets: [{
path: 'metadata.name',
rules: ['dnsLabel', 'noUpperCase'],
translationKey: 'nameNsDescription.name.label'
}],
chartNamespace: null,
};
Expand Down Expand Up @@ -144,6 +176,48 @@ export default {
return { options, labels };
},
defaultExistingResourceSetOptionIds() {
return this.defaultResourceSetOptionIds.filter((id) => {
return this.allResourceSetIds.includes(id);
});
},
resourceSetOptions() {
const optionIds = [...this.defaultExistingResourceSetOptionIds];
const addCustom = !optionIds.includes(this.value.spec?.resourceSetName) || this.allResourceSetIds.length > optionIds.length;
if (addCustom) {
optionIds.push(CUSTOM_RESOURCE_SET_ID);
}
return optionIds.map((id) => {
return {
label: this.t(`backupRestoreOperator.backup.resourceSetOptions.${ id }`),
value: id
};
});
},
allResourceSetIds() {
return this.allResourceSets.map((rs) => rs.id);
},
customResourceSetOptions() {
return this.allResourceSetIds.filter((id) => !this.defaultResourceSetOptionIds.includes(id));
},
showCustomResourceSetOptions() {
return this.resourceSetSelection === CUSTOM_RESOURCE_SET_ID;
},
showEncryptionWarningBanner() {
return this.resourceSetSelection === 'rancher-resource-set-full';
},
showMissingResourceSetWarningBanner() {
return !this.allResourceSetIds.includes(this.value.spec.resourceSetName);
},
namespaces() {
const choices = this.$store.getters['cluster/all'](NAMESPACE);
const out = sortBy(choices.map((obj) => {
Expand Down Expand Up @@ -172,9 +246,11 @@ export default {
}
},
resourceSet(neu) {
if (neu?.metadata?.name) {
this.value.spec['resourceSetName'] = neu?.metadata?.name;
resourceSetSelection(neu) {
if (neu === CUSTOM_RESOURCE_SET_ID) {
this.value.spec.resourceSetName = this.customResourceSetOptions[0];
} else {
this.value.spec.resourceSetName = neu;
}
},
Expand Down Expand Up @@ -212,7 +288,7 @@ export default {
:rules="{name: fvGetAndReportPathRules('metadata.name')}"
@change="name=value.metadata.name"
/>
<template v-if="!!resourceSet">
<template v-if="resourceSetCounts > 0">
<div class="bordered-section">
<RadioGroup
v-model:value="setSchedule"
Expand Down Expand Up @@ -245,6 +321,57 @@ export default {
</div>
</div>
</div>
<div class="bordered-section">
<div class="row mb-10">
<div class="col span-12">
<h3>{{ t('backupRestoreOperator.backup.label') }}</h3>
<div>{{ t('backupRestoreOperator.backup.description') }}</div>
</div>
</div>
<div class="row">
<div class="col span-12">
<RadioGroup
v-model:value="resourceSetSelection"
name="resourceSet"
:options="resourceSetOptions"
:mode="mode"
/>
</div>
</div>
<div
v-if="showCustomResourceSetOptions"
class="row mt-10"
>
<div class="col span-6">
<LabeledSelect
v-model:value="value.spec.resourceSetName"
:mode="mode"
:options="customResourceSetOptions"
:label="t('backupRestoreOperator.backup.resourceSetOptions.customResourceSetLabel')"
/>
</div>
</div>
<div
v-if="showEncryptionWarningBanner"
class="row mt-10"
>
<div class="col span-12">
<Banner color="warning">
<span v-clean-html="t('backupRestoreOperator.backup.enableEncryptionWarning')" />
</Banner>
</div>
</div>
<div
v-if="showMissingResourceSetWarningBanner"
class="row mt-10"
>
<div class="col span-12">
<Banner color="warning">
<span v-clean-html="t('backupRestoreOperator.backup.missingResourceSetWarning', {resourceSet: value.spec.resourceSetName})" />
</Banner>
</div>
</div>
</div>
<div class="bordered-section">
<div class="row">
Expand Down

0 comments on commit 49ee1e1

Please sign in to comment.