Skip to content

Commit 88d6a7b

Browse files
Sync persistent volumes before statefulsets. (zalando#293)
Avoid the condition of waiting for the pod that cannot start PostgreSQL because it ran out of disk space.
1 parent 922b3fa commit 88d6a7b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/cluster/sync.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ func (c *Cluster) Sync(newSpec *spec.Postgresql) (err error) {
5050
return
5151
}
5252

53+
// potentially enlarge volumes before changing the statefulset. By doing that
54+
// in this order we make sure the operator is not stuck waiting for a pod that
55+
// cannot start because it ran out of disk space.
56+
// TODO: handle the case of the cluster that is downsized and enlarged again
57+
// (there will be a volume from the old pod for which we can't act before the
58+
// the statefulset modification is concluded)
59+
c.logger.Debugf("syncing persistent volumes")
60+
if err = c.syncVolumes(); err != nil {
61+
err = fmt.Errorf("could not sync persistent volumes: %v", err)
62+
return
63+
}
64+
5365
c.logger.Debugf("syncing statefulsets")
5466
if err = c.syncStatefulSet(); err != nil {
5567
if !k8sutil.ResourceAlreadyExists(err) {
@@ -72,12 +84,6 @@ func (c *Cluster) Sync(newSpec *spec.Postgresql) (err error) {
7284
}
7385
}
7486

75-
c.logger.Debugf("syncing persistent volumes")
76-
if err = c.syncVolumes(); err != nil {
77-
err = fmt.Errorf("could not sync persistent volumes: %v", err)
78-
return
79-
}
80-
8187
c.logger.Debug("syncing pod disruption budgets")
8288
if err = c.syncPodDisruptionBudget(false); err != nil {
8389
err = fmt.Errorf("could not sync pod disruption budget: %v", err)

0 commit comments

Comments
 (0)