Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8SPG-614: Enable leader election #997

Merged
merged 5 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/postgres-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

//"github.com/percona/percona-postgresql-operator/internal/controller/pgupgrade"

"github.com/percona/percona-postgresql-operator/internal/controller/pgupgrade"
"github.com/percona/percona-postgresql-operator/internal/controller/postgrescluster"
"github.com/percona/percona-postgresql-operator/internal/controller/runtime"
Expand Down Expand Up @@ -106,6 +105,7 @@ func main() {
namespaces,
cfg,
false,
false,
features,
)
assertNoError(err)
Expand Down
2 changes: 1 addition & 1 deletion percona/controller/pgcluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ var _ = Describe("Watching secrets", Ordered, func() {
Expect(err).NotTo(HaveOccurred())

Expect(err).To(Not(HaveOccurred()))
mgr, err := runtime.CreateRuntimeManager(namespace.Name, cfg, true, gate)
mgr, err := runtime.CreateRuntimeManager(namespace.Name, cfg, true, true, gate)
Expect(err).To(Succeed())
Expect(v2.AddToScheme(mgr.GetScheme())).To(Succeed())

Expand Down
11 changes: 9 additions & 2 deletions percona/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ var refreshInterval = 60 * time.Minute

// CreateRuntimeManager does the same thing as `internal/controller/runtime.CreateRuntimeManager`,
// excet it configures the manager to watch multiple namespaces.
func CreateRuntimeManager(namespaces string, config *rest.Config, disableMetrics bool, features feature.MutableGate) (manager.Manager, error) {
func CreateRuntimeManager(namespaces string, config *rest.Config, disableMetrics, disableLeaderElection bool, features feature.MutableGate) (manager.Manager, error) {

options := manager.Options{
Cache: cache.Options{
SyncPeriod: &refreshInterval,
},
Scheme: r.Scheme,
Scheme: r.Scheme,
LeaderElection: disableLeaderElection,
LeaderElectionID: "08db3feb.percona.com",
inelpandzic marked this conversation as resolved.
Show resolved Hide resolved
}

if disableLeaderElection {
options.LeaderElection = false
options.LeaderElectionID = ""
}

options.BaseContext = func() context.Context {
Expand Down
Loading