Skip to content

fix: mark reports of superseded ReplicaSets without pods for deletion - #3070

Open
ahauserv wants to merge 1 commit into
aquasecurity:mainfrom
ahauserv:fix/mark-superseded-replicaset-reports
Open

ahauserv wants to merge 1 commit into
aquasecurity:mainfrom
ahauserv:fix/mark-superseded-replicaset-reports

Conversation

@ahauserv

Copy link
Copy Markdown

Description

With scanOnlyCurrentRevisions enabled, SkipProcessing checked for pods before checking whether a ReplicaSet (or ReplicationController) is the current revision. MarkOldReportForImmediateDeletion was therefore only reachable while a superseded revision still had pod objects, i.e. during the scale-down of a rollout. If the ReplicaSet had no pods at that moment (Deployment scaled to 0 before the template change, or the reconcile came after the pods were gone because of an operator restart or backlog), every later reconcile of the old ReplicaSet returned at Ignoring ReplicaSet with no active pods and the stale reports stayed until the report TTL expired (24h by default), reporting vulnerabilities of an image that no longer runs.

Reproduction in the linked issue.

This PR swaps the two checks: the current-revision check runs first, so an inactive revision is marked for immediate deletion whether or not it still has pods. The "no active pods" skip now only applies to the current revision. Same change for ReplicationController.

Before, for an old ReplicaSet scaled to 0:

DEBUG  reconciler.vulnerabilityreport  Ignoring ReplicaSet with no active pods  {"name": "nginx-old"}

and its reports keep trivy-operator.aquasecurity.github.io/report-ttl: 24h0m0s.

After:

DEBUG  reconciler.vulnerabilityreport  Ignoring inactive ReplicaSet  {"controllerKind": "Deployment", "controllerName": "nginx"}

and its reports get report-ttl: 0s and are removed by the TTL reconciler on the next reconcile.

Tests: new pkg/operator/workload/helper_test.go covers inactive/active ReplicaSet with and without pods, and an inactive ReplicationController without pods. The two "inactive without pods" cases fail on main.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@CLAassistant

CLAassistant commented Sep 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ahauserv
ahauserv force-pushed the fix/mark-superseded-replicaset-reports branch from c111fdd to e7735d0 Compare October 13, 2026 09:59
With scanOnlyCurrentRevisions enabled, SkipProcessing checked for pods
before checking whether a ReplicaSet or ReplicationController is the
current revision. MarkOldReportForImmediateDeletion was therefore only
reachable while a superseded revision still had pod objects, i.e. during
the scale-down of a rollout. If the operator missed that window (restart,
backlog, requeue after a failed Deployment lookup, pods terminating
immediately), every later reconcile hit the "no active pods" return
first and the stale reports lived on until the report TTL expired,
24h by default.

Check the revision first so an inactive revision is marked whether or not
it still has pods. The "no active pods" skip now only applies to the
current revision.

This branch has not been deployed

No deployments
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.

Reports of a superseded ReplicaSet are never marked for deletion once it has scaled to zero

2 participants