Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28778,6 +28778,8 @@ spec:
and is true
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
- message: CRVersion must be a valid semantic version
rule: '!has(self.crVersion) || self.crVersion == "" || self.crVersion.matches(''^[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$'')'
status:
properties:
conditions:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29473,6 +29473,8 @@ spec:
and is true
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
- message: CRVersion must be a valid semantic version
rule: '!has(self.crVersion) || self.crVersion == "" || self.crVersion.matches(''^[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$'')'
status:
properties:
conditions:
Expand Down
2 changes: 2 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29770,6 +29770,8 @@ spec:
and is true
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
- message: CRVersion must be a valid semantic version
rule: '!has(self.crVersion) || self.crVersion == "" || self.crVersion.matches(''^[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$'')'
status:
properties:
conditions:
Expand Down
2 changes: 2 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29770,6 +29770,8 @@ spec:
and is true
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
- message: CRVersion must be a valid semantic version
rule: '!has(self.crVersion) || self.crVersion == "" || self.crVersion.matches(''^[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$'')'
status:
properties:
conditions:
Expand Down
2 changes: 2 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29770,6 +29770,8 @@ spec:
and is true
rule: '!has(self.users) || self.postgresVersion >= 15 || self.users.all(u,
!has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)'
- message: CRVersion must be a valid semantic version
rule: '!has(self.crVersion) || self.crVersion == "" || self.crVersion.matches(''^[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$'')'
status:
properties:
conditions:
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type PerconaPGCluster struct {
}

// +kubebuilder:validation:XValidation:rule="!has(self.users) || self.postgresVersion >= 15 || self.users.all(u, !has(u.grantPublicSchemaAccess) || !u.grantPublicSchemaAccess)",message="PostgresVersion must be >= 15 if grantPublicSchemaAccess exists and is true"
// +kubebuilder:validation:XValidation:rule="!has(self.crVersion) || self.crVersion == \"\" || self.crVersion.matches('^[0-9]+\\\\.[0-9]+\\\\.[0-9]+(-[a-zA-Z0-9.+-]+)?$')",message="CRVersion must be a valid semantic version"
type PerconaPGClusterSpec struct {
// +optional
Metadata *crunchyv1beta1.Metadata `json:"metadata,omitempty"`
Expand Down Expand Up @@ -505,7 +506,11 @@ func (cr *PerconaPGCluster) ToCrunchy(ctx context.Context, postgresCluster *crun
}

func (cr *PerconaPGCluster) Version() *gover.Version {
return gover.Must(gover.NewVersion(cr.Spec.CRVersion))
crVersion := cr.Spec.CRVersion
if crVersion == "" {
crVersion = version.Version()
}
Comment on lines +509 to +512

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test case would only work on e2e tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we don't need to test ShouldCheckStandbyLag regression but it'd be great to add a simple unit test that covers PerconaPGCluster.Version() behavior

return gover.Must(gover.NewVersion(crVersion))
Comment on lines +509 to +513

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, this only falls back with the assumption that the opeator will reconcile the cluster and set the version asynchronously. Falling back to version.Version() on non empty can introduce hard to find bugs. But a way to do it, would actually be a validation pattern on the CRD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i agree

}

func (cr *PerconaPGCluster) CompareVersion(ver string) int {
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ func TestPerconaPGCluster_Validate(t *testing.T) {
})
}

func TestPerconaPGCluster_Version(t *testing.T) {
t.Run("empty CRVersion does not crash", func(t *testing.T) {
cr := new(PerconaPGCluster)
// cr.Version() should not panic when CRVersion is empty
ver := cr.Version()
require.NotNil(t, ver)
// Should return the default operator version
assert.Equal(t, version.Version(), ver.String())
})

t.Run("valid CRVersion is parsed correctly", func(t *testing.T) {
cr := new(PerconaPGCluster)
cr.Spec.CRVersion = "2.5.0"
ver := cr.Version()
require.NotNil(t, ver)
assert.Equal(t, "2.5.0", ver.String())
})
}

func TestPerconaPGCluster_Proxy(t *testing.T) {
t.Run("Proxy is nil, CRVersion < 2.9.0", func(t *testing.T) {
cr := new(PerconaPGCluster)
Expand Down
Loading