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

Fix rendered disk size <1Gi #452

Merged
merged 5 commits into from
May 16, 2019

Conversation

mareklibra
Copy link
Contributor

@mareklibra mareklibra commented May 15, 2019

If disk size < 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.


Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1708195

@mareklibra
Copy link
Contributor Author

diskSize

@mareklibra mareklibra changed the title Fix rendered disk size <1Gi WIP Fix rendered disk size <1Gi May 15, 2019
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.
@mareklibra mareklibra force-pushed the v2v.bz1708195.diskSize branch from 781ccc1 to 5c5dc94 Compare May 15, 2019 08:48
@coveralls
Copy link

coveralls commented May 15, 2019

Pull Request Test Coverage Report for Build 1858

  • 31 of 37 (83.78%) changed or added relevant lines in 8 files are covered.
  • 15 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.3%) to 84.001%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Wizard/CreateVmWizard/StorageTab.js 5 7 71.43%
src/k8s/requests/v2v/importVmware.js 3 5 60.0%
src/utils/utils.js 1 3 33.33%
Files with Coverage Reduction New Missed Lines %
src/k8s/requests/v2v/startV2VvmwareController.js 1 13.33%
src/components/Form/FormFactory.js 2 92.98%
src/utils/status/vm/vmStatus.js 2 92.37%
src/components/VmStatus/VmStatus.js 3 92.21%
src/selectors/prometheus/storage.js 3 58.82%
src/components/StorageOverview/TopConsumers/TopConsumers.js 4 88.68%
Totals Coverage Status
Change from base Build 1583: 0.3%
Covered Lines: 3962
Relevant Lines: 4519

💛 - Coveralls

@mareklibra mareklibra changed the title WIP Fix rendered disk size <1Gi Fix rendered disk size <1Gi May 15, 2019
@mareklibra
Copy link
Contributor Author

mareklibra commented May 15, 2019

@andybraren , any idea how to better present disk sizes of different units?

In most cases, the size in GiB is ok.
I think it's good to keep the user requesting disks per GiBs.

Anyway, in v2v flow, the disks can be smaller, like 1 KiB.
It's a rare case but should be handled.

@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably makes more sense to have this inside the renderConfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be inconstent for ediable fields (showing one size and seeing something different when editing the filed).

the inconsistencies could be resolved for now if we allow this only for STORAGE_TYPE_EXTERNAL_V2V_TEMP, STORAGE_TYPE_EXTERNAL_V2V_VDDK types and explicitely say it should not be editable in the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For v2v, it's not editable already.

For other flows, the user is not allowed to enter floating point number to disk size, so effectively the formatting is used in the single relevant case only.

If something, we should handle just the STORAGE_TYPE_EXTERNAL_IMPORT case, not the two mentioned.
Recently, component edit mode is disabled when renderConfig is missing. Changing that semantic would lead to further refactoring which I do not think is needed.

IMO, sort of functional readValueFormatter is good enough. In a follow-up (out of bug-fixing scope) we can merge it with the static addendum if really needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For v2v, it's not editable already

I know, but it could be confusing for someone who looks at this in the future

For other flows, the user is not allowed to enter floating point number to disk size, so effectively the formatting is used in the single relevant case only.

The user can have have templates with custom sizes, that would break this.

If something, we should handle just the STORAGE_TYPE_EXTERNAL_IMPORT case, not the two mentioned.
Recently, component edit mode is disabled when renderConfig is missing. Changing that semantic would lead to further refactoring which I do not think is needed.

IMO, sort of functional readValueFormatter is good enough. In a follow-up (out of bug-fixing scope) we can merge it with the static addendum if really needed.

You are right - I forgot about that one.

So it probably should be (STORAGE_TYPE_EXTERNAL_V2V_TEMP, STORAGE_TYPE_EXTERNAL_IMPORT), because there is fixed size for both of them.

We could switch the behaviour in readValueFormatter if one of these two types is detected:

Or rename renderConfig to renderEditConfig and create renderValueConfig for more generic approach. This could be a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the design suggestion bellow and what is stated here, I have added renderValueConfig, so far containing just single formatter optional prop.

Semantics of the renderConfig() is unchanged but renamed to renderEditConfig().

Size-cells of listed storage types contain always unit.

There's a gap in edit-mode - the unit is not rendered. But the user can get this information within the read-mode. Will be improved when moved to PF4 tables.

