@@ -12,6 +12,7 @@ import (
1212 "k8s.io/client-go/tools/remotecommand"
1313
1414 "github.com/zalando-incubator/postgres-operator/pkg/spec"
15+ "github.com/zalando-incubator/postgres-operator/pkg/util/constants"
1516)
1617
1718//ExecCommand executes arbitrary command inside the pod
@@ -28,8 +29,17 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (
2829 return "" , fmt .Errorf ("could not get pod info: %v" , err )
2930 }
3031
31- if len (pod .Spec .Containers ) != 1 {
32- return "" , fmt .Errorf ("could not determine which container to use" )
32+ // iterate through all containers looking for the one running PostgreSQL.
33+ targetContainer := - 1
34+ for i , cr := range pod .Spec .Containers {
35+ if cr .Name == constants .PostgresContainerName {
36+ targetContainer = i
37+ break
38+ }
39+ }
40+
41+ if targetContainer < 0 {
42+ return "" , fmt .Errorf ("could not find %s container to exec to" , constants .PostgresContainerName )
3343 }
3444
3545 req := c .KubeClient .RESTClient .Post ().
@@ -38,7 +48,7 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (
3848 Namespace (podName .Namespace ).
3949 SubResource ("exec" )
4050 req .VersionedParams (& v1.PodExecOptions {
41- Container : pod .Spec .Containers [0 ].Name ,
51+ Container : pod .Spec .Containers [targetContainer ].Name ,
4252 Command : command ,
4353 Stdout : true ,
4454 Stderr : true ,
0 commit comments