Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Fix rendered disk size <1Gi
Browse files Browse the repository at this point in the history
If disk size is < 1 Gi in the Storage Tab of CreateVmWizard,
the value is reformatted and appended by a lower matching unit.

Corresponding PVC is created with a value conforming the format
required by Kubernetes.
  • Loading branch information
mareklibra committed May 15, 2019
1 parent 6c9375a commit 781ccc1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/components/Table/EditableDraggableTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ class EditableDraggableTable extends React.Component {

getRenderConfig = additionalData => {
const { renderConfig } = additionalData.column;

return renderConfig ? renderConfig(additionalData.rowData) : null;
};

resolveRenderedValue = (value, additionalData, editable) => {
const renderConfig = this.getRenderConfig(additionalData);
const { readValueFormatter } = additionalData.column;

let result;
if (this.isDropdown(additionalData)) {
result = get(renderConfig.choices.find(clazz => clazz.id === value), 'name');
Expand All @@ -205,6 +206,10 @@ class EditableDraggableTable extends React.Component {
result = value;
}

if (!editable && readValueFormatter) {
result = readValueFormatter(result);
}

if (!editable && additionalData.column.hasAddendum) {
const { addendum } = additionalData.rowData;
if (addendum) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Wizard/CreateVmWizard/CreateVmWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export class CreateVmWizard extends React.Component {
vmSettings,
this.state.stepData[NETWORKS_TAB_KEY].value,
this.state.stepData[STORAGE_TAB_KEY].value,
this.props.persistentVolumeClaims
this.props.persistentVolumeClaims,
this.props.units,
)
.then(() => getResults(enhancedK8sMethods))
.catch(error => cleanupAndGetResults(enhancedK8sMethods, error))
Expand Down
3 changes: 3 additions & 0 deletions src/components/Wizard/CreateVmWizard/StorageTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import {

import { canBeBootable, needsBootableDisk } from './utils/storageTabUtils';

import { getValidK8SSize } from '../../../utils';

const initalStorageErrorsArray = () => Array(4).fill(null);

const genericValidator = (storage, validationResolvers) =>
Expand Down Expand Up @@ -428,6 +430,7 @@ export class StorageTab extends React.Component {
type: POSITIVE_NUMBER,
}
: null,
readValueFormatter: value => value < 1 ? getValidK8SSize(value, this.props.units, 'Gi', false) : value,
},
{
header: {
Expand Down
5 changes: 3 additions & 2 deletions src/k8s/objects/pvc/pvc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PersistentVolumeClaimModel } from '../../../models/index';
import { getValidK8SSize } from '../../../utils';

export const buildPvc = ({ generateName, namespace, storageType, size, storageClass }) => ({
export const buildPvc = ({generateName, namespace, storageType, size, storageClass, units}) => ({
apiVersion: PersistentVolumeClaimModel.apiVersion,
kind: PersistentVolumeClaimModel.kind,
metadata: {
Expand All @@ -12,7 +13,7 @@ export const buildPvc = ({ generateName, namespace, storageType, size, storageCl
volumeMode: 'Filesystem',
resources: {
requests: {
storage: `${size}Gi`,
storage: getValidK8SSize(size, units, 'Gi', true),
},
},
storageClassName: storageClass,
Expand Down
5 changes: 3 additions & 2 deletions src/k8s/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export const createVm = async (
vmSettings,
networks,
storages,
persistentVolumeClaims
persistentVolumeClaims,
units
) => {
const getSetting = settingsValue.bind(undefined, vmSettings);

Expand All @@ -195,7 +196,7 @@ export const createVm = async (
const importResult = await importVmwareVm(vmSettings, networks, storages, {
k8sCreate,
k8sPatch,
});
}, units);
// eslint-disable-next-line prefer-destructuring
conversionPod = importResult.conversionPod;
storages = importResult.mappedStorages;
Expand Down
8 changes: 5 additions & 3 deletions src/k8s/requests/v2v/importVmware.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const createProviderSecret = async (vmSettings, networks, storages, { k8sCreate
return null;
};

const resolveStorages = async (vmSettings, networks, storages, { k8sCreate }) => {
const resolveStorages = async (vmSettings, networks, storages, { k8sCreate }, lastResults, units) => {
const isImportStorage = storage =>
[STORAGE_TYPE_EXTERNAL_IMPORT, STORAGE_TYPE_EXTERNAL_V2V_TEMP].includes(storage.storageType);
const namespace = settingsValue(vmSettings, NAMESPACE_KEY);
Expand All @@ -88,6 +88,7 @@ const resolveStorages = async (vmSettings, networks, storages, { k8sCreate }) =>
generateName: storage.name,
name: undefined,
namespace,
units,
})
)
);
Expand Down Expand Up @@ -230,7 +231,7 @@ const startConversionPod = async (
};
};

export const importVmwareVm = async (vmSettings, networks, storages, { k8sCreate, k8sPatch }) =>
export const importVmwareVm = async (vmSettings, networks, storages, { k8sCreate, k8sPatch }, units) =>
[
createProviderSecret,
createConversionPodSecret,
Expand All @@ -247,7 +248,8 @@ export const importVmwareVm = async (vmSettings, networks, storages, { k8sCreate
k8sCreate,
k8sPatch,
},
lastResult
lastResult,
units,
);
return {
...lastResult,
Expand Down
2 changes: 2 additions & 0 deletions src/k8s/requests/v2v/startV2VvmwareController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const startV2VVMWareController = async ({ namespace }, { k8sGet, k8sCreat
: 'V2V VMWare controller deployment not found, so creating one ...'
);

// TODO: do not fail if i.e. ServiceAccount already exists
// TODO: notify user if deployment fails
[cleanupOldDeployment, resolveRolesAndServiceAccount, startVmWare].reduce(
async (lastResultPromise, stepFunction) => {
const lastResult = await lastResultPromise;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,10 @@ export const objectMerge = (dest, ...sources) =>
}
return undefined;
});

// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/scheduling/resources.md#resource-quantities
export const getValidK8SSize = (size, units, sizeUnit = 'Gi', useTrim = true) => {
const baseSize = units.dehumanize(`${size}${sizeUnit}`, 'binaryBytesWithoutB');
const validSize = units.humanize(baseSize.value, 'binaryBytesWithoutB');
return useTrim ? `${validSize.value}${validSize.unit.trim()}` : validSize.string;
};

0 comments on commit 781ccc1

Please sign in to comment.