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
+6 -2
View File
@@ -227,13 +227,17 @@ func (c *Cluster) logServiceChanges(role PostgresRole, old, new *v1.Service, isU
}
}
func (c *Cluster) getPostgresContainer(podSpec *v1.PodSpec) v1.Container {
var pgContainer v1.Container
func getPostgresContainer(podSpec *v1.PodSpec) (pgContainer v1.Container) {
for _, container := range podSpec.Containers {
if container.Name == constants.PostgresContainerName {
pgContainer = container
}
}
// if no postgres container was found, take the first one in the podSpec
if reflect.DeepEqual(pgContainer, v1.Container{}) && len(podSpec.Containers) > 0 {
pgContainer = podSpec.Containers[0]
}
return pgContainer
}