Skip to content

feat: add observedGeneration in status#80

Open
sandert-k8s wants to merge 3 commits into
kyverno:mainfrom
sandert-k8s:add-generation
Open

feat: add observedGeneration in status#80
sandert-k8s wants to merge 3 commits into
kyverno:mainfrom
sandert-k8s:add-generation

Conversation

@sandert-k8s
Copy link
Copy Markdown

@sandert-k8s sandert-k8s commented Apr 17, 2026

Explanation

This change adds the observedGeneration to the status object. This is already part of the CRD (so no CRD change required), but it was just not picked up by the controller. This has been added. Also keeps backward compatibility.

Related PR

kyverno/kyverno#15889

Related issue

2 Related issues:
kyverno/kyverno#12256
argoproj/argo-cd#27354 (review)

Proposed Changes

This change adds the observedGeneration to the status field to track if the processed generation is the same as in the annotation.

Checklist

  • [ x] I have read the contributing guidelines.
  • [ x] I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Copilot AI review requested due to automatic review settings April 17, 2026 07:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the policy ConditionStatus helper so it can populate observedGeneration on metav1.Condition, allowing controllers to record which resource generation a condition was computed from.

Changes:

  • Extend ConditionStatus.SetReadyByCondition to accept a generation value and set metav1.Condition.ObservedGeneration.
  • Update existing unit tests to use the new method signature.
  • Add unit tests verifying ObservedGeneration is set and updated on repeated calls.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
api/policies.kyverno.io/v1alpha1/conditions.go Adds a generation parameter to SetReadyByCondition and writes it into the condition’s ObservedGeneration field.
api/policies.kyverno.io/v1alpha1/conditions_test.go Updates existing tests for the new signature and adds coverage for ObservedGeneration behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/policies.kyverno.io/v1alpha1/conditions.go Outdated
Comment thread api/policies.kyverno.io/v1alpha1/conditions.go Outdated
Signed-off-by: sandert-k8s <sandert98@gmail.com>
Co-authored-by: GitHub Copilot (model Claude Sonnet 4.6) <noreply@github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@Suhani95 Suhani95 left a comment

Choose a reason for hiding this comment

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

Hi @sandert-k8s Good change overall.
However, there are no production call sites using obj.GetGeneration() yet, so most updates will still set observedGeneration = 0. In Kubernetes patterns, this field is only meaningful when it reflects the actual reconciled generation. It might be worth wiring this into controller/status paths.

Comment thread api/policies.kyverno.io/v1alpha1/conditions_test.go
Comment thread api/policies.kyverno.io/v1alpha1/conditions.go
Signed-off-by: sandert-k8s <sandert98@gmail.com>
Signed-off-by: sandert-k8s <sandert98@gmail.com>
@sandert-k8s
Copy link
Copy Markdown
Author

Hi @sandert-k8s Good change overall. However, there are no production call sites using obj.GetGeneration() yet, so most updates will still set observedGeneration = 0. In Kubernetes patterns, this field is only meaningful when it reflects the actual reconciled generation. It might be worth wiring this into controller/status paths.

Hi! Definitely :) Thats done in this PR: kyverno/kyverno#15889 . But thats still draft, because it needs this kyverno-api version to work.

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.

3 participants