Implements EBS volume resizing #35.

In order to support volumes different from EBS and filesystems other than EXT2/3/4 the respective code parts were implemented as interfaces. Adding the new resize for the volume or the filesystem will require implementing the interface, but no other changes in the cluster code itself.

Volume resizing first changes the EBS and the filesystem, and only afterwards is reflected in the Kubernetes "PersistentVolume" object. This is done deliberately to be able to check if the volume needs resizing by peeking at the Size of the PersistentVolume structure. We recheck, nevertheless, in the EBSVolumeResizer, whether the actual EBS volume size doesn't match the spec, since call to the AWS ModifyVolume is counted against the resize limit of once every 6 hours, even for those calls that shouldn't result in an actual resize (i.e. when the size matches the one for the running volume).

As a collateral, split the constants into multiple files, move the volume code into a separate file and fix minor issues related to the error reporting.
This commit is contained in:
Oleksii Kliukin
2017-06-06 13:53:27 +02:00
committed by GitHub
parent 1fb05212a9
commit 7b0ca31bfb
25 changed files with 554 additions and 134 deletions
+37 -20
View File
@@ -5,6 +5,7 @@ import (
"github.com/zalando-incubator/postgres-operator/pkg/util"
"github.com/zalando-incubator/postgres-operator/pkg/util/k8sutil"
"github.com/zalando-incubator/postgres-operator/pkg/util/volumes"
)
func (c *Cluster) Sync() error {
@@ -44,18 +45,22 @@ func (c *Cluster) Sync() error {
}
}
if c.databaseAccessDisabled() {
return nil
}
if err := c.initDbConn(); err != nil {
return fmt.Errorf("could not init db connection: %v", err)
} else {
c.logger.Debugf("Syncing roles")
if err := c.SyncRoles(); err != nil {
return fmt.Errorf("could not sync roles: %v", err)
if !c.databaseAccessDisabled() {
if err := c.initDbConn(); err != nil {
return fmt.Errorf("could not init db connection: %v", err)
} else {
c.logger.Debugf("Syncing roles")
if err := c.SyncRoles(); err != nil {
return fmt.Errorf("could not sync roles: %v", err)
}
}
}
c.logger.Debugf("Syncing persistent volumes")
if err := c.SyncVolumes(); err != nil {
return fmt.Errorf("could not sync persistent volumes: %v", err)
}
return nil
}
@@ -114,7 +119,7 @@ func (c *Cluster) syncEndpoint() error {
func (c *Cluster) syncStatefulSet() error {
cSpec := c.Spec
var rollUpdate, needsReplace bool
var rollUpdate bool
if c.Statefulset == nil {
c.logger.Infof("could not find the cluster's statefulset")
pods, err := c.listPods()
@@ -139,24 +144,20 @@ func (c *Cluster) syncStatefulSet() error {
return nil
}
}
/* TODO: should check that we need to replace the statefulset */
if !rollUpdate {
var (
match bool
reason string
)
desiredSS, err := c.genStatefulSet(cSpec)
if err != nil {
return fmt.Errorf("could not generate statefulset: %v", err)
}
match, needsReplace, rollUpdate, reason = c.compareStatefulSetWith(desiredSS)
if match {
cmp := c.compareStatefulSetWith(desiredSS)
if cmp.match {
return nil
}
c.logStatefulSetChanges(c.Statefulset, desiredSS, false, reason)
c.logStatefulSetChanges(c.Statefulset, desiredSS, false, cmp.reasons)
if !needsReplace {
if !cmp.replace {
if err := c.updateStatefulSet(desiredSS); err != nil {
return fmt.Errorf("could not update statefulset: %v", err)
}
@@ -166,7 +167,7 @@ func (c *Cluster) syncStatefulSet() error {
}
}
if !rollUpdate {
if !cmp.rollingUpdate {
c.logger.Debugln("No rolling update is needed")
return nil
}
@@ -199,3 +200,19 @@ func (c *Cluster) SyncRoles() error {
}
return nil
}
/* SyncVolume reads all persistent volumes and checks that their size matches the one declared in the statefulset */
func (c *Cluster) SyncVolumes() error {
act, err := c.VolumesNeedResizing(c.Spec.Volume)
if err != nil {
return fmt.Errorf("could not compare size of the volumes: %v", err)
}
if !act {
return nil
}
if err := c.resizeVolumes(c.Spec.Volume, []volumes.VolumeResizer{&volumes.EBSVolumeResizer{}}); err != nil {
return fmt.Errorf("Could not sync volumes: %v", err)
}
c.logger.Infof("volumes have been synced successfully")
return nil
}