Skip to content

Commit 172c718

Browse files
allow running withoug pgbouncer
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
1 parent 32278ca commit 172c718

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

percona/controller/pgcluster/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func (r *PGClusterReconciler) reconcileEnvFromSecrets(ctx context.Context, cr *v
599599
m[&set.EnvFrom] = set.Metadata
600600
}
601601

602-
if len(cr.Spec.Proxy.PGBouncer.EnvFrom) > 0 {
602+
if cr.Spec.Proxy != nil && len(cr.Spec.Proxy.PGBouncer.EnvFrom) > 0 {
603603
if cr.Spec.Proxy.PGBouncer.Metadata == nil {
604604
cr.Spec.Proxy.PGBouncer.Metadata = new(v1beta1.Metadata)
605605
}

percona/controller/pgcluster/status.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pgcluster
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/pkg/errors"
78
corev1 "k8s.io/api/core/v1"
@@ -11,16 +12,33 @@ import (
1112
"k8s.io/client-go/util/retry"
1213

1314
"github.com/percona/percona-postgresql-operator/v2/internal/controller/postgrescluster"
15+
"github.com/percona/percona-postgresql-operator/v2/internal/naming"
1416
pNaming "github.com/percona/percona-postgresql-operator/v2/percona/naming"
1517
v2 "github.com/percona/percona-postgresql-operator/v2/pkg/apis/pgv2.percona.com/v2"
1618
"github.com/percona/percona-postgresql-operator/v2/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1719
)
1820

1921
func (r *PGClusterReconciler) getHost(ctx context.Context, cr *v2.PerconaPGCluster) (string, error) {
20-
svcName := cr.Name + "-pgbouncer"
22+
postgresCluster := &v1beta1.PostgresCluster{
23+
ObjectMeta: metav1.ObjectMeta{
24+
Name: cr.Name,
25+
Namespace: cr.Namespace,
26+
},
27+
}
28+
29+
svcFQDN := func(svcName, ns string) string {
30+
return fmt.Sprintf("%s.%s.svc", svcName, ns)
31+
}
32+
33+
// If proxy is not configured, use the pod service
34+
if cr.Spec.Proxy == nil || cr.Spec.Proxy.PGBouncer == nil {
35+
return svcFQDN(naming.ClusterPodService(postgresCluster).Name, postgresCluster.Namespace), nil
36+
}
2137

38+
// PGBouncer is not exposed, use the service name
39+
svcName := naming.ClusterPGBouncer(postgresCluster).Name
2240
if cr.Spec.Proxy.PGBouncer.ServiceExpose == nil || cr.Spec.Proxy.PGBouncer.ServiceExpose.Type != string(corev1.ServiceTypeLoadBalancer) {
23-
return svcName + "." + cr.Namespace + ".svc", nil
41+
return svcFQDN(svcName, postgresCluster.Namespace), nil
2442
}
2543

2644
svc := &corev1.Service{}

pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,19 @@ func (cr *PerconaPGCluster) Default() {
212212
cr.Spec.InstanceSets[i].Metadata.Labels[LabelOperatorVersion] = cr.Spec.CRVersion
213213
}
214214

215-
if cr.Spec.Proxy == nil {
216-
cr.Spec.Proxy = new(PGProxySpec)
217-
}
218-
219-
if cr.Spec.Proxy.PGBouncer == nil {
220-
cr.Spec.Proxy.PGBouncer = new(PGBouncerSpec)
221-
}
215+
if cr.Spec.Proxy != nil {
216+
if cr.Spec.Proxy.PGBouncer == nil {
217+
cr.Spec.Proxy.PGBouncer = new(PGBouncerSpec)
218+
}
222219

223-
if cr.Spec.Proxy.PGBouncer.Metadata == nil {
224-
cr.Spec.Proxy.PGBouncer.Metadata = new(crunchyv1beta1.Metadata)
225-
}
226-
if cr.Spec.Proxy.PGBouncer.Metadata.Labels == nil {
227-
cr.Spec.Proxy.PGBouncer.Metadata.Labels = make(map[string]string)
220+
if cr.Spec.Proxy.PGBouncer.Metadata == nil {
221+
cr.Spec.Proxy.PGBouncer.Metadata = new(crunchyv1beta1.Metadata)
222+
}
223+
if cr.Spec.Proxy.PGBouncer.Metadata.Labels == nil {
224+
cr.Spec.Proxy.PGBouncer.Metadata.Labels = make(map[string]string)
225+
}
226+
cr.Spec.Proxy.PGBouncer.Metadata.Labels[LabelOperatorVersion] = cr.Spec.CRVersion
228227
}
229-
cr.Spec.Proxy.PGBouncer.Metadata.Labels[LabelOperatorVersion] = cr.Spec.CRVersion
230228

231229
t := true
232230
f := false

0 commit comments

Comments
 (0)