pick first container if postgres is not found (#1505)

* pick first container if postgres is not found

* minor change
This commit is contained in:
Felix Kunde
2021-05-28 11:44:10 +02:00
committed by GitHub
parent 7884af2d59
commit dd9c3907b7
6 changed files with 45 additions and 36 deletions
+3 -2
View File
@@ -12,6 +12,7 @@ import (
"k8s.io/client-go/tools/remotecommand"
"github.com/zalando/postgres-operator/pkg/spec"
"github.com/zalando/postgres-operator/pkg/util/constants"
)
//ExecCommand executes arbitrary command inside the pod
@@ -31,14 +32,14 @@ func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (
// iterate through all containers looking for the one running PostgreSQL.
targetContainer := -1
for i, cr := range pod.Spec.Containers {
if cr.Name == c.containerName() {
if cr.Name == constants.PostgresContainerName {
targetContainer = i
break
}
}
if targetContainer < 0 {
return "", fmt.Errorf("could not find %s container to exec to", c.containerName())
return "", fmt.Errorf("could not find %s container to exec to", constants.PostgresContainerName)
}
req := c.KubeClient.RESTClient.Post().