Skip to content

Commit

Permalink
Convert to controller runtime runnables (#4202)
Browse files Browse the repository at this point in the history
- controller runtime manages controllers and other runnables (previously
goroutines added to the server workgroup)
- leader election now uses a combination of configmap and lease objects,
in a future release we can move to just leases
- controllers and other components are currently not dependent on leader election
- other components (status writers) are set to be dependent on leader
election
- adds to the leaderelection e2e tests to check on leaderelection
configmap in addition to new lease resource and events

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
  • Loading branch information
sunjayBhatia authored Dec 6, 2021
1 parent 0250de9 commit 801c194
Show file tree
Hide file tree
Showing 48 changed files with 1,264 additions and 590 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ lint-flags:

.PHONY: generate
generate: ## Re-generate generated code and documentation
generate: generate-rbac generate-crd-deepcopy generate-crd-yaml generate-gateway-crd-yaml generate-deployment generate-api-docs generate-metrics-docs generate-uml
generate: generate-rbac generate-crd-deepcopy generate-crd-yaml generate-gateway-crd-yaml generate-deployment generate-api-docs generate-metrics-docs generate-uml generate-go

.PHONY: generate-rbac
generate-rbac:
Expand Down Expand Up @@ -240,9 +240,14 @@ generate-api-docs:

.PHONY: generate-metrics-docs
generate-metrics-docs:
@echo Generating metrics documentation ...
@echo "Generating metrics documentation..."
@cd site/content/guides/metrics && rm -f *.md && go run ../../../../hack/generate-metrics-doc.go

.PHONY: generate-go
generate-go:
@echo "Generating mocks..."
@go generate ./...

.PHONY: check-generate
check-generate: generate
@./hack/actions/check-uncommitted-codegen.sh
Expand Down
8 changes: 8 additions & 0 deletions changelogs/unreleased/4202-sunjayBhatia-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Transition to controller-runtime managed leader election

Contour now utilizes [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) Manager based leader election and coordination of subroutines.
With this change, Contour is also transitioning away from using a ConfigMap for leader election.
In this release, Contour now uses a combination of ConfigMap and Lease object.
A future release will remove usage of the ConfigMap resource for leader election.

This change should be a no-op for most users, however be sure to re-apply the relevant parts of your deployment for RBAC to ensure Contour has access to Lease and Event objects (this would be the ClusterRole in the provided example YAML).
17 changes: 5 additions & 12 deletions cmd/contour/ingressstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,16 @@ import (
type loadBalancerStatusWriter struct {
log logrus.FieldLogger
cache cache.Cache
isLeader chan struct{}
lbStatus chan v1.LoadBalancerStatus
statusUpdater k8s.StatusUpdater
ingressClassName string
}

func (isw *loadBalancerStatusWriter) Start(stop <-chan struct{}) error {
// Await leadership election.
isw.log.Info("awaiting leadership election")
select {
case <-stop:
// We were asked to stop before elected leader.
return nil
case <-isw.isLeader:
isw.log.Info("elected leader")
}
func (isw *loadBalancerStatusWriter) NeedLeaderElection() bool {
return true
}

func (isw *loadBalancerStatusWriter) Start(ctx context.Context) error {
u := &k8s.StatusAddressUpdater{
Logger: func() logrus.FieldLogger {
// Configure the StatusAddressUpdater logger.
Expand Down Expand Up @@ -98,7 +91,7 @@ func (isw *loadBalancerStatusWriter) Start(stop <-chan struct{}) error {

for {
select {
case <-stop:
case <-ctx.Done():
// Once started, there's no way to stop the
// informer from here. Clear the load balancer
// status so that subsequent informer events
Expand Down
7 changes: 7 additions & 0 deletions cmd/contour/ingressstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

func Test_parseStatusFlag(t *testing.T) {
Expand Down Expand Up @@ -194,3 +196,8 @@ func Test_lbAddress(t *testing.T) {
})
}
}

func TestRequireLeaderElection(t *testing.T) {
var l manager.LeaderElectionRunnable = &loadBalancerStatusWriter{}
require.True(t, l.NeedLeaderElection())
}
157 changes: 0 additions & 157 deletions cmd/contour/leadership.go

This file was deleted.

Loading

0 comments on commit 801c194

Please sign in to comment.