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

Convert to controller runtime runnables #4202

Conversation

sunjayBhatia
Copy link
Member

  • 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

- 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>
@sunjayBhatia sunjayBhatia requested a review from a team as a code owner November 30, 2021 23:18
@sunjayBhatia sunjayBhatia requested review from tsaarni and stevesloka and removed request for a team November 30, 2021 23:18
@sunjayBhatia sunjayBhatia added the release-note/minor A minor change that needs about a paragraph of explanation in the release notes. label Nov 30, 2021
@sunjayBhatia
Copy link
Member Author

overrides #4157

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@codecov
Copy link

codecov bot commented Nov 30, 2021

Codecov Report

Merging #4202 (975532e) into main (7bf2309) will increase coverage by 0.07%.
The diff coverage is 28.34%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4202      +/-   ##
==========================================
+ Coverage   76.52%   76.59%   +0.07%     
==========================================
  Files         111      114       +3     
  Lines        9869     9999     +130     
==========================================
+ Hits         7552     7659     +107     
+ Misses       2150     2149       -1     
- Partials      167      191      +24     
Impacted Files Coverage Δ
cmd/contour/serve.go 12.01% <1.56%> (-0.49%) ⬇️
internal/k8s/status.go 22.64% <10.52%> (+4.45%) ⬆️
internal/controller/mocks/manager.go 12.90% <12.90%> (ø)
internal/controller/gatewayclass.go 15.65% <33.33%> (+15.65%) ⬆️
internal/controller/gateway.go 12.86% <37.50%> (+12.86%) ⬆️
internal/controller/httproute.go 26.92% <42.85%> (+26.92%) ⬆️
internal/controller/tlsroute.go 26.92% <42.85%> (+26.92%) ⬆️
cmd/contour/ingressstatus.go 40.00% <50.00%> (+5.62%) ⬆️
internal/debug/debug.go 9.09% <50.00%> (+9.09%) ⬆️
internal/contour/metrics.go 68.96% <69.23%> (+0.33%) ⬆️
... and 11 more

for name, test := range tests {
t.Run(name, func(t *testing.T) {
mockManager := &mocks.Manager{}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what people think about these tests, they ensure the controller is registered and that it does not require leader election, using a generated mock manager (see mock package and go generate command above)

"github.com/stretchr/testify/require"
)

func TestEventHandlerNotRequireLeaderElection(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what people think of these tests for the various components, settled on this after spiking through another option which i wonder what people think of

  • new object as thin wrapper around controller-runtime manager
  • mainly for testing, can test by mocking controller-runtime manager (see controller tests for example)
  • instead of manager.Add(Runnable) method, have something like manager.Add(Runnable, requireLeaderElection bool)

decided against this for a few reasons, mainly bc it ended up being a v thin wrapper (need to expose a lot of things from the base controller-runtime manager) and puts more logic in the main package, rather than closer to the components themselves which should have the knowledge about whether they need leader election or not

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handful of comments, but overall this is looking nice!

examples/contour/02-role-contour.yaml Show resolved Hide resolved
hack/actions/install-kubernetes-toolchain.sh Outdated Show resolved Hide resolved
internal/controller/controller.go Show resolved Hide resolved
internal/debug/debug.go Outdated Show resolved Hide resolved
internal/httpsvc/http.go Outdated Show resolved Hide resolved
cmd/contour/serve.go Show resolved Hide resolved
cmd/contour/serve.go Show resolved Hide resolved
internal/featuretests/v3/featuretests.go Show resolved Hide resolved
…aderelection

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Copy link
Member

@stevesloka stevesloka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm with @skriss's comments. Nice work @sunjayBhatia!

…aderelection

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@sunjayBhatia sunjayBhatia force-pushed the controller-runtime-leaderelection branch 2 times, most recently from 5dc4c52 to 640b248 Compare December 2, 2021 22:17
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@skriss
Copy link
Member

skriss commented Dec 3, 2021

@sunjayBhatia I was playing with this locally and had a couple issues:

  • proxies created after my local Contour acquires leadership do not seem to trigger a DAG rebuild/get status
  • the process is not shutting down cleanly on SIGTERM

I imagine the first is related to the E2E failures. I haven't had a chance to dig into these any further yet, just wanted to put the reports here. I'll look some more later this AM.

@sunjayBhatia
Copy link
Member Author

@sunjayBhatia I was playing with this locally and had a couple issues:

  • proxies created after my local Contour acquires leadership do not seem to trigger a DAG rebuild/get status
  • the process is not shutting down cleanly on SIGTERM

I imagine the first is related to the E2E failures. I haven't had a chance to dig into these any further yet, just wanted to put the reports here. I'll look some more later this AM.

yep, same issues here, e2e tests do some capturing of the issues but a little worried about other components besides just the main status updater (e.g load balancer status updater), needs a little more work

@sunjayBhatia
Copy link
Member Author

Contour server failed" error="failed waiting for all runnables to end within grace period of 30s: context deadline exceeded on shutdown, could adjust to not use graceful shutdown as well

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@sunjayBhatia
Copy link
Member Author

Contour server failed" error="failed waiting for all runnables to end within grace period of 30s: context deadline exceeded on shutdown, could adjust to not use graceful shutdown as well

i think fixing my silly channels mistake also helped with shutdown issues

@skriss
Copy link
Member

skriss commented Dec 3, 2021

Yep looks better for me

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought on the tests, otherwise I think this looks good, doing some ad-hoc testing locally too

internal/k8s/status_test.go Show resolved Hide resolved
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 local testing all looks good to me, as does the new leader election notification abstraction

internal/leadership/notifier.go Show resolved Hide resolved
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@sunjayBhatia
Copy link
Member Author

Tests need a small fix to make them more robust now we’re deleting contour and restarting in incluster suite

Also check new leader pod exists

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, not sure if there were any other outstanding threads here though

@sunjayBhatia
Copy link
Member Author

LGTM, not sure if there were any other outstanding threads here though

i think we got everything!

@sunjayBhatia sunjayBhatia merged commit 801c194 into projectcontour:main Dec 6, 2021
@sunjayBhatia sunjayBhatia deleted the controller-runtime-leaderelection branch December 6, 2021 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor A minor change that needs about a paragraph of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants