mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-01 03:36:04 +08:00
feat: support advance option and creation from DataVolume (#776)
* feat: support advance option and creation from DataVolume
- advance option would let user change the accessMode/volumeMode
- creation from DataVolume could supports various scenario with
3rd-party storage
Signed-off-by: Vicente Cheng <freeze.bilsted@gmail.com>
* feat: add data migration action on volume page
Signed-off-by: Vicente Cheng <freeze.bilsted@gmail.com>
* refactor: use show advanced options link instead of checkbox
Signed-off-by: Andy Lee <andy.lee@suse.com>
* feat: add feature flag
Signed-off-by: Andy Lee <andy.lee@suse.com>
* feat: add feature flag for dataMigration action
Signed-off-by: Andy Lee <andy.lee@suse.com>
---------
Signed-off-by: Vicente Cheng <freeze.bilsted@gmail.com>
Signed-off-by: Andy Lee <andy.lee@suse.com>
Co-authored-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
@@ -9,8 +9,11 @@ import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import NameNsDescription from '@shell/components/form/NameNsDescription';
|
||||
import Conditions from '@shell/components/form/Conditions';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { Checkbox } from '@components/Form/Checkbox';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { exceptionToErrorsArray } from '@shell/utils/error';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
import { get } from '@shell/utils/object';
|
||||
import { clone, get } from '@shell/utils/object';
|
||||
import { STORAGE_CLASS, LONGHORN, PV } from '@shell/config/types';
|
||||
import { sortBy } from '@shell/utils/sort';
|
||||
import { saferDump } from '@shell/utils/create-yaml';
|
||||
@@ -33,6 +36,7 @@ export default {
|
||||
|
||||
components: {
|
||||
Banner,
|
||||
Checkbox,
|
||||
Tab,
|
||||
UnitInput,
|
||||
CruResource,
|
||||
@@ -90,14 +94,34 @@ export default {
|
||||
source,
|
||||
storage,
|
||||
imageId,
|
||||
snapshots: [],
|
||||
images: [],
|
||||
showAdvanced: false,
|
||||
createWithDataVolume: false,
|
||||
snapshots: [],
|
||||
images: [],
|
||||
GIBIBYTE
|
||||
};
|
||||
},
|
||||
|
||||
created() {
|
||||
this.registerBeforeHook(this.willSave, 'willSave');
|
||||
|
||||
if (this.mode === _CREATE) {
|
||||
const originalSaveYaml = this.value.saveYaml?.bind(this.value);
|
||||
|
||||
this.value.saveYaml = async(yaml) => {
|
||||
if (this.createWithDataVolume && this.isBlank) {
|
||||
const parsed = jsyaml.load(yaml);
|
||||
const dvObj = { ...parsed, type: 'cdi.kubevirt.io.datavolume' };
|
||||
const dataVolume = await this.$store.dispatch('harvester/create', dvObj);
|
||||
|
||||
await dataVolume.save();
|
||||
|
||||
return dataVolume;
|
||||
}
|
||||
|
||||
return originalSaveYaml(yaml);
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
@@ -135,6 +159,10 @@ export default {
|
||||
return Object.values(VOLUME_MODE);
|
||||
},
|
||||
|
||||
accessModeOptions() {
|
||||
return ['ReadWriteOnce', 'ReadWriteMany', 'ReadOnlyMany'];
|
||||
},
|
||||
|
||||
imageOption() {
|
||||
return sortBy(
|
||||
this.images
|
||||
@@ -275,6 +303,10 @@ export default {
|
||||
return this.$store.getters['harvester-common/getFeatureEnabled']('lhV2VolExpansion');
|
||||
},
|
||||
|
||||
isCreatePVCWithDataVolumeFeatureEnabled() {
|
||||
return this.$store.getters['harvester-common/getFeatureEnabled']('createPVCWithDataVolume');
|
||||
},
|
||||
|
||||
isResizeDisabled() {
|
||||
return (
|
||||
!this.isLHV2VolExpansionFeatureEnabled &&
|
||||
@@ -341,6 +373,58 @@ export default {
|
||||
|
||||
return readWriteOnce ? ['ReadWriteOnce'] : ['ReadWriteMany'];
|
||||
},
|
||||
buildDataVolumeObj() {
|
||||
const storage = {
|
||||
storageClassName: this.value.spec.storageClassName,
|
||||
resources: { requests: { storage: this.storage } },
|
||||
};
|
||||
|
||||
if (this.showAdvanced && this.value.spec.accessModes?.length > 0) {
|
||||
storage.accessModes = this.value.spec.accessModes;
|
||||
}
|
||||
|
||||
if (this.showAdvanced && this.value.spec.volumeMode) {
|
||||
storage.volumeMode = this.value.spec.volumeMode;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'cdi.kubevirt.io.datavolume',
|
||||
apiVersion: 'cdi.kubevirt.io/v1beta1',
|
||||
kind: 'DataVolume',
|
||||
metadata: {
|
||||
name: this.value.metadata.name,
|
||||
namespace: this.value.metadata.namespace,
|
||||
annotations: this.value.metadata.annotations || {},
|
||||
labels: this.value.metadata.labels || {},
|
||||
},
|
||||
spec: {
|
||||
source: { blank: {} },
|
||||
storage,
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
async save(buttonDone) {
|
||||
if (this.isCreate && this.isBlank && this.createWithDataVolume) {
|
||||
try {
|
||||
this.update();
|
||||
const dvObj = this.buildDataVolumeObj();
|
||||
const dataVolume = await this.$store.dispatch('harvester/create', dvObj);
|
||||
|
||||
await dataVolume.save();
|
||||
buttonDone(true);
|
||||
this.done();
|
||||
} catch (err) {
|
||||
const error = err?.data || err;
|
||||
|
||||
this['errors'] = exceptionToErrorsArray(error);
|
||||
buttonDone(false);
|
||||
}
|
||||
} else {
|
||||
await CreateEditView.methods.save.call(this, buttonDone);
|
||||
}
|
||||
},
|
||||
|
||||
willSave() {
|
||||
this.update();
|
||||
},
|
||||
@@ -383,9 +467,17 @@ export default {
|
||||
this.update();
|
||||
},
|
||||
generateYaml() {
|
||||
const out = saferDump(this.value);
|
||||
this.update();
|
||||
|
||||
return out;
|
||||
if (this.isCreate && this.isBlank && this.createWithDataVolume) {
|
||||
return saferDump(this.buildDataVolumeObj());
|
||||
}
|
||||
|
||||
const plain = clone(this.value);
|
||||
|
||||
delete plain.saveYaml;
|
||||
|
||||
return saferDump(plain);
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -458,18 +550,6 @@ export default {
|
||||
@update:value="update"
|
||||
/>
|
||||
|
||||
<LabeledSelect
|
||||
v-if="showVolumeMode"
|
||||
v-model:value="value.spec.volumeMode"
|
||||
:label="t('harvester.volume.volumeMode')"
|
||||
:options="volumeModeOptions"
|
||||
required
|
||||
:disabled="!isCreate"
|
||||
:mode="mode"
|
||||
class="mb-20"
|
||||
@update:value="update"
|
||||
/>
|
||||
|
||||
<UnitInput
|
||||
v-model:value="storage"
|
||||
:label="t('harvester.volume.size')"
|
||||
@@ -490,6 +570,44 @@ export default {
|
||||
>
|
||||
<span>{{ t('harvester.volume.longhorn.disableResize') }}</span>
|
||||
</Banner>
|
||||
|
||||
<div class="row mb-20">
|
||||
<Checkbox
|
||||
v-if="isCreate && isBlank && isCreatePVCWithDataVolumeFeatureEnabled"
|
||||
v-model:value="createWithDataVolume"
|
||||
:label="t('harvester.volume.createWithDataVolume')"
|
||||
tooltip-key="harvester.volume.createWithDataVolumeTooltip"
|
||||
/>
|
||||
</div>
|
||||
<a
|
||||
v-if="isCreate && isCreatePVCWithDataVolumeFeatureEnabled"
|
||||
role="button"
|
||||
class="hand"
|
||||
@click="showAdvanced = !showAdvanced"
|
||||
>
|
||||
{{ showAdvanced ? t('harvester.volume.hideAdvanced') : t('harvester.volume.showAdvanced') }}
|
||||
</a>
|
||||
|
||||
<LabeledSelect
|
||||
v-if="showAdvanced"
|
||||
v-model:value="value.spec.accessModes"
|
||||
:label="t('harvester.volume.accessModes')"
|
||||
:options="accessModeOptions"
|
||||
:multiple="true"
|
||||
:mode="mode"
|
||||
class="mb-20 mt-20"
|
||||
@update:value="update"
|
||||
/>
|
||||
|
||||
<LabeledSelect
|
||||
v-if="showAdvanced"
|
||||
v-model:value="value.spec.volumeMode"
|
||||
:label="t('harvester.volume.volumeMode')"
|
||||
:options="volumeModeOptions"
|
||||
:mode="mode"
|
||||
class="mb-20"
|
||||
@update:value="update"
|
||||
/>
|
||||
</Tab>
|
||||
<Tab
|
||||
v-if="!isCreate"
|
||||
|
||||
Reference in New Issue
Block a user