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
-61
View File
@@ -1,61 +0,0 @@
package controller
import (
"bytes"
"fmt"
remotecommandconsts "k8s.io/apimachinery/pkg/util/remotecommand"
"k8s.io/client-go/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned/remotecommand"
"github.com/zalando-incubator/postgres-operator/pkg/spec"
)
func (c *Controller) ExecCommand(podName spec.NamespacedName, command []string) (string, error) {
var (
execOut bytes.Buffer
execErr bytes.Buffer
)
pod, err := c.KubeClient.Pods(podName.Namespace).Get(podName.Name)
if err != nil {
return "", fmt.Errorf("could not get pod info: %v", err)
}
if len(pod.Spec.Containers) != 1 {
return "", fmt.Errorf("could not determine which container to use")
}
req := c.RestClient.Post().
Resource("pods").
Name(podName.Name).
Namespace(podName.Namespace).
SubResource("exec")
req.VersionedParams(&api.PodExecOptions{
Container: pod.Spec.Containers[0].Name,
Command: command,
Stdout: true,
Stderr: true,
}, api.ParameterCodec)
exec, err := remotecommand.NewExecutor(c.RestConfig, "POST", req.URL())
if err != nil {
return "", fmt.Errorf("failed to init executor: %v", err)
}
err = exec.Stream(remotecommand.StreamOptions{
SupportedProtocols: remotecommandconsts.SupportedStreamingProtocols,
Stdout: &execOut,
Stderr: &execErr,
})
if err != nil {
return "", fmt.Errorf("could not execute: %v", err)
}
if execErr.Len() > 0 {
return "", fmt.Errorf("stderr: %v", execErr.String())
}
return execOut.String(), nil
}
+2 -2
View File
@@ -169,8 +169,8 @@ func (c *Controller) processEvent(obj interface{}) error {
}
if err := cl.Sync(); err != nil {
cl.Error = fmt.Errorf("could not sync cluster '%s': %s", clusterName, err)
logger.Errorf("%v", cl)
cl.Error = fmt.Errorf("could not sync cluster '%s': %v", clusterName, err)
logger.Errorf("%v", cl.Error)
return nil
}
cl.Error = nil
+1
View File
@@ -23,6 +23,7 @@ func (c *Controller) makeClusterConfig() cluster.Config {
return cluster.Config{
KubeClient: c.KubeClient,
RestClient: c.RestClient,
RestConfig: c.RestConfig,
TeamsAPIClient: c.TeamsAPIClient,
OpConfig: config.Copy(c.opConfig),
InfrastructureRoles: infrastructureRoles,