diff --git a/deploy/crds/vms-crd.yaml b/deploy/crds/vms-crd.yaml index 406a5cf..b40dc8c 100644 --- a/deploy/crds/vms-crd.yaml +++ b/deploy/crds/vms-crd.yaml @@ -62,7 +62,7 @@ spec: anyOf: - type: integer - type: string - pattern: ^\s*(\d+(\.\d+)?)\s*(B|kB|MB|GB|TB|PB|EB|KiB|MiB|GiB|TiB|PiB|EiB|Ki|Mi|Gi|Ti|Pi|Ei)?$ + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true description: >- Limits describes the maximum amount of compute @@ -73,7 +73,7 @@ spec: anyOf: - type: integer - type: string - pattern: ^\s*(\d+(\.\d+)?)\s*(B|kB|MB|GB|TB|PB|EB|KiB|MiB|GiB|TiB|PiB|EiB|Ki|Mi|Gi|Ti|Pi|Ei)?$ + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true description: >- Requests describes the minimum amount of compute diff --git a/dev-example/test-vm.yaml b/dev-example/test-vm.yaml index d3f4123..a60ef59 100644 --- a/dev-example/test-vm.yaml +++ b/dev-example/test-vm.yaml @@ -17,8 +17,8 @@ spec: vm: # state: Running bootMenu: yes - maximumRam: "8 GiB" - currentRam: "4 GiB" + maximumRam: 8Gi + currentRam: 4Gi maximumCpus: 4 currentCpus: 4 diff --git a/example/local-path/test-vm.yaml b/example/local-path/test-vm.yaml index c6f3011..49e22ae 100644 --- a/example/local-path/test-vm.yaml +++ b/example/local-path/test-vm.yaml @@ -15,8 +15,8 @@ spec: vm: maximumCpus: 4 currentCpus: 2 - maximumRam: "8 GiB" - currentRam: "4 GiB" + maximumRam: 8Gi + currentRam: 4Gi networks: - user: {} diff --git a/example/rook-ceph/test-vm.yaml b/example/rook-ceph/test-vm.yaml index 2dc71e0..1222be3 100644 --- a/example/rook-ceph/test-vm.yaml +++ b/example/rook-ceph/test-vm.yaml @@ -15,8 +15,8 @@ spec: vm: maximumCpus: 4 currentCpus: 2 - maximumRam: "8 GiB" - currentRam: "4 GiB" + maximumRam: 8Gi + currentRam: 4Gi networks: - user: {} diff --git a/org.jdrupes.vmoperator.manager/resources/org/jdrupes/vmoperator/manager/runnerSts.ftl.yaml b/org.jdrupes.vmoperator.manager/resources/org/jdrupes/vmoperator/manager/runnerSts.ftl.yaml index f870ae7..053e1c3 100644 --- a/org.jdrupes.vmoperator.manager/resources/org/jdrupes/vmoperator/manager/runnerSts.ftl.yaml +++ b/org.jdrupes.vmoperator.manager/resources/org/jdrupes/vmoperator/manager/runnerSts.ftl.yaml @@ -99,14 +99,14 @@ spec: <#if reconciler.cpuOvercommit??> <#assign factor = reconciler.cpuOvercommit * 1.0 /> - cpu: ${ (cr.spec.vm.currentCpus.asInt / factor)?floor?c } + cpu: ${ (parseQuantity(cr.spec.vm.currentCpus.asString) / factor)?floor?c } <#if cr.spec.vm.currentRam?? > <#assign factor = 1.25 /> <#if reconciler.ramOvercommit??> <#assign factor = reconciler.ramOvercommit * 1.0 /> - memory: ${ (parseMemory(cr.spec.vm.currentRam.asString) / factor)?floor?c } + memory: ${ (parseQuantity(cr.spec.vm.currentRam.asString) / factor)?floor?c } diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java index efba4d4..f135a7e 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Reconciler.java @@ -30,6 +30,7 @@ import freemarker.template.TemplateHashModel; import freemarker.template.TemplateMethodModelEx; import freemarker.template.TemplateModelException; import freemarker.template.TemplateNotFoundException; +import io.kubernetes.client.custom.Quantity; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi; import java.io.IOException; @@ -42,7 +43,6 @@ import java.util.Optional; import static org.jdrupes.vmoperator.manager.Constants.VM_OP_GROUP; import org.jdrupes.vmoperator.manager.VmDefChanged.Type; import org.jdrupes.vmoperator.util.ExtendedObjectWrapper; -import org.jdrupes.vmoperator.util.ParseUtils; import org.jgrapes.core.Channel; import org.jgrapes.core.Component; import org.jgrapes.core.annotation.Handler; @@ -219,7 +219,7 @@ public class Reconciler extends Component { model.put("reconciler", config); // Methods - model.put("parseMemory", new TemplateMethodModelEx() { + model.put("parseQuantity", new TemplateMethodModelEx() { @Override @SuppressWarnings("PMD.PreserveStackTrace") public Object exec(@SuppressWarnings("rawtypes") List arguments) @@ -229,7 +229,7 @@ public class Reconciler extends Component { return number; } try { - return ParseUtils.parseMemory(arg.toString()); + return Quantity.fromString(arg.toString()).getNumber(); } catch (NumberFormatException e) { throw new TemplateModelException("Cannot parse memory " + "specified as \"" + arg + "\": " + e.getMessage());