@@ -9,6 +9,7 @@ package v1
9
9
import (
10
10
"fmt"
11
11
"reflect"
12
+ "strconv"
12
13
13
14
"regexp"
14
15
@@ -17,6 +18,7 @@ import (
17
18
"inet.af/netaddr"
18
19
corev1 "k8s.io/api/core/v1"
19
20
networkingv1 "k8s.io/api/networking/v1"
21
+ "k8s.io/apimachinery/pkg/api/resource"
20
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
23
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
22
24
"k8s.io/apimachinery/pkg/runtime"
@@ -50,6 +52,8 @@ const (
50
52
BackupConfigLabelName string = "postgres.database.fits.cloud/is-backup"
51
53
// BackupConfigKey defines the key under which the BackupConfig is stored in the data map.
52
54
BackupConfigKey = "config"
55
+ // SharedBufferParameterKey defines the key under which the shared buffer size is stored in the parameters map. Defined by the postgres-operator/patroni
56
+ SharedBufferParameterKey = "shared_buffer"
53
57
)
54
58
55
59
var (
@@ -401,8 +405,8 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
401
405
402
406
z .Spec .NumberOfInstances = p .Spec .NumberOfInstances
403
407
z .Spec .PostgresqlParam .PgVersion = p .Spec .Version
404
- // TODO set shared_buffer from p .Spec.Size.SharedBuffer
405
- // z.Spec.PostgresqlParam.Parameters = map[string]string{}
408
+ z .Spec .PostgresqlParam . Parameters = map [ string ] string {}
409
+ setSharedBufferSize ( z .Spec .PostgresqlParam .Parameters , p . Spec . Size . SharedBuffer )
406
410
z .Spec .Resources .ResourceRequests .CPU = p .Spec .Size .CPU
407
411
z .Spec .Resources .ResourceRequests .Memory = p .Spec .Size .Memory
408
412
z .Spec .Resources .ResourceLimits .CPU = p .Spec .Size .CPU
@@ -542,3 +546,18 @@ func (p *Postgres) buildSidecars(c *corev1.ConfigMap) []zalando.Sidecar {
542
546
543
547
return sidecars
544
548
}
549
+
550
+ // setSharedBufferSize converts and, if valid, sets the shared_buffer parameter in the given map.
551
+ func setSharedBufferSize (parameters map [string ]string , shmSize string ) {
552
+ // First step is to convert the string back to a quantity
553
+ size , err := resource .ParseQuantity (shmSize )
554
+ if err == nil {
555
+ // if successful, get the given shared buffer size in bytes.
556
+ sizeInBytes , ok := size .AsInt64 ()
557
+ if ok && sizeInBytes >= (32 * 1024 * 1024 ) {
558
+ // if more than 32Mi (our minimum value), convert the value to MB as required by postgres (although the docs are not very specific about that)
559
+ sizeInMB := sizeInBytes / (1024 * 1024 )
560
+ parameters [SharedBufferParameterKey ] = strconv .FormatInt (sizeInMB , 10 ) + "MB"
561
+ }
562
+ }
563
+ }
0 commit comments