Skip to content

Commit f5e122e

Browse files
authored
Fix resource constraints (zalando#2735)
* Add empty string cases to patterns for pod resources * Added empty strings test case * Restored k8sres.go and changed test to zeros * Updated validation pattern in manifests/operatorconfiguration.crd.yaml and pkg/apis/acid.zalan.do/v1/crds.go
1 parent d21466d commit f5e122e

File tree

4 files changed

+62
-24
lines changed

4 files changed

+62
-24
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,28 @@ spec:
376376
properties:
377377
default_cpu_limit:
378378
type: string
379-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
379+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
380380
default_cpu_request:
381381
type: string
382-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
382+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
383383
default_memory_limit:
384384
type: string
385-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
385+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
386386
default_memory_request:
387387
type: string
388-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
388+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
389389
max_cpu_request:
390390
type: string
391-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
391+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
392392
max_memory_request:
393393
type: string
394-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
394+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
395395
min_cpu_limit:
396396
type: string
397-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
397+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
398398
min_memory_limit:
399399
type: string
400-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
400+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
401401
timeouts:
402402
type: object
403403
properties:

manifests/operatorconfiguration.crd.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,28 +374,28 @@ spec:
374374
properties:
375375
default_cpu_limit:
376376
type: string
377-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
377+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
378378
default_cpu_request:
379379
type: string
380-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
380+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
381381
default_memory_limit:
382382
type: string
383-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
383+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
384384
default_memory_request:
385385
type: string
386-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
386+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
387387
max_cpu_request:
388388
type: string
389-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
389+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
390390
max_memory_request:
391391
type: string
392-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
392+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
393393
min_cpu_limit:
394394
type: string
395-
pattern: '^(\d+m|\d+(\.\d{1,3})?)$'
395+
pattern: '^(\d+m|\d+(\.\d{1,3})?)$|^$'
396396
min_memory_limit:
397397
type: string
398-
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
398+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$|^$'
399399
timeouts:
400400
type: object
401401
properties:

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,35 +1573,35 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
15731573
Properties: map[string]apiextv1.JSONSchemaProps{
15741574
"default_cpu_limit": {
15751575
Type: "string",
1576-
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1576+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$|^$",
15771577
},
15781578
"default_cpu_request": {
15791579
Type: "string",
1580-
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1580+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$|^$",
15811581
},
15821582
"default_memory_limit": {
15831583
Type: "string",
1584-
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1584+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$|^$",
15851585
},
15861586
"default_memory_request": {
15871587
Type: "string",
1588-
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1588+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$|^$",
15891589
},
15901590
"max_cpu_request": {
15911591
Type: "string",
1592-
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1592+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$|^$",
15931593
},
15941594
"max_memory_request": {
15951595
Type: "string",
1596-
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1596+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$|^$",
15971597
},
15981598
"min_cpu_limit": {
15991599
Type: "string",
1600-
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$",
1600+
Pattern: "^(\\d+m|\\d+(\\.\\d{1,3})?)$|^$",
16011601
},
16021602
"min_memory_limit": {
16031603
Type: "string",
1604-
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
1604+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$|^$",
16051605
},
16061606
},
16071607
},

pkg/cluster/k8sres_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,44 @@ func TestGenerateResourceRequirements(t *testing.T) {
29932993
ResourceRequests: acidv1.ResourceDescription{CPU: k8sutil.StringToPointer("100m"), Memory: k8sutil.StringToPointer("100Mi")},
29942994
},
29952995
},
2996+
{
2997+
subTest: "test generation of resources when min limits are all set to zero",
2998+
config: config.Config{
2999+
Resources: config.Resources{
3000+
ClusterLabels: map[string]string{"application": "spilo"},
3001+
ClusterNameLabel: clusterNameLabel,
3002+
DefaultCPURequest: "0",
3003+
DefaultCPULimit: "0",
3004+
MaxCPURequest: "0",
3005+
MinCPULimit: "0",
3006+
DefaultMemoryRequest: "0",
3007+
DefaultMemoryLimit: "0",
3008+
MaxMemoryRequest: "0",
3009+
MinMemoryLimit: "0",
3010+
PodRoleLabel: "spilo-role",
3011+
},
3012+
PodManagementPolicy: "ordered_ready",
3013+
SetMemoryRequestToLimit: false,
3014+
},
3015+
pgSpec: acidv1.Postgresql{
3016+
ObjectMeta: metav1.ObjectMeta{
3017+
Name: clusterName,
3018+
Namespace: namespace,
3019+
},
3020+
Spec: acidv1.PostgresSpec{
3021+
Resources: &acidv1.Resources{
3022+
ResourceLimits: acidv1.ResourceDescription{CPU: k8sutil.StringToPointer("5m"), Memory: k8sutil.StringToPointer("5Mi")},
3023+
},
3024+
TeamID: "acid",
3025+
Volume: acidv1.Volume{
3026+
Size: "1G",
3027+
},
3028+
},
3029+
},
3030+
expectedResources: acidv1.Resources{
3031+
ResourceLimits: acidv1.ResourceDescription{CPU: k8sutil.StringToPointer("5m"), Memory: k8sutil.StringToPointer("5Mi")},
3032+
},
3033+
},
29963034
{
29973035
subTest: "test matchLimitsWithRequestsIfSmaller",
29983036
config: config.Config{

0 commit comments

Comments
 (0)