Skip to content

Emit Kubernetes events on pods during eviction#388

Open
databus23 wants to merge 1 commit into
masterfrom
feature/eviction-pod-events
Open

Emit Kubernetes events on pods during eviction#388
databus23 wants to merge 1 commit into
masterfrom
feature/eviction-pod-events

Conversation

@databus23

@databus23 databus23 commented May 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Record a Normal event on each Pod when it is evicted, deleted, or force-deleted during a node drain
  • Events are visible via kubectl describe pod and show the Node as the related object
  • Threaded through all three drain call sites: maintenance plugin, ESX controller, kubernikus controller
  • The recorder field in DrainParameters is optional (nil = no events), so existing callers and tests work without changes

Test plan

  • go build ./... compiles cleanly
  • All unit tests pass (common, state, plugin, plugin/impl)
  • Full gmake build/cover.out passes (ESX suite is flaky on timing but passes on retry)
  • In a real cluster: drain a node, verify kubectl get events --field-selector regarding.name=<pod> shows eviction event

Record a Normal event on each Pod as it is evicted, deleted, or
force-deleted during a node drain. Events are visible via
`kubectl describe pod` and help operators understand why a pod
was terminated during maintenance.

The event recorder is threaded through DrainParameters (optional,
nil-safe) and passed from the main reconciler, ESX controller, and
kubernikus controller.
@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (2 decrease, 1 increase)

Impacted Packages Coverage Δ 🤖
github.com/sapcc/maintenance-controller 0.00% (ø)
github.com/sapcc/maintenance-controller/common 72.59% (-0.57%) 👎
github.com/sapcc/maintenance-controller/esx 72.49% (+1.18%) 👍
github.com/sapcc/maintenance-controller/kubernikus 62.11% (-3.16%) 👎
github.com/sapcc/maintenance-controller/plugin/impl 81.14% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/sapcc/maintenance-controller/common/schedule.go 70.67% (-0.66%) 150 (+7) 106 (+4) 44 (+3) 👎
github.com/sapcc/maintenance-controller/esx/runnable.go 75.97% (+0.65%) 154 117 (+1) 37 (-1) 👍
github.com/sapcc/maintenance-controller/kubernikus/node_controller.go 62.11% (-3.16%) 95 59 (-3) 36 (+3) 👎
github.com/sapcc/maintenance-controller/main.go 0.00% (ø) 0 0 0
github.com/sapcc/maintenance-controller/plugin/impl/eviction.go 76.19% (ø) 21 16 5

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Comment thread common/schedule.go
GracePeriodSeconds *int64
// optional recorder to emit events on evicted pods
Recorder events.EventRecorder
Node *corev1.Node

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

2 participants