mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 15:06:49 +02:00
Add hugepages 2Mi and 1Gi fields to ResourceDescription and pass them to the statefulset (#2311)
* Add hugepages-2Mi and 1Gi to ResourceDescription type and crd (#1549, #1788) * Add tests for hugepages resource requests/limits * Add tests for hugepages resource requests/limits on sidecars, too * Add docs for hugepages support * Add link to kubernetes docs on hugepages * Add tests for hugepages not being set on container if not requested in custom resource * Add hugepages resources fields to manifest docs * Add hugepages resources fields to complete manifest example * Add hugepages resources fields to chart crd --------- Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
This commit is contained in:
@@ -3,10 +3,11 @@ package v1
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
acidzalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
acidzalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
)
|
||||
|
||||
// CRDResource* define names necesssary for the k8s CRD API
|
||||
@@ -684,6 +685,14 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
"hugepages-2Mi": {
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
"hugepages-1Gi": {
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
},
|
||||
},
|
||||
"requests": {
|
||||
@@ -697,6 +706,14 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
"hugepages-2Mi": {
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
"hugepages-1Gi": {
|
||||
Type: "string",
|
||||
Pattern: "^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -153,8 +153,10 @@ type PostgresqlParam struct {
|
||||
|
||||
// ResourceDescription describes CPU and memory resources defined for a cluster.
|
||||
type ResourceDescription struct {
|
||||
CPU string `json:"cpu"`
|
||||
Memory string `json:"memory"`
|
||||
CPU string `json:"cpu"`
|
||||
Memory string `json:"memory"`
|
||||
HugePages2Mi string `json:"hugepages-2Mi"`
|
||||
HugePages1Gi string `json:"hugepages-1Gi"`
|
||||
}
|
||||
|
||||
// Resources describes requests and limits for the cluster resouces.
|
||||
|
||||
+17
-3
@@ -20,6 +20,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
"github.com/zalando/postgres-operator/pkg/spec"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
@@ -28,9 +32,6 @@ import (
|
||||
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
||||
"github.com/zalando/postgres-operator/pkg/util/patroni"
|
||||
"github.com/zalando/postgres-operator/pkg/util/retryutil"
|
||||
"golang.org/x/exp/maps"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -266,6 +267,19 @@ func fillResourceList(spec acidv1.ResourceDescription, defaults acidv1.ResourceD
|
||||
}
|
||||
}
|
||||
|
||||
if spec.HugePages2Mi != "" {
|
||||
requests[v1.ResourceHugePagesPrefix+"2Mi"], err = resource.ParseQuantity(spec.HugePages2Mi)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse hugepages-2Mi quantity: %v", err)
|
||||
}
|
||||
}
|
||||
if spec.HugePages1Gi != "" {
|
||||
requests[v1.ResourceHugePagesPrefix+"1Gi"], err = resource.ParseQuantity(spec.HugePages1Gi)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse hugepages-1Gi quantity: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return requests, nil
|
||||
}
|
||||
|
||||
|
||||
+126
-2
@@ -5,9 +5,8 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -3081,6 +3080,131 @@ func TestGenerateResourceRequirements(t *testing.T) {
|
||||
ResourceLimits: acidv1.ResourceDescription{CPU: "1", Memory: "2Gi"},
|
||||
},
|
||||
},
|
||||
{
|
||||
subTest: "test HugePages are not set on container when not requested in manifest",
|
||||
config: config.Config{
|
||||
Resources: configResources,
|
||||
PodManagementPolicy: "ordered_ready",
|
||||
},
|
||||
pgSpec: acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: acidv1.PostgresSpec{
|
||||
Resources: &acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{},
|
||||
ResourceLimits: acidv1.ResourceDescription{},
|
||||
},
|
||||
TeamID: "acid",
|
||||
Volume: acidv1.Volume{
|
||||
Size: "1G",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResources: acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{
|
||||
CPU: "100m",
|
||||
Memory: "100Mi",
|
||||
},
|
||||
ResourceLimits: acidv1.ResourceDescription{
|
||||
CPU: "1",
|
||||
Memory: "500Mi",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
subTest: "test HugePages are passed through to the postgres container",
|
||||
config: config.Config{
|
||||
Resources: configResources,
|
||||
PodManagementPolicy: "ordered_ready",
|
||||
},
|
||||
pgSpec: acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: acidv1.PostgresSpec{
|
||||
Resources: &acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{
|
||||
HugePages2Mi: "128Mi",
|
||||
HugePages1Gi: "1Gi",
|
||||
},
|
||||
ResourceLimits: acidv1.ResourceDescription{
|
||||
HugePages2Mi: "256Mi",
|
||||
HugePages1Gi: "2Gi",
|
||||
},
|
||||
},
|
||||
TeamID: "acid",
|
||||
Volume: acidv1.Volume{
|
||||
Size: "1G",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResources: acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{
|
||||
CPU: "100m",
|
||||
Memory: "100Mi",
|
||||
HugePages2Mi: "128Mi",
|
||||
HugePages1Gi: "1Gi",
|
||||
},
|
||||
ResourceLimits: acidv1.ResourceDescription{
|
||||
CPU: "1",
|
||||
Memory: "500Mi",
|
||||
HugePages2Mi: "256Mi",
|
||||
HugePages1Gi: "2Gi",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
subTest: "test HugePages are passed through on sidecars",
|
||||
config: config.Config{
|
||||
Resources: configResources,
|
||||
PodManagementPolicy: "ordered_ready",
|
||||
},
|
||||
pgSpec: acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: clusterName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: acidv1.PostgresSpec{
|
||||
Sidecars: []acidv1.Sidecar{
|
||||
{
|
||||
Name: "test-sidecar",
|
||||
DockerImage: "test-image",
|
||||
Resources: &acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{
|
||||
HugePages2Mi: "128Mi",
|
||||
HugePages1Gi: "1Gi",
|
||||
},
|
||||
ResourceLimits: acidv1.ResourceDescription{
|
||||
HugePages2Mi: "256Mi",
|
||||
HugePages1Gi: "2Gi",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TeamID: "acid",
|
||||
Volume: acidv1.Volume{
|
||||
Size: "1G",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedResources: acidv1.Resources{
|
||||
ResourceRequests: acidv1.ResourceDescription{
|
||||
CPU: "100m",
|
||||
Memory: "100Mi",
|
||||
HugePages2Mi: "128Mi",
|
||||
HugePages1Gi: "1Gi",
|
||||
},
|
||||
ResourceLimits: acidv1.ResourceDescription{
|
||||
CPU: "1",
|
||||
Memory: "500Mi",
|
||||
HugePages2Mi: "256Mi",
|
||||
HugePages1Gi: "2Gi",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user