Skip to content

Commit 84fdf44

Browse files
committed
fix unit-tests
1 parent 4784e18 commit 84fdf44

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

cmd/postgres-operator/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func main() {
113113
options, err := initManager(ctx)
114114
assertNoError(err)
115115

116+
options.LeaderElection = true
117+
options.LeaderElectionID = perconaRuntime.ElectionID
118+
116119
mgr, err := perconaRuntime.CreateRuntimeManager(
117120
cfg,
118121
features,

config/manager/default/manager.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ spec:
3535
value: INFO
3636
- name: DISABLE_TELEMETRY
3737
value: "false"
38+
- name: PGO_WORKERS
39+
value: "1"
3840
ports:
3941
- containerPort: 8080
4042
name: metrics

deploy/cw-bundle.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47673,6 +47673,8 @@ spec:
4767347673
value: INFO
4767447674
- name: DISABLE_TELEMETRY
4767547675
value: "false"
47676+
- name: PGO_WORKERS
47677+
value: "1"
4767647678
image: perconalab/percona-postgresql-operator:main
4767747679
imagePullPolicy: Always
4767847680
livenessProbe:

percona/controller/pgcluster/controller_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"crypto/md5" //nolint:gosec
99
"fmt"
10+
"os"
1011
"strconv"
1112
"sync"
1213
"time"
@@ -24,8 +25,10 @@ import (
2425
"k8s.io/apimachinery/pkg/types"
2526
ctrl "sigs.k8s.io/controller-runtime"
2627
"sigs.k8s.io/controller-runtime/pkg/client"
28+
metricsServer "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2729

2830
"github.com/percona/percona-postgresql-operator/internal/controller/postgrescluster"
31+
internalRuntime "github.com/percona/percona-postgresql-operator/internal/controller/runtime"
2932
"github.com/percona/percona-postgresql-operator/internal/feature"
3033
"github.com/percona/percona-postgresql-operator/internal/naming"
3134
perconaController "github.com/percona/percona-postgresql-operator/percona/controller"
@@ -539,7 +542,15 @@ var _ = Describe("Watching secrets", Ordered, func() {
539542
Expect(err).NotTo(HaveOccurred())
540543

541544
Expect(err).To(Not(HaveOccurred()))
542-
mgr, err := runtime.CreateRuntimeManager(namespace.Name, cfg, true, true, gate)
545+
546+
os.Setenv("PGO_TARGET_NAMESPACE", "")
547+
mgr, err := runtime.CreateRuntimeManager(cfg, gate, internalRuntime.Options{
548+
LeaderElection: false,
549+
HealthProbeBindAddress: "0",
550+
Metrics: metricsServer.Options{
551+
BindAddress: "0",
552+
},
553+
})
543554
Expect(err).To(Succeed())
544555
Expect(v2.AddToScheme(mgr.GetScheme())).To(Succeed())
545556

percona/runtime/runtime.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ import (
1818
// default refresh interval in minutes
1919
const refreshInterval time.Duration = 60 * time.Minute
2020

21-
const electionID string = "08db3feb.percona.com"
21+
const ElectionID string = "08db3feb.percona.com"
2222

2323
// CreateRuntimeManager wraps internal/controller/runtime.NewManager and modifies the given options:
2424
// - Fully overwrites the Cache field
2525
// - Sets Cache.SyncPeriod to refreshInterval const
2626
// - Sets Cache.DefaultNamespaces by using k8s.GetWatchNamespace() split by ","
27-
// - Sets LeaderElection to true
28-
// - Sets LeaderElectionID to the electionID const
2927
// - Sets BaseContext to include the provided feature gates
3028
func CreateRuntimeManager(config *rest.Config, features feature.MutableGate, options manager.Options) (manager.Manager, error) {
3129
namespaces, err := k8s.GetWatchNamespace()
@@ -45,9 +43,6 @@ func CreateRuntimeManager(config *rest.Config, features feature.MutableGate, opt
4543
options.Cache.DefaultNamespaces = namespaces
4644
}
4745

48-
options.LeaderElection = true
49-
options.LeaderElectionID = electionID
50-
5146
options.BaseContext = func() context.Context {
5247
ctx := context.Background()
5348
return feature.NewContext(ctx, features)

0 commit comments

Comments
 (0)