Merge pull request #314 from zalando-incubator/volume_resize_with_multiple_containers
Fix exec into pods to resize volumes for multi-container pods.
This commit is contained in:
		
						commit
						59795d48d2
					
				|  | @ -12,6 +12,7 @@ import ( | |||
| 	"k8s.io/client-go/tools/remotecommand" | ||||
| 
 | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/spec" | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/util/constants" | ||||
| ) | ||||
| 
 | ||||
| //ExecCommand executes arbitrary command inside the pod
 | ||||
|  | @ -28,8 +29,17 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) ( | |||
| 		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") | ||||
| 	// iterate through all containers looking for the one running PostgreSQL.
 | ||||
| 	targetContainer := -1 | ||||
| 	for i, cr := range pod.Spec.Containers { | ||||
| 		if cr.Name == constants.PostgresContainerName { | ||||
| 			targetContainer = i | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if targetContainer < 0 { | ||||
| 		return "", fmt.Errorf("could not find %s container to exec to", constants.PostgresContainerName) | ||||
| 	} | ||||
| 
 | ||||
| 	req := c.KubeClient.RESTClient.Post(). | ||||
|  | @ -38,7 +48,7 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) ( | |||
| 		Namespace(podName.Namespace). | ||||
| 		SubResource("exec") | ||||
| 	req.VersionedParams(&v1.PodExecOptions{ | ||||
| 		Container: pod.Spec.Containers[0].Name, | ||||
| 		Container: pod.Spec.Containers[targetContainer].Name, | ||||
| 		Command:   command, | ||||
| 		Stdout:    true, | ||||
| 		Stderr:    true, | ||||
|  |  | |||
|  | @ -15,7 +15,6 @@ import ( | |||
| 	"k8s.io/client-go/pkg/apis/apps/v1beta1" | ||||
| 	policyv1beta1 "k8s.io/client-go/pkg/apis/policy/v1beta1" | ||||
| 	"k8s.io/client-go/rest" | ||||
| 
 | ||||
| ) | ||||
| 
 | ||||
| // EventType contains type of the events for the TPRs and Pods received from Kubernetes
 | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ import "time" | |||
| 
 | ||||
| // General kubernetes-related constants
 | ||||
| const ( | ||||
| 	PostgresContainerName       = "postgres" | ||||
| 	K8sAPIPath                  = "/apis" | ||||
| 	StatefulsetDeletionInterval = 1 * time.Second | ||||
| 	StatefulsetDeletionTimeout  = 30 * time.Second | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue