Skip to content

Commit 087104c

Browse files
committed
Adds the 'environment' Field to the PostgresCluster Spec
An 'environment' field is now available within the PostgresCluster spec, which allows the user to specify the infrastructure and/or stage in development the PostgresCluster is associated with. Accepted values for this field are 'production' and 'development'. 'production' is the default. Additionally, a CEL validation rule has been added to the CRD that requires backups to be configured for 'production' PostgresCluster's. This change is fully backward compatible and non-breaking with existing PostgresCluster specs. Issue: PGO-1645
1 parent c50a3fe commit 087104c

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7599,6 +7599,19 @@ spec:
75997599
scheduling constraints will be used in addition to any custom constraints
76007600
provided.
76017601
type: boolean
7602+
environment:
7603+
default: production
7604+
description: |-
7605+
Environment allows PGO to adapt its behavior according to the specific infrastructure
7606+
and/or stage of development the PostgresCluster is associated with. This includes
7607+
requiring and/or loosening the requirements for certain components and settings, while
7608+
also providing deeper insights, events and status that more closely align with
7609+
PostgresCluster's intended use.
7610+
Defaults to “production”. Acceptable values are "development" and "production".
7611+
enum:
7612+
- production
7613+
- development
7614+
type: string
76027615
image:
76037616
description: |-
76047617
The image name to use for PostgreSQL containers. When omitted, the value
@@ -16874,6 +16887,10 @@ spec:
1687416887
- instances
1687516888
- postgresVersion
1687616889
type: object
16890+
x-kubernetes-validations:
16891+
- message: Backups must be enabled for production PostgresCluster's.
16892+
rule: '(self.environment == ''production'') ? self.backups.pgbackrest
16893+
!= null : true'
1687716894
status:
1687816895
description: PostgresClusterStatus defines the observed state of PostgresCluster
1687916896
properties:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ spec:
4343
pgbackrest:
4444
repos: null
4545
config: {}
46+
environment: production
4647
instances: null
4748
patroni:
4849
leaderLeaseDurationSeconds: 30
@@ -76,6 +77,7 @@ spec:
7677
pgbackrest:
7778
repos: null
7879
config: {}
80+
environment: production
7981
instances:
8082
- dataVolumeClaimSpec:
8183
resources: {}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
// PostgresClusterSpec defines the desired state of PostgresCluster
16+
// +kubebuilder:validation:XValidation:rule="(self.environment == 'production') ? self.backups.pgbackrest != null : true", message="Backups must be enabled for production PostgresCluster's."
1617
type PostgresClusterSpec struct {
1718
// +optional
1819
Metadata *Metadata `json:"metadata,omitempty"`
@@ -58,6 +59,17 @@ type PostgresClusterSpec struct {
5859
// +optional
5960
DisableDefaultPodScheduling *bool `json:"disableDefaultPodScheduling,omitempty"`
6061

62+
// Environment allows PGO to adapt its behavior according to the specific infrastructure
63+
// and/or stage of development the PostgresCluster is associated with. This includes
64+
// requiring and/or loosening the requirements for certain components and settings, while
65+
// also providing deeper insights, events and status that more closely align with
66+
// PostgresCluster's intended use.
67+
// Defaults to “production”. Acceptable values are "development" and "production".
68+
// +kubebuilder:validation:Enum={production,development}
69+
// +kubebuilder:default=production
70+
// +optional
71+
Environment *string `json:"environment,"`
72+
6173
// The image name to use for PostgreSQL containers. When omitted, the value
6274
// comes from an operator environment variable. For standard PostgreSQL images,
6375
// the format is RELATED_IMAGE_POSTGRES_{postgresVersion},
@@ -305,6 +317,11 @@ func (s *PostgresClusterSpec) Default() {
305317
if s.UserInterface != nil {
306318
s.UserInterface.Default()
307319
}
320+
321+
if s.Environment == nil {
322+
s.Environment = new(string)
323+
*s.Environment = "production"
324+
}
308325
}
309326

310327
// Backups defines a PostgreSQL archive configuration

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

Lines changed: 5 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)