@@ -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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is overly complicated IMO. I think we should pass the size here with the unit already or pass just the bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't hardcode to Gi here since i.e. size equal to 1KiB does not match the required pattern.

We can either convert to a reasonable unit or use bytes in all cases.

As I already use this conversion for rendering, I think it's nice to keep it here as well. Just for better readability and debugging of the result. But I do not strongly insist on keeping it, just like it.

Copy link
Contributor

@atiratree atiratree May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/k8s/objects/pvc/pvc.js should be pretty generic. I would rather send size and unit from above to here.

And would rather include the conversion here in src/k8s/requests/v2v/importVmware.js:

const extImportPvcsPromises = storages.filter(isImportStorage).map(storage =>
    k8sCreate(
      PersistentVolumeClaimModel,
      buildPvc({
        ...storage,
        generateName: storage.name,
        name: undefined,
        namespace,
        units,
      })
    )
  );

where it is clear because of the import storage type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, moved one layer up

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather implement this with addendum approach or combine these approaches altogether (addendum with functional approach). So we don't have two approaches for the similar thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's very similar, the formatter can just do more things than just appending a string.

For flexibility, I am more for the functional approach but refactoring of the addendum is not feasible for the 2.0.0 scope. Can be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If implemented using static addendum, the logic would need to be moved to a higher level while affecting other flows and so potentially introducing new bugs. So I decided to go this safer way.

One more idea: we can keep using addendum as it is and optionally assigning a function to it (instead of recent string). The EdditableDraggableTable would check it's type and act accordingly. But such reusing of single property for two different types introduces more confusion, imo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can leave this for later. Can you please create an issue to unify these two approaches?

Yes better to rewrite it without any magic and use just the functional approach.

k8sCreate,
k8sPatch,
},
units
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass this as a object for better enhancement. { units } ?

I guess we should have begin with the object parameters to begin with (maybe TODO for refactoring?).

Only this have to be left the same (because of future possibility of passing EnhancedK8sMethods):

{
        k8sCreate,
        k8sPatch,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sidenote: this should be pretty easy to do with the new VM dialog refactoring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know.
I think its a "nice to have" even for 2.0.0 which will not contain the refactoring.

Anyway, it's of lower priority since there is a workaround possible (by deleting role, rolebinding and the service account).

@mareklibra mareklibra force-pushed the v2v.bz1708195.diskSize branch from 613964b to bfb5eac Compare May 15, 2019 13:46
@andybraren
Copy link

@mareklibra Here's a rough mockup of one idea that attaches a unit dropdown to the text field. The dropdown would default to Gi, but could be changed to Ki or Ti. The Size column title would no longer have (Gi). FYI @matthewcarleton

1-6-1-storage-create

This combined field is used when creating a PVC in the Console - maybe some of that code could be reused? Here's an old screenshot I took from OpenShift Console #1209 (ignore the incorrect units) that shows the combined field in action:

53191270-64649700-35d9-11e9-8a84-b09f9b505801

@atiratree
Copy link
Contributor

@mareklibra Here's a rough mockup of one idea that attaches a unit dropdown to the text field. The dropdown would default to Gi, but could be changed to Ki or Ti. The Size column title would no longer have (Gi).

We are planning to do something like this, but this will be much easier once we convert to pf4 tables - so I think it is postponed until then.

This combined field is used when creating a PVC in the Console - maybe some of that code could be reused? Here's an old screenshot I took from OpenShift Console #1209 (ignore the incorrect units) that shows the combined field in action:

this piece is not really reusable currently - we can work on that once we get merged into openshift/console IMO

@andybraren
Copy link

Hmm, I guess a short-term solution would be to:

  • Remove (Gi) from the Size column header
  • Use Ki within the cell when necessary for v2v
  • Put Gi to the right of the text input for editable disks, and the string becomes 10 Gi when not in edit mode

Would this work for now?

1-6-1-storage-create

@atiratree
Copy link
Contributor

Would this work for now?

+1 this sounds reasonable

@mareklibra
Copy link
Contributor Author

Would this work for now?

Yes, thanks

To be consistent with the newly introduced `rederValueConfig()`
Let's keep using "Gi" as the base unit.
In a later version, we will implement proper unit-selector.
@atiratree atiratree merged commit 40fb63e into kubevirt:master May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants