cdk8s-team/cdk8s-plus

PVC in cdk8s+ rejects storage non-gibibyte constraints

TrueGoric opened this issue · 1 comments

Description of the bug:

While specifying storage requests for PersistentVolumeClaim in cdk8s-plus-26 the application throws an error if the value cannot be rounded to gibibytes.

Reproduction Steps:

const pvc = new PersistentVolumeClaim(this, 'pvc', {
    accessModes: [
        PersistentVolumeAccessMode.READ_WRITE_ONCE
    ],
    storage: Size.mebibytes(1)
});

Error Log:

/projdir/node_modules/cdk8s/lib/size.js:134
                throw new Error(`'${amount} ${fromUnit}' cannot be converted into a whole number of ${toUnit}.`);
                ^

Error: '1 mebibytes' cannot be converted into a whole number of gibibytes.
    at convert (/projdir/node_modules/cdk8s/lib/size.js:134:23)

Environment:

  • Framework Version: cdk8s - 2.7.43, cdk8s-plus-26 - 2.2.10
  • OS: Fedora 38

Other:

It seems PersistentVolumeClaim._toKube() forces the conversion (src/pvc.ts, line 200):

    const storage = this.storage ? k8s.Quantity.fromString(this.storage.toGibibytes() + 'Gi') : undefined;

I wanted to submit a PR, but it turns out that Size class doesn't expose the necessary APIs (which I guess was the reason this conversion).


This is a 🐛 Bug Report

This issue has not received any attention in 1 year and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.