Skip to content

Commit 63868d6

Browse files
committed
fix(patroni/http): uses proper feature gates
Replaces environment variable toggle by a feature gate, already used in the package. Signed-off-by: Juliana Oliveira <[email protected]>
1 parent d317c9d commit 63868d6

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

internal/controller/postgrescluster/instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"os"
1211
"sort"
1312
"strings"
1413
"time"
@@ -822,8 +821,8 @@ func (r *Reconciler) rolloutInstance(
822821

823822
var success bool
824823

825-
// If FEAT_PATRONI_PREFER_HTTP is active, try HTTP first, then fallback
826-
if os.Getenv("FEAT_PATRONI_PREFER_HTTP") == "true" {
824+
// If PatroniPreferHTTP feature is enabled, try HTTP first, then fallback
825+
if feature.Enabled(ctx, feature.PatroniPreferHTTP) {
827826
log.Info("Attempting HTTP call...")
828827

829828
if res, httpErr := patroni.NewHttpClient(ctx, r.Client, pod.Name); httpErr == nil {

internal/controller/postgrescluster/patroni.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"os"
1211
"time"
1312

1413
"github.com/pkg/errors"
@@ -17,6 +16,7 @@ import (
1716
"k8s.io/apimachinery/pkg/util/intstr"
1817
"sigs.k8s.io/controller-runtime/pkg/client"
1918

19+
"github.com/percona/percona-postgresql-operator/internal/feature"
2020
"github.com/percona/percona-postgresql-operator/internal/initialize"
2121
"github.com/percona/percona-postgresql-operator/internal/logging"
2222
"github.com/percona/percona-postgresql-operator/internal/naming"
@@ -103,8 +103,8 @@ func (r *Reconciler) handlePatroniRestarts(
103103
role = "master"
104104
}
105105

106-
// If FEAT_PATRONI_PREFER_HTTP is active, try HTTP first, then fallback
107-
if os.Getenv("FEAT_PATRONI_PREFER_HTTP") == "true" {
106+
// If PatroniPreferHTTP feature is enabled, try HTTP first, then fallback
107+
if feature.Enabled(ctx, feature.PatroniPreferHTTP) {
108108
log.Info("Attempting HTTP call...")
109109

110110
if client, err := patroni.NewHttpClient(ctx, r.Client, pod.Name); err == nil {
@@ -144,8 +144,8 @@ func (r *Reconciler) handlePatroniRestarts(
144144
if replicaNeedsRestart != nil {
145145
pod := replicaNeedsRestart.Pods[0]
146146

147-
// If FEAT_PATRONI_PREFER_HTTP is active, try HTTP first, then fallback
148-
if os.Getenv("FEAT_PATRONI_PREFER_HTTP") == "true" {
147+
// If PatroniPreferHTTP feature is enabled, try HTTP first, then fallback
148+
if feature.Enabled(ctx, feature.PatroniPreferHTTP) {
149149
log.Info("Attempting HTTP call...")
150150

151151
if client, err := patroni.NewHttpClient(ctx, r.Client, pod.Name); err == nil {
@@ -253,8 +253,8 @@ func (r *Reconciler) reconcilePatroniDynamicConfiguration(
253253

254254
configuration = patroni.DynamicConfiguration(cluster, configuration, pgHBAs, pgParameters)
255255

256-
// If FEAT_PATRONI_PREFER_HTTP is active, try HTTP first, then fallback
257-
if os.Getenv("FEAT_PATRONI_PREFER_HTTP") == "true" {
256+
// If PatroniPreferHTTP feature is enabled, try HTTP first, then fallback
257+
if feature.Enabled(ctx, feature.PatroniPreferHTTP) {
258258
log.Info("Attempting HTTP call...")
259259

260260
if client, err := patroni.NewHttpClient(ctx, r.Client, pod.Name); err == nil {
@@ -605,8 +605,8 @@ func (r *Reconciler) reconcilePatroniSwitchover(ctx context.Context,
605605
var timeline int64
606606
var err error
607607

608-
// If FEAT_PATRONI_PREFER_HTTP is active, try HTTP first, then fallback
609-
if os.Getenv("FEAT_PATRONI_PREFER_HTTP") == "true" {
608+
// If PatroniPreferHTTP feature is enabled, try HTTP first, then fallback
609+
if feature.Enabled(ctx, feature.PatroniPreferHTTP) {
610610
log.Info("Attempting HTTP call...")
611611

612612
if res, httpErr := patroni.NewHttpClient(ctx, r.Client, runningPod.Name); httpErr == nil {

internal/feature/features.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ const (
8686

8787
// Support VolumeSnapshots
8888
VolumeSnapshots = "VolumeSnapshots"
89+
90+
// Use HTTP client for Patroni API calls instead of kubectl exec
91+
PatroniPreferHTTP = "PatroniPreferHTTP"
8992
)
9093

9194
// NewGate returns a MutableGate with the Features defined in this package.
@@ -98,6 +101,7 @@ func NewGate() MutableGate {
98101
AutoGrowVolumes: {Default: false, PreRelease: featuregate.Alpha},
99102
BridgeIdentifiers: {Default: false, PreRelease: featuregate.Alpha},
100103
InstanceSidecars: {Default: false, PreRelease: featuregate.Alpha},
104+
PatroniPreferHTTP: {Default: false, PreRelease: featuregate.Alpha},
101105
PGBouncerSidecars: {Default: false, PreRelease: featuregate.Alpha},
102106
TablespaceVolumes: {Default: false, PreRelease: featuregate.Alpha},
103107
VolumeSnapshots: {Default: false, PreRelease: featuregate.Alpha},

0 commit comments

Comments
 (0)