Skip to content

Commit

Permalink
behavior updates, in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmoore4 committed Dec 11, 2024
1 parent 88ed7e1 commit b076535
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11630,6 +11630,28 @@ spec:
format: int32
minimum: 3
type: integer
log:
description: Patroni log configuration settings.
properties:
fileSize:
description: Patroni Log file size
type: string
logLevel:
default: INFO
description: |-
Patroni log level
https://docs.python.org/3.6/library/logging.html#levels
enum:
- CRITICAL
- ERROR
- WARNING
- INFO
- DEBUG
- NOTSET
type: string
required:
- fileSize
type: object
port:
default: 8008
description: |-
Expand Down
37 changes: 26 additions & 11 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/yaml"

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

// Configure the Patroni log path directory
// - https://patroni.readthedocs.io/en/latest/yaml_configuration.html#log
//
// Setting file_size to 0 means that there will be no rollover.
// - https://github.com/patroni/patroni/blob/v3.3.4/patroni/log.py#L431-L432
// - https://docs.python.org/3.11/library/logging.handlers.html#rotatingfilehandler
"log": map[string]any{
"dir": naming.PatroniPGDataLogPath,
"file_size": 0,
},

// Use Kubernetes Endpoints for the distributed configuration store (DCS).
// These values cannot change during the cluster's lifetime.
//
Expand Down Expand Up @@ -163,6 +153,31 @@ func clusterYAML(
},
}

if cluster.Spec.Patroni != nil {
if cluster.Spec.Patroni.Log != nil {

fileSize, err := resource.ParseQuantity(*cluster.Spec.Patroni.Log.FileSize)
sizeInBytes := fileSize.Value()

// TODO: This isn't how I want to handle this, figure something better out...
if err != nil {
fmt.Printf("Bad Patroni log file size given, using 25MB instead, error: %v\n", err)
sizeInBytes = 25000000 // Patroni's default size
}

root["log"] = map[string]any{
// Configure the Patroni log settings
// - https://patroni.readthedocs.io/en/latest/yaml_configuration.html#log
"dir": naming.PatroniPGDataLogPath,
"file_num": 1,
"file_size": sizeInBytes,
"type": "json",
"level": cluster.Spec.Patroni.Log.LogLevel, // defaults to "INFO"
}

}
}

if !ClusterBootstrapped(cluster) {
// Patroni has not yet bootstrapped. Populate the "bootstrap.dcs" field to
// facilitate it. When Patroni is already bootstrapped, this field is ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type PatroniSpec struct {
// +kubebuilder:validation:Minimum=3
LeaderLeaseDurationSeconds *int32 `json:"leaderLeaseDurationSeconds,omitempty"`

// Patroni log configuration settings.
// +optional
Log *PatroniLogConfig `json:"log,omitempty"`

// The port on which Patroni should listen.
// Changing this value causes PostgreSQL to restart.
// +optional
Expand All @@ -48,6 +52,21 @@ type PatroniSpec struct {
// - https://patroni.readthedocs.io/en/latest/kubernetes.html
}

type PatroniLogConfig struct {

// Patroni Log file size
// https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
// +required
FileSize *string `json:"fileSize"`

// Patroni log level
// https://docs.python.org/3.6/library/logging.html#levels
// +kubebuilder:validation:Enum={CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}
// +kubebuilder:default:=INFO
// +optional
LogLevel *string `json:"logLevel,omitempty"`
}

type PatroniSwitchover struct {

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b076535

Please sign in to comment.