Skip to content

Commit 510ddf4

Browse files
committed
Validate pg_upgrade versions at the API server
1 parent ef1eae0 commit 510ddf4

File tree

5 files changed

+3
-20
lines changed

5 files changed

+3
-20
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ spec:
11551155
- toPostgresVersion
11561156
type: object
11571157
x-kubernetes-validations:
1158+
- rule: self.fromPostgresVersion < self.toPostgresVersion
11581159
- message: Only Copy or Link before PostgreSQL 12
11591160
rule: '!has(self.transferMethod) || (self.toPostgresVersion < 12 ? self.transferMethod
11601161
in ["Copy","Link"] : true)'

internal/controller/pgupgrade/pgupgrade_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *PGUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
153153
setStatusToProgressingIfReasonWas("", upgrade)
154154

155155
// The "from" version must be smaller than the "to" version.
156+
// NOTE: CRD validation also rejects these values.
156157
// An invalid PGUpgrade should not be requeued.
157158
if upgrade.Spec.FromPostgresVersion >= upgrade.Spec.ToPostgresVersion {
158159

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type PGUpgradeSpec struct {
7676
// Arguments and settings for the pg_upgrade tool.
7777
// See: https://www.postgresql.org/docs/current/pgupgrade.html
7878
// ---
79+
// +kubebuilder:validation:XValidation:rule=`self.fromPostgresVersion < self.toPostgresVersion`
7980
// +kubebuilder:validation:XValidation:rule=`!has(self.transferMethod) || (self.toPostgresVersion < 12 ? self.transferMethod in ["Copy","Link"] : true)`,message="Only Copy or Link before PostgreSQL 12"
8081
// +kubebuilder:validation:XValidation:rule=`!has(self.transferMethod) || (self.toPostgresVersion < 17 ? self.transferMethod in ["Clone","Copy","Link"] : true)`,message="Only Clone, Copy, or Link before PostgreSQL 17"
8182
type PGUpgradeSettings struct {

testing/kuttl/e2e/major-upgrade/01--invalid-pgupgrade.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

testing/kuttl/e2e/major-upgrade/01-assert.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)