Skip to content

CRD validation ratcheting: userInterface #4198

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

Merged

Conversation

benjaminjb
Copy link
Contributor

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

This lays the groundwork for a v1 of the CRD; with a conversion type of None and validation ratcheting to handle differences between versions.

Other Information:
Issues: [PGO-2524]

Comment on lines 19 to 21
func TestPostgresClusterWebhooks(t *testing.T) {
var _ webhook.Defaulter = new(PostgresCluster)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed in a Dependabot PR that this doesn't compile with newer controller-runtime:

golangci-lint: pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types_test.go#L18
undefined: webhook.Defaulter (typecheck)

⛏️ What do you think of removing this now, in both apiVersions, as we're considering ratcheting over webhooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually removed this file locally since we didn't make any changes, but now I'm waffling. Ah well, removing for now.

@benjaminjb benjaminjb force-pushed the benjb/crd-validation-ratcheting branch from 15f72a7 to 8c2ad0e Compare July 11, 2025 18:08
Copy link
Member

@cbandy cbandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Missed some generated code.

LGTM. Please squash.

// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:Type=object
// +kubebuilder:validation:XValidation:rule="type(self) == null_type || self == oldSelf", message="DynamicConfiguration not available in v1, please use ..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 Ah! oldSelf means no K8s ratcheting, and self == oldSelf sounds similar to the built-in ratcheting.

// The PGBackRest field is incompatible with the PostgresCluster field: only one
// data source can be used for pre-populating a new PostgreSQL cluster
// +optional
// +kubebuilder:validation:XValidation:rule="!has(self.repo.volume)", message="Only S3, GCS or Azure repos can be used as a pgBackRest data source.", fieldPath=".repo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I wish there were a way to define these rules over multiple lines.

@@ -0,0 +1,740 @@
// Copyright 2021 - 2025 Crunchy Data Solutions, Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Looks like the copy/re-use goes file-wise; that works for me. We can arrange things into smaller files if/as we find it necessary.

},
},
postgresVersion: 16,
backups: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I remember now that I tried turning backups into a pointer so we could omit it in these tests, and it sent me down some long hole.

},
},
postgresVersion: 16,
backups: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 🤔 I'll think about making it a pointer on the new struct!

Comment on lines +617 to +618
assert.ErrorContains(t, cc.Update(ctx, v1base),
"userInterface not available in v1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 I like this test!

- Add kubebuilder markers to v1beta1 to mark as storage version
- Add v1 files for changed version (postgrescluster)
- Add rule to disallow userInterface
- Add v1 conversion test, runtime scheme
- Add a helper for kube version tests
- Remove ref to webhook in v1beta1

Issues: [PGO-2524]
@benjaminjb benjaminjb force-pushed the benjb/crd-validation-ratcheting branch from 8c2ad0e to b8b9d49 Compare July 11, 2025 20:17
@benjaminjb benjaminjb merged commit 29cb15d into CrunchyData:main Jul 11, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants