Skip to content

fix: react to label changes on pods again - #62

Merged
mariotrace merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/pod-update-event-filter
Jul 31, 2026
Merged

mariotrace merged 1 commit into
dynatrace-oss:mainfrom
knQzx:fix/pod-update-event-filter

Conversation

@knQzx

@knQzx knQzx commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

the update filter in SetupWithManager has an empty case *corev1.Pod: sitting in front of the deployment case:

switch e.ObjectNew.(type) {
case *corev1.Pod:
case *appsv1.Deployment:
    // For pods and deployments, consider generation changes and label changes
    return predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{}).Update(e)

go type switches do not fall through, so a pod update matches the first case, runs nothing and falls out to return false. the Watches(&corev1.Pod{}, watchHandler) two lines above therefore never fires on updates, and LabelChangedPredicate is dead for pods

in practice: labelling a running pod so that a policy should now match it does not enqueue a reconcile, so the honeytoken never arrives. removing the label does not trigger cleanup either. the pod only gets picked up when something else happens to reconcile the policy

the comment on the deployment case says "For pods and deployments", so both kinds were meant to share that predicate

changes

merged the two cases, and did the same in DeleteFunc where the shape is identical (harmless there, both branches return false, but it reads as the same mistake)

moved the filter into deceptionPolicyEventFilter() so it can be exercised without standing up a manager

testing

three specs: a pod update that changes labels must pass, a deployment update that changes labels must pass, and a pod update that only changes status must still be dropped. that last one pins that this does not open the door to status churn

before the change the first spec fails, after it all three pass. go test ./internal/... ./api/... is green with the envtest binaries from make setup-envtest

The update filter had an empty `case *corev1.Pod:` ahead of the deployment
case. Go type switches do not fall through, so every pod update returned
false and the LabelChangedPredicate never applied to pods: labelling a running
pod did not enqueue a reconcile, and removing the label did not trigger
cleanup. The comment on the next case shows both kinds were meant to share it.

Moved the filter into its own function so it can be tested without a manager.
@mariotrace

Copy link
Copy Markdown
Member

Wow, thanks! How could we have missed that previously, I am embarrassed, thank you for this excellent finding! 💙 Merging ...

@mariotrace
mariotrace merged commit a19750f into dynatrace-oss:main Jul 31, 2026
7 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.

2 participants