Bug 1293836 - Wrong RegEx when create quota with minus
Summary: Wrong RegEx when create quota with minus
Keywords:
Status: CLOSED EOL
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: unspecified
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: ---
: ---
Assignee: Derek Carr
QA Contact: Qingyu Wang
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-12-23 09:10 UTC by Qixuan Wang
Modified: 2020-02-26 19:11 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-02-26 19:11:09 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Qixuan Wang 2015-12-23 09:10:37 UTC
Description of problem:
Create quota with negative number, the regular expression '^([+-]?[0-9.]+)([eEimkKMGTP]*[-+]?[0-9]*)$' " which includes negative number.

Version-Release number of selected component (if applicable):
openshift v1.1-428-ged29520
kubernetes v1.1.0-origin-1107-g4c8e6f4
etcd 2.1.2

How reproducible:
Always

Steps to Reproduce:
1.Create quota with minus
$ cat negquota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: negquota
spec:
  hard:
    cpu: "-20"
    memory: “-1Gi“
    persistentvolumeclaims: "-10"
    pods: "-10"
    replicationcontrollers: "-20"
    resourcequotas: "-2"
    secrets: "-10"
    services: "-5"

$ oc create -f negquota.yaml -n qwangp --config=/home/fedora/openshift.local.config/master/admin.kubeconfig


Actual results:
1. [root@ip-172-18-14-187 fedora]# oc create -f negquota.yaml -n qwangp --config=/home/fedora/openshift.local.config/master/admin.kubeconfig 
unable to load "negquota.yaml": quantities must match the regular expression '^([+-]?[0-9.]+)([eEimkKMGTP]*[-+]?[0-9]*)$' 


Expected results:
1. The message should like "xxx must be non-negative"

Additional info:

Comment 1 Derek Carr 2016-01-04 19:51:07 UTC
The server is correctly validating that the incoming value conforms to the Kube syntax for compute resources.  Since the regex is used to validate the incoming object before it's actually parsed, I am not sure I see a huge value in updating the code to special case the check for negative values versus just stating the value does not match the regex.

Moving to low priority.

Comment 2 Qixuan Wang 2016-08-03 06:32:59 UTC
Tested on OSE3.3(openshift v3.3.0.13, kubernetes v1.3.0+57fb9ac, etcd2.3.0+git), the problem has gone.

[root@dhcp-141-95 testv3]# oc create -f negquota.yaml -n qwang1 --config=/home/qwang/admin.kubeconfig 
The ResourceQuota "negquota" is invalid.

* spec.hard[pods]: Invalid value: "-10": must be greater than or equal to 0
* spec.hard[replicationcontrollers]: Invalid value: "-20": must be greater than or equal to 0
* spec.hard[resourcequotas]: Invalid value: "-2": must be greater than or equal to 0
* spec.hard[secrets]: Invalid value: "-10": must be greater than or equal to 0
* spec.hard[services]: Invalid value: "-5": must be greater than or equal to 0
* spec.hard[cpu]: Invalid value: "-20": must be greater than or equal to 0
* spec.hard[memory]: Invalid value: "-1Gi": must be greater than or equal to 0
* spec.hard[persistentvolumeclaims]: Invalid value: "-10": must be greater than or equal to 0

Comment 3 Qixuan Wang 2016-08-03 06:59:54 UTC
Fractional numbers, decimals, negative numbers can match the RegEx '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'

[root@dhcp-141-95 testv3]# cat quota-2.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: quota-2
spec:
  hard:
    cpu: "2/10"
    memory: "1/5Gi"
    persistentvolumeclaims: "1/10"
    pods: "1/10"
    replicationcontrollers: "2/10"
    resourcequotas: "3/10"
    secrets: "5/10"
    services: "5/10"

[root@dhcp-141-95 testv3]# oc create -f quota-3.yaml -n qwang1 --config=/home/qwang/admin.kubeconfig 
unable to decode "quota-3.yaml": quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'


Note You need to log in before you can comment on or make changes to this bug.