Skip to content

fix: skip resources with unparsable trap annotations instead of failing - #66

Merged
mariotrace merged 2 commits into
dynatrace-oss:mainfrom
knQzx:fix/skip-unparsable-annotations
Sep 4, 2026
Merged

mariotrace merged 2 commits into
dynatrace-oss:mainfrom
knQzx:fix/skip-unparsable-annotations

Conversation

@knQzx

@knQzx knQzx commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

GetAnnotatedResources lists every pod and deployment in the cluster and gives up on the first one whose koney/changes annotation does not parse:

annotationChange, err := GetAnnotationChange(&pod, crdName)
if err != nil {
    return nil, err
}

nothing filters, quarantines or skips the bad object, so a single unrelated resource takes the whole listing down

a pod with koney/changes: "-", set by anyone who can create a pod in any namespace, by a GitOps template or by a hand edit, then has cluster-wide effect:

no traps are deployed or updated anymore - every reconcile of every DeceptionPolicy runs cleanupRemovedTraps first and returns early on the error

policies cannot be deleted - cleanupDeceptionPolicy fails the same way, the finalizer is never removed and the object stays in Terminating forever

the annotation is koney bookkeeping rather than a user-facing API, and closed issue #12 already treats annotation-parsing brittleness as a bug, so failing closed on someone else's broken value looks unintended

this logs and skips resources whose annotation cannot be read, which also lets the clean-up path finish and release the finalizer. added tests for a valid resource, a broken one next to a valid one, and a lone broken one

// Resources whose annotation cannot be parsed are skipped, because we list all pods and deployments
// in the cluster here, and anyone who can annotate a single resource would otherwise stop the
// reconciliation of every DeceptionPolicy, including the clean-up that removes their finalizers.
func GetAnnotatedResources(r client.Reader, ctx context.Context, crdName string) ([]client.Object, error) {

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.

Good targeted fix, thanks! Could you make the comment less verbose possibly, please, e.g.

// GetAnnotatedResources returns a list of resources that have been annotated with a specific DeceptionPolicy.
// Resources whose annotation cannot be parsed are skipped.

Reason is that the upstream errors in the reconciliation loop are the problem of the caller, not something that we should document here (and that eventually gets outdated easily).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

shortened to your version, thanks!

@knQzx
knQzx force-pushed the fix/skip-unparsable-annotations branch from 4edb5f6 to e10a7c0 Compare September 3, 2026 22:03
@mariotrace
mariotrace merged commit 3f24c65 into dynatrace-oss:main Sep 4, 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