-
Notifications
You must be signed in to change notification settings - Fork 611
Adds the 'environment' Field to the PostgresCluster Spec #3993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a22d726
a995cdd
ccdcaa4
e0fb9bd
049007c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
) | ||
|
||
// PostgresClusterSpec defines the desired state of PostgresCluster | ||
// +kubebuilder:validation:XValidation:rule="(self.environment == 'production') ? self.backups.pgbackrest != null : true", message="Backups must be enabled for production PostgresCluster's." | ||
type PostgresClusterSpec struct { | ||
// +optional | ||
Metadata *Metadata `json:"metadata,omitempty"` | ||
|
@@ -58,6 +59,17 @@ type PostgresClusterSpec struct { | |
// +optional | ||
DisableDefaultPodScheduling *bool `json:"disableDefaultPodScheduling,omitempty"` | ||
|
||
// Environment allows PGO to adapt its behavior according to the specific infrastructure | ||
// and/or stage of development the PostgresCluster is associated with. This includes | ||
// requiring and/or loosening the requirements for certain components and settings, while | ||
// also providing deeper insights, events and status that more closely align with | ||
// PostgresCluster's intended use. | ||
andrewlecuyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Defaults to “production”. Acceptable values are "development" and "production". | ||
// +kubebuilder:validation:Enum={production,development} | ||
// +kubebuilder:default=production | ||
// +optional | ||
Environment *string `json:"environment,omitempty"` | ||
Comment on lines
+67
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I forget how optional + default behaves. My memory is that the API fills in the default before it saves. If so, will we "always" have a value? 👍🏻 Pointer for optional seems right. If we don't like dereferencing it, we can change the struct later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These semantics always trip me up too. But yea, like you mentioned, the field should/will always have a value, since the API will will in the default if nothing is provided by the user. |
||
|
||
// The image name to use for PostgreSQL containers. When omitted, the value | ||
// comes from an operator environment variable. For standard PostgreSQL images, | ||
// the format is RELATED_IMAGE_POSTGRES_{postgresVersion}, | ||
|
@@ -305,6 +317,11 @@ func (s *PostgresClusterSpec) Default() { | |
if s.UserInterface != nil { | ||
s.UserInterface.Default() | ||
} | ||
|
||
if s.Environment == nil { | ||
s.Environment = new(string) | ||
*s.Environment = "production" | ||
} | ||
} | ||
|
||
// Backups defines a PostgreSQL archive configuration | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ I wanna drop "PostgresCluster" here, too. Not sure why. I don't like the singular "environment" in my proposed message, so double not-sure.
🔧 I think we should use
has()
to check for the presence of a field. Ispgbackrest
required within thebackups
section? If so, we can trust/defer to its own validation rules.🌱 With controller-gen >= 0.16.0, we can use
fieldPath
to indicate more clearly thatspec.backups
is what's missing.📝 If you have any doubts about the logic of the rule, you can add some tests like the ones in internal/testing/validation/postgrescluster_test.go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the following
message
:I also switch the
null
check tohas()
. However, I did go one layer deeper withhas(self.backups.pgbackrest)
to protect against an emptybackups
section (backups: {}
). I don't love the error messages displayed when this does fail, since the validation rule itself essentially fails due to the missing field. But for now this does appear to protect against everything we need it to, and it does seem like there is a fine line with keeping these errors pretty, and keeping the rules from getting too complex.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did attempt a bump to controller-gen
0.16.3
, but saw something a bit strange with our RBAC (I'll capture in a story if no thoughts in the Slack thread I started). This did give mefieldPath
andreason
, though I found it was really only helpful if the user actually included the section (and thereason
, while returned from the API, is displayed bykubectl
). But this could again be tied to further expanding the rule a bit (e.g. per my last comment) to get some better validation error messages/behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and made the bump to
0.16.3
.fieldRef
andreason
have now been added to the CEL validation marker as a result.Additionally, I made one final tweak to the validation rule:
Now I get a clean/consistent error whether
backups
is empty or missing:Missing
backups
:Empty
backups
: