Skip to content

Commit

Permalink
Use full election leader ID
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Mar 11, 2019
1 parent 7c717ca commit 20a8948
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
14 changes: 11 additions & 3 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (

"k8s.io/ingress-nginx/internal/file"
"k8s.io/ingress-nginx/internal/ingress"
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
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/store"
Expand Down Expand Up @@ -262,18 +263,25 @@ func (n *NGINXController) Start() {

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{
Client: n.cfg.Client,
ElectionID: n.cfg.ElectionID,
ElectionID: electionID,
OnStartedLeading: func(stopCh chan struct{}) {
if n.syncStatus != nil {
go n.syncStatus.Run(stopCh)
}

n.metricCollector.OnStartedLeading(n.cfg.ElectionID)
n.metricCollector.OnStartedLeading(electionID)
},
OnStoppedLeading: func() {
n.metricCollector.OnStoppedLeading(n.cfg.ElectionID)
n.metricCollector.OnStoppedLeading(electionID)

// Remove prometheus metrics related to SSL certificates
srvs := sets.NewString()
Expand Down
12 changes: 1 addition & 11 deletions internal/ingress/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controller

import (
"context"
"fmt"
"os"
"time"

Expand All @@ -31,8 +30,6 @@ import (
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"

"k8s.io/ingress-nginx/internal/ingress/annotations/class"
)

type leaderElectionConfig struct {
Expand All @@ -48,13 +45,6 @@ type leaderElectionConfig struct {
}

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

// start a new context
Expand Down Expand Up @@ -106,7 +96,7 @@ func setupLeaderElection(config *leaderElectionConfig) {
})

lock := resourcelock.ConfigMapLock{
ConfigMapMeta: metav1.ObjectMeta{Namespace: config.PodNamespace, Name: electionID},
ConfigMapMeta: metav1.ObjectMeta{Namespace: config.PodNamespace, Name: config.ElectionID},
Client: config.Client.CoreV1(),
LockConfig: resourcelock.ResourceLockConfig{
Identity: config.PodName,
Expand Down

0 comments on commit 20a8948

Please sign in to comment.