Skip to content

Commit

Permalink
Merge pull request #1228 from harvester/mergify/bp/release-harvester-…
Browse files Browse the repository at this point in the history
…v1.4/pr-1226

Get provisioner and engine version from Volume (backport #1226)
  • Loading branch information
torchiaf authored Nov 8, 2024
2 parents b6cefc3 + 1309662 commit e54a466
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 34 deletions.
4 changes: 1 addition & 3 deletions pkg/harvester/edit/harvesterhci.io.storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import { allHash } from '@shell/utils/promise';
import { clone } from '@shell/utils/object';
import { LONGHORN_DRIVER } from '@shell/models/persistentvolume';
import { LVM_DRIVER } from '../../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V1, DATA_ENGINE_V2 } from '../../models/harvester/persistentvolumeclaim';
const LONGHORN_V2_DATA_ENGINE = 'longhorn-system/v2-data-engine';
export const DATA_ENGINE_V1 = 'v1';
export const DATA_ENGINE_V2 = 'v2';
export const LVM_TOPOLOGY_LABEL = 'topology.lvm.csi/node';
const VOLUME_BINDING_MODE_IMMEDIATE = 'Immediate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { _CREATE, _VIEW } from '@shell/config/query-params';
import { CSI_SECRETS } from '@pkg/harvester/config/harvester-map';
import { clone } from '@shell/utils/object';
import { uniq } from '@shell/utils/array';
import { DATA_ENGINE_V1 } from '../index.vue';
import { DATA_ENGINE_V1 } from '../../../models/harvester/persistentvolumeclaim';
// UI components for Longhorn storage class parameters
const DEFAULT_PARAMETERS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { _CREATE, _VIEW } from '@shell/config/query-params';
import { CSI_SECRETS } from '@pkg/harvester/config/harvester-map';
import { clone } from '@shell/utils/object';
import { uniq } from '@shell/utils/array';
import { DATA_ENGINE_V2 } from '../index.vue';
import { DATA_ENGINE_V2 } from '../../../models/harvester/persistentvolumeclaim';
// UI components for Longhorn storage class parameters
const DEFAULT_PARAMETERS = [
Expand Down
28 changes: 16 additions & 12 deletions pkg/harvester/edit/harvesterhci.io.volume.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import CreateEditView from '@shell/mixins/create-edit-view';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import { STATE, NAME, AGE, NAMESPACE } from '@shell/config/table-headers';
import { LVM_DRIVER } from '../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V2 } from './harvesterhci.io.storage/index.vue';
import { DATA_ENGINE_V2 } from '../models/harvester/persistentvolumeclaim';
export default {
name: 'HarvesterVolume',
Expand Down Expand Up @@ -224,25 +224,29 @@ export default {
rebuildStatus() {
return this.value.longhornEngine?.status?.rebuildStatus;
},
isLonghornV2() {
return this.value.storageClass?.isLonghornV2;
}
},
methods: {
getAccessMode() {
const storageClassName = this.value.spec.storageClassName;
const storageClass = this.storageClasses.find(sc => sc.name === storageClassName);
let readWriteOnce = this.value.isLvm || this.value.isLonghornV2;
if (storageClass) {
readWriteOnce = storageClass.provisioner === LVM_DRIVER || storageClass.parameters?.dataEngine === DATA_ENGINE_V2;
}
return readWriteOnce ? ['ReadWriteOnce'] : ['ReadWriteMany'];
},
willSave() {
this.update();
},
update() {
let imageAnnotations = '';
let storageClassName = this.value.spec.storageClassName;
const storageClass = this.storageClasses.find(sc => sc.name === storageClassName);
const storageClassProvisioner = storageClass?.provisioner;
const storageClassDataEngine = storageClass?.parameters?.dataEngine;
if (this.isVMImage && this.imageId) {
const images = this.$store.getters['harvester/all'](HCI.IMAGE);
Expand All @@ -259,7 +263,7 @@ export default {
...this.value.spec,
resources: { requests: { storage: this.storage } },
storageClassName,
accessModes: storageClassProvisioner === LVM_DRIVER || storageClassDataEngine === DATA_ENGINE_V2 ? ['ReadWriteOnce'] : ['ReadWriteMany'],
accessModes: this.getAccessMode(),
};
this.value.setAnnotations(imageAnnotations);
Expand Down Expand Up @@ -349,13 +353,13 @@ export default {
:output-modifier="true"
:increment="1024"
:mode="mode"
:disabled="isLonghornV2 && isEdit"
:disabled="value?.isLonghornV2 && isEdit"
required
class="mb-20"
@input="update"
/>
<Banner v-if="isLonghornV2 && isEdit" color="warning">
<Banner v-if="value?.isLonghornV2 && isEdit" color="warning">
<span>{{ t('harvester.volume.longhorn.disableResize') }}</span>
</Banner>
</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default {
},
isLonghornV2(volume) {
return volume?.pvc?.storageClass?.isLonghornV2;
return volume?.pvc?.isLonghornV2 || volume?.pvc?.storageClass?.isLonghornV2;
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
},
isLonghornV2() {
return this.value.pvc?.storageClass?.isLonghornV2;
return this.value.pvc?.isLonghornV2 || this.value.pvc?.storageClass?.isLonghornV2;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { _VIEW } from '@shell/config/query-params';
import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string';
import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass';
import { DATA_ENGINE_V2 } from '../../../../edit/harvesterhci.io.storage/index.vue';
import { DATA_ENGINE_V2 } from '../../../../models/harvester/persistentvolumeclaim';
export default {
name: 'HarvesterEditVolume',
Expand Down Expand Up @@ -102,19 +102,15 @@ export default {
},
isLonghornV2() {
return this.value.pvc?.storageClass?.isLonghornV2;
return this.value.pvc?.isLonghornV2 || this.value.pvc?.storageClass?.isLonghornV2;
}
},
watch: {
'value.storageClassName': {
immediate: true,
handler(neu) {
const storageClass = this.storageClasses.find(sc => sc.name === neu);
const provisioner = storageClass?.provisioner;
const engine = storageClass?.parameters?.dataEngine;
this.value.accessMode = provisioner === LVM_DRIVER || engine === DATA_ENGINE_V2 ? 'ReadWriteOnce' : 'ReadWriteMany';
this.value.accessMode = this.getAccessMode(neu);
}
},
Expand Down Expand Up @@ -146,6 +142,18 @@ export default {
},
methods: {
getAccessMode(storageClassName) {
const storageClass = this.storageClasses.find(sc => sc.name === storageClassName);
let readWriteOnce = this.value.pvc?.isLvm || this.value.pvc?.isLonghornV2;
if (storageClass) {
readWriteOnce = storageClass.provisioner === LVM_DRIVER || storageClass.parameters?.dataEngine === DATA_ENGINE_V2;
}
return readWriteOnce ? 'ReadWriteOnce' : 'ReadWriteMany';
},
update() {
this.$emit('update');
},
Expand Down
30 changes: 26 additions & 4 deletions pkg/harvester/models/harvester/persistentvolumeclaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { get, clone } from '@shell/utils/object';
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
import HarvesterResource from '../harvester';
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../config/harvester';

import { LVM_DRIVER } from './storage.k8s.io.storageclass';
import { LONGHORN_DRIVER } from '@shell/models/persistentvolume';
import { DATA_ENGINE_V2 } from '../../edit/harvesterhci.io.storage/index.vue';

const DEGRADED_ERRORS = ['replica scheduling failed', 'precheck new replica failed'];

export const DATA_ENGINE_V1 = 'v1';
export const DATA_ENGINE_V2 = 'v2';

export default class HciPv extends HarvesterResource {
applyDefaults(_, realMode) {
const accessModes = realMode === _CLONE ? this.spec.accessModes : [];
Expand All @@ -36,7 +38,7 @@ export default class HciPv extends HarvesterResource {
let out = super._availableActions;

// Longhorn V2 provisioner do not support volume clone feature yet
if (this.storageClass.longhornVersion === DATA_ENGINE_V2) {
if (this.isLonghornV2) {
out = out.filter(action => action.action !== 'goToClone');
} else {
const clone = out.find(action => action.action === 'goToClone');
Expand All @@ -46,7 +48,7 @@ export default class HciPv extends HarvesterResource {
}
}

if (this.storageClass.provisioner !== LONGHORN_DRIVER || this.storageClass.longhornVersion !== DATA_ENGINE_V2) {
if (!this.isLonghorn || !this.isLonghornV2) {
out = [
{
action: 'exportImage',
Expand Down Expand Up @@ -305,6 +307,26 @@ export default class HciPv extends HarvesterResource {
return this.$rootGetters['harvester/all'](PV).find(pv => pv.metadata?.name === this.spec?.volumeName);
}

get volumeProvider() {
return this.relatedPV?.spec.csi?.driver;
}

get dataEngine() {
return this.relatedPV?.spec.csi?.volumeAttributes?.dataEngine;
}

get isLvm() {
return this.volumeProvider === LVM_DRIVER;
}

get isLonghorn() {
return this.volumeProvider === LONGHORN_DRIVER;
}

get isLonghornV2() {
return this.dataEngine === DATA_ENGINE_V2;
}

get resourceExternalLink() {
const host = window.location.host;
const { params } = this.currentRoute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HCI } from '../../types';
import StorageClass from '@shell/models/storage.k8s.io.storageclass';
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../config/harvester';
import { LONGHORN_DRIVER } from '@shell/models/persistentvolume';
import { DATA_ENGINE_V1, DATA_ENGINE_V2 } from '../../edit/harvesterhci.io.storage/index.vue';
import { DATA_ENGINE_V1, DATA_ENGINE_V2 } from '../../models/harvester/persistentvolumeclaim';

export const LVM_DRIVER = 'lvm.driver.harvesterhci.io';

Expand Down
5 changes: 2 additions & 3 deletions pkg/harvester/models/kubevirt.io.virtualmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { matchesSomeRegex } from '@shell/utils/string';
import { LABELS_TO_IGNORE_REGEX } from '@shell/config/labels-annotations';
import { BACKUP_TYPE } from '../config/types';
import { parseVolumeClaimTemplates } from '@pkg/utils/vm';
import { LVM_DRIVER } from './harvester/storage.k8s.io.storageclass';

export const OFF = 'Off';

Expand Down Expand Up @@ -610,11 +609,11 @@ export default class VirtVm extends HarvesterResource {
}

get lvmVolumes() {
return this.volumes.filter(volume => volume.storageClass.provisioner === LVM_DRIVER);
return this.volumes.filter(volume => volume?.isLvm);
}

get longhornV2Volumes() {
return this.volumes.filter(volume => volume.storageClass.isLonghornV2);
return this.volumes.filter(volume => volume?.isLonghornV2);
}

get encryptedVolumeType() {
Expand Down

0 comments on commit e54a466

Please sign in to comment.