Use full election leader ID
This commit is contained in:
parent
7c717cabcf
commit
20a89480f0
2 changed files with 12 additions and 14 deletions
|
@ -49,6 +49,7 @@ import (
|
||||||
|
|
||||||
"k8s.io/ingress-nginx/internal/file"
|
"k8s.io/ingress-nginx/internal/file"
|
||||||
"k8s.io/ingress-nginx/internal/ingress"
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
|
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||||
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/controller/process"
|
"k8s.io/ingress-nginx/internal/ingress/controller/process"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/controller/store"
|
"k8s.io/ingress-nginx/internal/ingress/controller/store"
|
||||||
|
@ -262,18 +263,25 @@ func (n *NGINXController) Start() {
|
||||||
|
|
||||||
n.store.Run(n.stopCh)
|
n.store.Run(n.stopCh)
|
||||||
|
|
||||||
|
// we need to use the defined ingress class to allow multiple leaders
|
||||||
|
// in order to update information about ingress status
|
||||||
|
electionID := fmt.Sprintf("%v-%v", n.cfg.ElectionID, class.DefaultClass)
|
||||||
|
if class.IngressClass != "" {
|
||||||
|
electionID = fmt.Sprintf("%v-%v", n.cfg.ElectionID, class.IngressClass)
|
||||||
|
}
|
||||||
|
|
||||||
setupLeaderElection(&leaderElectionConfig{
|
setupLeaderElection(&leaderElectionConfig{
|
||||||
Client: n.cfg.Client,
|
Client: n.cfg.Client,
|
||||||
ElectionID: n.cfg.ElectionID,
|
ElectionID: electionID,
|
||||||
OnStartedLeading: func(stopCh chan struct{}) {
|
OnStartedLeading: func(stopCh chan struct{}) {
|
||||||
if n.syncStatus != nil {
|
if n.syncStatus != nil {
|
||||||
go n.syncStatus.Run(stopCh)
|
go n.syncStatus.Run(stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.metricCollector.OnStartedLeading(n.cfg.ElectionID)
|
n.metricCollector.OnStartedLeading(electionID)
|
||||||
},
|
},
|
||||||
OnStoppedLeading: func() {
|
OnStoppedLeading: func() {
|
||||||
n.metricCollector.OnStoppedLeading(n.cfg.ElectionID)
|
n.metricCollector.OnStoppedLeading(electionID)
|
||||||
|
|
||||||
// Remove prometheus metrics related to SSL certificates
|
// Remove prometheus metrics related to SSL certificates
|
||||||
srvs := sets.NewString()
|
srvs := sets.NewString()
|
||||||
|
|
|
@ -18,7 +18,6 @@ package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -31,8 +30,6 @@ import (
|
||||||
"k8s.io/client-go/tools/leaderelection"
|
"k8s.io/client-go/tools/leaderelection"
|
||||||
"k8s.io/client-go/tools/leaderelection/resourcelock"
|
"k8s.io/client-go/tools/leaderelection/resourcelock"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
|
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type leaderElectionConfig struct {
|
type leaderElectionConfig struct {
|
||||||
|
@ -48,13 +45,6 @@ type leaderElectionConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupLeaderElection(config *leaderElectionConfig) {
|
func setupLeaderElection(config *leaderElectionConfig) {
|
||||||
// we need to use the defined ingress class to allow multiple leaders
|
|
||||||
// in order to update information about ingress status
|
|
||||||
electionID := fmt.Sprintf("%v-%v", config.ElectionID, class.DefaultClass)
|
|
||||||
if class.IngressClass != "" {
|
|
||||||
electionID = fmt.Sprintf("%v-%v", config.ElectionID, class.IngressClass)
|
|
||||||
}
|
|
||||||
|
|
||||||
var elector *leaderelection.LeaderElector
|
var elector *leaderelection.LeaderElector
|
||||||
|
|
||||||
// start a new context
|
// start a new context
|
||||||
|
@ -106,7 +96,7 @@ func setupLeaderElection(config *leaderElectionConfig) {
|
||||||
})
|
})
|
||||||
|
|
||||||
lock := resourcelock.ConfigMapLock{
|
lock := resourcelock.ConfigMapLock{
|
||||||
ConfigMapMeta: metav1.ObjectMeta{Namespace: config.PodNamespace, Name: electionID},
|
ConfigMapMeta: metav1.ObjectMeta{Namespace: config.PodNamespace, Name: config.ElectionID},
|
||||||
Client: config.Client.CoreV1(),
|
Client: config.Client.CoreV1(),
|
||||||
LockConfig: resourcelock.ResourceLockConfig{
|
LockConfig: resourcelock.ResourceLockConfig{
|
||||||
Identity: config.PodName,
|
Identity: config.PodName,
|
||||||
|
|
Loading…
Reference in a new issue