Skip to content

Commit b076535

Browse files
committed
behavior updates, in progress
1 parent 88ed7e1 commit b076535

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11630,6 +11630,28 @@ spec:
1163011630
format: int32
1163111631
minimum: 3
1163211632
type: integer
11633+
log:
11634+
description: Patroni log configuration settings.
11635+
properties:
11636+
fileSize:
11637+
description: Patroni Log file size
11638+
type: string
11639+
logLevel:
11640+
default: INFO
11641+
description: |-
11642+
Patroni log level
11643+
https://docs.python.org/3.6/library/logging.html#levels
11644+
enum:
11645+
- CRITICAL
11646+
- ERROR
11647+
- WARNING
11648+
- INFO
11649+
- DEBUG
11650+
- NOTSET
11651+
type: string
11652+
required:
11653+
- fileSize
11654+
type: object
1163311655
port:
1163411656
default: 8008
1163511657
description: |-

internal/patroni/config.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
corev1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/api/resource"
1314
"sigs.k8s.io/yaml"
1415

1516
"github.com/crunchydata/postgres-operator/internal/config"
@@ -50,17 +51,6 @@ func clusterYAML(
5051
// lifetime.
5152
"scope": naming.PatroniScope(cluster),
5253

53-
// Configure the Patroni log path directory
54-
// - https://patroni.readthedocs.io/en/latest/yaml_configuration.html#log
55-
//
56-
// Setting file_size to 0 means that there will be no rollover.
57-
// - https://github.com/patroni/patroni/blob/v3.3.4/patroni/log.py#L431-L432
58-
// - https://docs.python.org/3.11/library/logging.handlers.html#rotatingfilehandler
59-
"log": map[string]any{
60-
"dir": naming.PatroniPGDataLogPath,
61-
"file_size": 0,
62-
},
63-
6454
// Use Kubernetes Endpoints for the distributed configuration store (DCS).
6555
// These values cannot change during the cluster's lifetime.
6656
//
@@ -163,6 +153,31 @@ func clusterYAML(
163153
},
164154
}
165155

156+
if cluster.Spec.Patroni != nil {
157+
if cluster.Spec.Patroni.Log != nil {
158+
159+
fileSize, err := resource.ParseQuantity(*cluster.Spec.Patroni.Log.FileSize)
160+
sizeInBytes := fileSize.Value()
161+
162+
// TODO: This isn't how I want to handle this, figure something better out...
163+
if err != nil {
164+
fmt.Printf("Bad Patroni log file size given, using 25MB instead, error: %v\n", err)
165+
sizeInBytes = 25000000 // Patroni's default size
166+
}
167+
168+
root["log"] = map[string]any{
169+
// Configure the Patroni log settings
170+
// - https://patroni.readthedocs.io/en/latest/yaml_configuration.html#log
171+
"dir": naming.PatroniPGDataLogPath,
172+
"file_num": 1,
173+
"file_size": sizeInBytes,
174+
"type": "json",
175+
"level": cluster.Spec.Patroni.Log.LogLevel, // defaults to "INFO"
176+
}
177+
178+
}
179+
}
180+
166181
if !ClusterBootstrapped(cluster) {
167182
// Patroni has not yet bootstrapped. Populate the "bootstrap.dcs" field to
168183
// facilitate it. When Patroni is already bootstrapped, this field is ignored.

pkg/apis/postgres-operator.crunchydata.com/v1beta1/patroni_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ type PatroniSpec struct {
2323
// +kubebuilder:validation:Minimum=3
2424
LeaderLeaseDurationSeconds *int32 `json:"leaderLeaseDurationSeconds,omitempty"`
2525

26+
// Patroni log configuration settings.
27+
// +optional
28+
Log *PatroniLogConfig `json:"log,omitempty"`
29+
2630
// The port on which Patroni should listen.
2731
// Changing this value causes PostgreSQL to restart.
2832
// +optional
@@ -48,6 +52,21 @@ type PatroniSpec struct {
4852
// - https://patroni.readthedocs.io/en/latest/kubernetes.html
4953
}
5054

55+
type PatroniLogConfig struct {
56+
57+
// Patroni Log file size
58+
// https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
59+
// +required
60+
FileSize *string `json:"fileSize"`
61+
62+
// Patroni log level
63+
// https://docs.python.org/3.6/library/logging.html#levels
64+
// +kubebuilder:validation:Enum={CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
65+
// +kubebuilder:default:=INFO
66+
// +optional
67+
LogLevel *string `json:"logLevel,omitempty"`
68+
}
69+
5170
type PatroniSwitchover struct {
5271

5372
// Whether or not the operator should allow switchovers in a PostgresCluster

pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)