@@ -83,15 +83,16 @@ type Cluster struct {
8383 deleteOptions metav1.DeleteOptions
8484 podEventsQueue * cache.FIFO
8585
86- teamsAPIClient teams.Interface
87- oauthTokenGetter OAuthTokenGetter
88- KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place?
89- currentProcess Process
90- processMu sync.RWMutex // protects the current operation for reporting, no need to hold the master mutex
91- specMu sync.RWMutex // protects the spec for reporting, no need to hold the master mutex
92- ConnectionPooler map [PostgresRole ]* ConnectionPoolerObjects
93- EBSVolumes map [string ]volumes.VolumeProperties
94- VolumeResizer volumes.VolumeResizer
86+ teamsAPIClient teams.Interface
87+ oauthTokenGetter OAuthTokenGetter
88+ KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place?
89+ currentProcess Process
90+ processMu sync.RWMutex // protects the current operation for reporting, no need to hold the master mutex
91+ specMu sync.RWMutex // protects the spec for reporting, no need to hold the master mutex
92+ ConnectionPooler map [PostgresRole ]* ConnectionPoolerObjects
93+ EBSVolumes map [string ]volumes.VolumeProperties
94+ VolumeResizer volumes.VolumeResizer
95+ currentMajorVersion int
9596}
9697
9798type compareStatefulsetResult struct {
@@ -128,15 +129,16 @@ func New(cfg Config, kubeClient k8sutil.KubernetesClient, pgSpec acidv1.Postgres
128129 Secrets : make (map [types.UID ]* v1.Secret ),
129130 Services : make (map [PostgresRole ]* v1.Service ),
130131 Endpoints : make (map [PostgresRole ]* v1.Endpoints )},
131- userSyncStrategy : users.DefaultUserSyncStrategy {PasswordEncryption : passwordEncryption },
132- deleteOptions : metav1.DeleteOptions {PropagationPolicy : & deletePropagationPolicy },
133- podEventsQueue : podEventsQueue ,
134- KubeClient : kubeClient ,
132+ userSyncStrategy : users.DefaultUserSyncStrategy {PasswordEncryption : passwordEncryption },
133+ deleteOptions : metav1.DeleteOptions {PropagationPolicy : & deletePropagationPolicy },
134+ podEventsQueue : podEventsQueue ,
135+ KubeClient : kubeClient ,
136+ currentMajorVersion : 0 ,
135137 }
136138 cluster .logger = logger .WithField ("pkg" , "cluster" ).WithField ("cluster-name" , cluster .clusterName ())
137139 cluster .teamsAPIClient = teams .NewTeamsAPI (cfg .OpConfig .TeamsAPIUrl , logger )
138140 cluster .oauthTokenGetter = newSecretOauthTokenGetter (& kubeClient , cfg .OpConfig .OAuthTokenSecretName )
139- cluster .patroni = patroni .New (cluster .logger )
141+ cluster .patroni = patroni .New (cluster .logger , nil )
140142 cluster .eventRecorder = eventRecorder
141143
142144 cluster .EBSVolumes = make (map [string ]volumes.VolumeProperties )
@@ -359,7 +361,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
359361 }
360362 if ! reflect .DeepEqual (c .Statefulset .Annotations , statefulSet .Annotations ) {
361363 match = false
362- reasons = append (reasons , "new statefulset's annotations does not match the current one" )
364+ reasons = append (reasons , "new statefulset's annotations do not match the current one" )
363365 }
364366
365367 needsRollUpdate , reasons = c .compareContainers ("initContainers" , c .Statefulset .Spec .Template .Spec .InitContainers , statefulSet .Spec .Template .Spec .InitContainers , needsRollUpdate , reasons )
@@ -614,17 +616,14 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
614616
615617 logNiceDiff (c .logger , oldSpec , newSpec )
616618
617- if oldSpec .Spec .PostgresqlParam .PgVersion > newSpec .Spec .PostgresqlParam .PgVersion {
618- c .logger .Warningf ("postgresql version change(%q -> %q) has no effect" ,
619- oldSpec .Spec .PostgresqlParam .PgVersion , newSpec .Spec .PostgresqlParam .PgVersion )
620- c .eventRecorder .Eventf (c .GetReference (), v1 .EventTypeWarning , "PostgreSQL" , "postgresql version change(%q -> %q) has no effect" ,
621- oldSpec .Spec .PostgresqlParam .PgVersion , newSpec .Spec .PostgresqlParam .PgVersion )
622- // we need that hack to generate statefulset with the old version
623- newSpec .Spec .PostgresqlParam .PgVersion = oldSpec .Spec .PostgresqlParam .PgVersion
624- } else if oldSpec .Spec .PostgresqlParam .PgVersion < newSpec .Spec .PostgresqlParam .PgVersion {
625- c .logger .Infof ("postgresql version increased (%q -> %q), major version upgrade can be done manually after StatefulSet Sync" ,
619+ if IsBiggerPostgresVersion (oldSpec .Spec .PostgresqlParam .PgVersion , c .GetDesiredMajorVersion ()) {
620+ c .logger .Infof ("postgresql version increased (%s -> %s), depending on config manual upgrade needed" ,
626621 oldSpec .Spec .PostgresqlParam .PgVersion , newSpec .Spec .PostgresqlParam .PgVersion )
627622 syncStatetfulSet = true
623+ } else {
624+ c .logger .Infof ("postgresql major version unchanged or smaller, no changes needed" )
625+ // sticking with old version, this will also advance GetDesiredVersion next time.
626+ newSpec .Spec .PostgresqlParam .PgVersion = oldSpec .Spec .PostgresqlParam .PgVersion
628627 }
629628
630629 // Service
@@ -781,6 +780,14 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
781780 updateFailed = true
782781 }
783782
783+ if ! updateFailed {
784+ // Major version upgrade must only fire after success of earlier operations and should stay last
785+ if err := c .majorVersionUpgrade (); err != nil {
786+ c .logger .Errorf ("major version upgrade failed: %v" , err )
787+ updateFailed = true
788+ }
789+ }
790+
784791 return nil
785792}
786793
0 commit comments