@@ -18,6 +18,7 @@ import (
1818 "github.com/crunchydata/postgres-operator/internal/controller/runtime"
1919 "github.com/crunchydata/postgres-operator/internal/testing/cmp"
2020 "github.com/crunchydata/postgres-operator/internal/testing/require"
21+ v1 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1"
2122 "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2223)
2324
@@ -519,3 +520,98 @@ func TestPostgresUserOptions(t *testing.T) {
519520 assert .NilError (t , cc .Create (ctx , cluster , client .DryRunAll ))
520521 })
521522}
523+
524+ func TestPostgresUserInterfaceAcrossVersions (t * testing.T ) {
525+ ctx := context .Background ()
526+ cc := require .Kubernetes (t )
527+ t .Parallel ()
528+
529+ namespace := require .Namespace (t , cc )
530+
531+ base := v1beta1 .NewPostgresCluster ()
532+ // Start with a bunch of required fields.
533+ base .Namespace = namespace .Name
534+ base .Name = "postgres-pgadmin"
535+ require .UnmarshalInto (t , & base .Spec , `{
536+ userInterface: {
537+ pgAdmin: {
538+ dataVolumeClaimSpec: {
539+ accessModes: [ReadWriteOnce],
540+ resources: { requests: { storage: 1Mi } },
541+ },
542+ },
543+ },
544+ postgresVersion: 16,
545+ backups: {
546+ pgbackrest: {
547+ repos: [{ name: repo1 }],
548+ },
549+ },
550+ instances: [{
551+ dataVolumeClaimSpec: {
552+ accessModes: [ReadWriteOnce],
553+ resources: { requests: { storage: 1Mi } },
554+ },
555+ }],
556+ }` )
557+
558+ v1base := v1 .NewPostgresCluster ()
559+ // Start with a bunch of required fields.
560+ v1base .Namespace = namespace .Name
561+ v1base .Name = "postgres-pgadmin"
562+ require .UnmarshalInto (t , & v1base .Spec , `{
563+ userInterface: {
564+ pgAdmin: {
565+ dataVolumeClaimSpec: {
566+ accessModes: [ReadWriteOnce],
567+ resources: { requests: { storage: 1Mi } },
568+ },
569+ },
570+ },
571+ postgresVersion: 16,
572+ backups: {
573+ pgbackrest: {
574+ repos: [{ name: repo1 }],
575+ },
576+ },
577+ instances: [{
578+ dataVolumeClaimSpec: {
579+ accessModes: [ReadWriteOnce],
580+ resources: { requests: { storage: 1Mi } },
581+ },
582+ }],
583+ }` )
584+
585+ t .Run ("v1beta1 is valid with pgadmin" , func (t * testing.T ) {
586+ assert .NilError (t , cc .Create (ctx , base .DeepCopy (), client .DryRunAll ),
587+ "expected this base cluster to be valid" )
588+ })
589+ t .Run ("v1 is invalid with pgadmin" , func (t * testing.T ) {
590+ assert .ErrorContains (t , cc .Create (ctx , v1base .DeepCopy (), client .DryRunAll ),
591+ "userInterface not available in v1" )
592+ })
593+
594+ t .Run ("v1 is valid with pgadmin but only if unchanged from v1beta1" , func (t * testing.T ) {
595+ // A v1 that has been updated from a v1beta1 with no change to the userInterface is valid
596+ assert .NilError (t , cc .Create (ctx , base ),
597+ "expected this base cluster to be valid" )
598+ v1base .ResourceVersion = base .ResourceVersion
599+ assert .NilError (t , cc .Update (ctx , v1base ),
600+ "expected this v1 cluster to be a valid update" )
601+
602+ // But will not be valid if there's a change to the userInterface
603+ require .UnmarshalInto (t , & v1base .Spec , `{
604+ userInterface: {
605+ pgAdmin: {
606+ dataVolumeClaimSpec: {
607+ accessModes: [ReadWriteOnce, ReadWriteMany],
608+ resources: { requests: { storage: 2Mi } },
609+ },
610+ },
611+ },
612+ }` )
613+
614+ assert .ErrorContains (t , cc .Update (ctx , v1base ),
615+ "userInterface not available in v1" )
616+ })
617+ }
0 commit comments