Skip to content

Commit 0679ab3

Browse files
authored
fix: Allow multiple sharded instances to be hosted in one namespace (#2265)
1 parent 7befa71 commit 0679ab3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"crypto/sha256"
2122
"flag"
2223
"fmt"
2324
"log/slog"
@@ -167,6 +168,12 @@ func main() { // nolint:gocyclo
167168
setupLog.Error(fmt.Errorf("invalid value %s for %s", enforceCacheLabelsLevel, enforceCacheLabelsEnvVar), "falling back to disabling cache enforcement")
168169
}
169170

171+
// Determine LeaderElectionID from
172+
leHash := sha256.New()
173+
leHash.Write([]byte(watchNamespace))
174+
leHash.Write([]byte(watchNamespaceSelector))
175+
leHash.Write([]byte(watchLabelSelectors))
176+
170177
clusterDomain, _ := os.LookupEnv(clusterDomainEnvVar)
171178

172179
// Fetch k8s api credentials and detect platform
@@ -190,7 +197,7 @@ func main() { // nolint:gocyclo
190197
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
191198
HealthProbeBindAddress: probeAddr,
192199
LeaderElection: enableLeaderElection,
193-
LeaderElectionID: "f75f3bba.integreatly.org",
200+
LeaderElectionID: fmt.Sprintf("grafana-operator-%x", leHash.Sum(nil)),
194201
PprofBindAddress: pprofAddr,
195202
Controller: config.Controller{
196203
MaxConcurrentReconciles: maxConcurrentReconciles,

0 commit comments

Comments
 (0)