Skip to content

Grant leader election core events access - #7349

Merged
ChrisJBurns merged 1 commit into
stacklok:mainfrom
pcbeingused333:fix/operator-leader-election-events
Nov 27, 2026
Merged

ChrisJBurns merged 1 commit into
stacklok:mainfrom
pcbeingused333:fix/operator-leader-election-events

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #7299

Summary

  • Why: the leader-election lock is created by controller-runtime with the legacy event recorder (GetEventRecorderFor), which writes events in the core API group. The leader-election Role only allows events in events.k8s.io, so with rbac.scope=namespace and an operator namespace outside allowedNamespaces, winning the election logs events is forbidden.
  • What: add a core-group events create/patch rule to operator.leaderElectionRole.rules. The events.k8s.io rule stays. The chart README is regenerated with helm-docs.
  • Add a helm-unittest suite for the leader-election Role in that namespace-scoped setup.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Ran helm unittest deploy/charts/operator: the new test fails without the values.yaml change (85 passed, 1 failed) and all 86 tests pass with it. This renders the chart only; it was not run against a cluster.

Does this introduce a user-facing change?

The operator can now record its leader-election event in namespace-scoped installs. Installs that override operator.leaderElectionRole.rules need to add the rule themselves.

This change was prepared with AI assistance.

The leader-election lock records events through the core API group, but
the leader-election Role only allowed events in events.k8s.io. When the
operator namespace is not in rbac.allowedNamespaces, writing the
LeaderElection event is forbidden.

Fixes stacklok#7299

Signed-off-by: Alex <[email protected]>
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.56%. Comparing base (4b9f678) to head (9c847f8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7349      +/-   ##
==========================================
- Coverage   82.57%   82.56%   -0.01%     
==========================================
  Files         940      940              
  Lines       96639    96639              
==========================================
- Hits        79799    79790       -9     
- Misses      16835    16844       +9     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns
ChrisJBurns merged commit 7d1ef06 into stacklok:main Nov 27, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Operator leader-election event recording fails with namespace-scoped RBAC

2 participants