Skip to content

Commit 33a7041

Browse files
committed
Add hugepages-2Mi and 1Gi to ResourceDescription type and crd (#1549, #1788)
1 parent af084a5 commit 33a7041

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

manifests/minimal-postgres-manifest.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ spec:
1414
foo_user: [] # role for application foo
1515
databases:
1616
foo: zalando # dbname: owner
17+
resources:
18+
limits:
19+
hugepages-2Mi: 250Mi
20+
memory: 250Mi
1721
preparedDatabases:
1822
bar: {}
1923
postgresql:

manifests/postgresql.crd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ spec:
439439
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
440440
# Note: the value specified here must not be zero or be higher
441441
# than the corresponding limit.
442+
hugepages-2Mi:
443+
type: string
444+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
445+
hugepages-1Gi:
446+
type: string
447+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
442448
requests:
443449
type: object
444450
properties:
@@ -448,6 +454,12 @@ spec:
448454
memory:
449455
type: string
450456
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
457+
hugepages-2Mi:
458+
type: string
459+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
460+
hugepages-1Gi:
461+
type: string
462+
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
451463
schedulerName:
452464
type: string
453465
serviceAnnotations:

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package v1
33
import (
44
"fmt"
55

6-
acidzalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
7-
"github.com/zalando/postgres-operator/pkg/util"
86
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
97
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
9+
acidzalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
10+
"github.com/zalando/postgres-operator/pkg/util"
1011
)
1112

1213
// CRDResource* define names necesssary for the k8s CRD API
@@ -684,6 +685,14 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
684685
Type: "string",
685686
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
686687
},
688+
"hugepages-2Mi": {
689+
Type: "string",
690+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
691+
},
692+
"hugepages-1Gi": {
693+
Type: "string",
694+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
695+
},
687696
},
688697
},
689698
"requests": {
@@ -697,6 +706,14 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
697706
Type: "string",
698707
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
699708
},
709+
"hugepages-2Mi": {
710+
Type: "string",
711+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
712+
},
713+
"hugepages-1Gi": {
714+
Type: "string",
715+
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
716+
},
700717
},
701718
},
702719
},

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ type PostgresqlParam struct {
153153

154154
// ResourceDescription describes CPU and memory resources defined for a cluster.
155155
type ResourceDescription struct {
156-
CPU string `json:"cpu"`
157-
Memory string `json:"memory"`
156+
CPU string `json:"cpu"`
157+
Memory string `json:"memory"`
158+
HugePages2Mi string `json:"hugepages-2Mi"`
159+
HugePages1Gi string `json:"hugepages-1Gi"`
158160
}
159161

160162
// Resources describes requests and limits for the cluster resouces.

pkg/cluster/k8sres.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"k8s.io/apimachinery/pkg/types"
2121
"k8s.io/apimachinery/pkg/util/intstr"
2222

23+
"golang.org/x/exp/maps"
24+
batchv1 "k8s.io/api/batch/v1"
25+
"k8s.io/apimachinery/pkg/labels"
26+
2327
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
2428
"github.com/zalando/postgres-operator/pkg/spec"
2529
"github.com/zalando/postgres-operator/pkg/util"
@@ -28,9 +32,6 @@ import (
2832
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
2933
"github.com/zalando/postgres-operator/pkg/util/patroni"
3034
"github.com/zalando/postgres-operator/pkg/util/retryutil"
31-
"golang.org/x/exp/maps"
32-
batchv1 "k8s.io/api/batch/v1"
33-
"k8s.io/apimachinery/pkg/labels"
3435
)
3536

3637
const (
@@ -267,6 +268,19 @@ func fillResourceList(spec acidv1.ResourceDescription, defaults acidv1.ResourceD
267268
}
268269
}
269270

271+
if spec.HugePages2Mi != "" {
272+
requests[v1.ResourceHugePagesPrefix+"1Mi"], err = resource.ParseQuantity(spec.HugePages2Mi)
273+
if err != nil {
274+
return nil, fmt.Errorf("could not parse hugepages-2Mi quantity: %v", err)
275+
}
276+
}
277+
if spec.HugePages1Gi != "" {
278+
requests[v1.ResourceHugePagesPrefix+"1Gi"], err = resource.ParseQuantity(spec.HugePages1Gi)
279+
if err != nil {
280+
return nil, fmt.Errorf("could not parse hugepages-1Gi quantity: %v", err)
281+
}
282+
}
283+
270284
return requests, nil
271285
}
272286

0 commit comments

Comments
 (0)