-
Notifications
You must be signed in to change notification settings - Fork 621
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
benjaminjb
merged 1 commit into
CrunchyData:main
from
benjaminjb:benjb/crd-validation-ratcheting
Jul 11, 2025
+20,275
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18,631 changes: 18,631 additions & 0 deletions
18,631
config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/crunchydata/postgres-operator/internal/controller/runtime" | ||
"github.com/crunchydata/postgres-operator/internal/testing/cmp" | ||
"github.com/crunchydata/postgres-operator/internal/testing/require" | ||
v1 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1" | ||
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" | ||
) | ||
|
||
|
@@ -519,3 +520,101 @@ func TestPostgresUserOptions(t *testing.T) { | |
assert.NilError(t, cc.Create(ctx, cluster, client.DryRunAll)) | ||
}) | ||
} | ||
|
||
func TestPostgresUserInterfaceAcrossVersions(t *testing.T) { | ||
ctx := context.Background() | ||
cc := require.Kubernetes(t) | ||
t.Parallel() | ||
|
||
namespace := require.Namespace(t, cc) | ||
|
||
base := v1beta1.NewPostgresCluster() | ||
// Start with a bunch of required fields. | ||
base.Namespace = namespace.Name | ||
base.Name = "postgres-pgadmin" | ||
require.UnmarshalInto(t, &base.Spec, `{ | ||
userInterface: { | ||
pgAdmin: { | ||
dataVolumeClaimSpec: { | ||
accessModes: [ReadWriteOnce], | ||
resources: { requests: { storage: 1Mi } }, | ||
}, | ||
}, | ||
}, | ||
postgresVersion: 16, | ||
backups: { | ||
pgbackrest: { | ||
repos: [{ name: repo1 }], | ||
}, | ||
}, | ||
instances: [{ | ||
dataVolumeClaimSpec: { | ||
accessModes: [ReadWriteOnce], | ||
resources: { requests: { storage: 1Mi } }, | ||
}, | ||
}], | ||
}`) | ||
|
||
v1base := v1.NewPostgresCluster() | ||
// Start with a bunch of required fields. | ||
v1base.Namespace = namespace.Name | ||
v1base.Name = "postgres-pgadmin" | ||
require.UnmarshalInto(t, &v1base.Spec, `{ | ||
userInterface: { | ||
pgAdmin: { | ||
dataVolumeClaimSpec: { | ||
accessModes: [ReadWriteOnce], | ||
resources: { requests: { storage: 1Mi } }, | ||
}, | ||
}, | ||
}, | ||
postgresVersion: 16, | ||
backups: { | ||
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'll think about making it a pointer on the new struct! |
||
pgbackrest: { | ||
repos: [{ name: repo1 }], | ||
}, | ||
}, | ||
instances: [{ | ||
dataVolumeClaimSpec: { | ||
accessModes: [ReadWriteOnce], | ||
resources: { requests: { storage: 1Mi } }, | ||
}, | ||
}], | ||
}`) | ||
|
||
t.Run("v1beta1 is valid with pgadmin", func(t *testing.T) { | ||
assert.NilError(t, cc.Create(ctx, base.DeepCopy(), client.DryRunAll), | ||
"expected this base cluster to be valid") | ||
}) | ||
t.Run("v1 is invalid with pgadmin", func(t *testing.T) { | ||
assert.ErrorContains(t, cc.Create(ctx, v1base.DeepCopy(), client.DryRunAll), | ||
"userInterface not available in v1") | ||
}) | ||
|
||
t.Run("v1 is valid with pgadmin but only if unchanged from v1beta1", func(t *testing.T) { | ||
cbandy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Validation ratcheting is enabled starting in Kubernetes 1.30 | ||
require.KubernetesAtLeast(t, "1.30") | ||
|
||
// A v1 that has been updated from a v1beta1 with no change to the userInterface is valid | ||
assert.NilError(t, cc.Create(ctx, base), | ||
"expected this base cluster to be valid") | ||
v1base.ResourceVersion = base.ResourceVersion | ||
assert.NilError(t, cc.Update(ctx, v1base), | ||
"expected this v1 cluster to be a valid update") | ||
|
||
// But will not be valid if there's a change to the userInterface | ||
require.UnmarshalInto(t, &v1base.Spec, `{ | ||
userInterface: { | ||
pgAdmin: { | ||
dataVolumeClaimSpec: { | ||
accessModes: [ReadWriteOnce, ReadWriteMany], | ||
resources: { requests: { storage: 2Mi } }, | ||
}, | ||
}, | ||
}, | ||
}`) | ||
|
||
assert.ErrorContains(t, cc.Update(ctx, v1base), | ||
"userInterface not available in v1") | ||
Comment on lines
+617
to
+618
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 like this test! |
||
}) | ||
} |
24 changes: 24 additions & 0 deletions
24
pkg/apis/postgres-operator.crunchydata.com/v1/groupversion_info.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2021 - 2025 Crunchy Data Solutions, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// package v1 contains API Schema definitions for the postgres-operator v1beta1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=postgres-operator.crunchydata.com | ||
package v1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "postgres-operator.crunchydata.com", Version: "v1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.