Skip to content

fix(etcd): initialize ResourceVersion in NewObjectStoreCluster (#352)#353

Open
arpitjain099 wants to merge 2 commits into
kyverno:mainfrom
arpitjain099:chore/clusterstore-nil-init
Open

fix(etcd): initialize ResourceVersion in NewObjectStoreCluster (#352)#353
arpitjain099 wants to merge 2 commits into
kyverno:mainfrom
arpitjain099:chore/clusterstore-nil-init

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Jun 28, 2026

Copy link
Copy Markdown

Fixes #352.

Creating any cluster-scoped report against the etcd backend panics the apiserver with a nil pointer dereference. The cluster store wraps an objectStoreNamespaced whose embedded *versioning.ResourceVersion is left nil, so the first UseResourceVersion() call during Create dereferences nil. The stack lands at versioning/versioning.go:33 via etcd/store.go:223, which matches the trace in the issue. The namespaced constructor already sets this field; the cluster one just forgot. Fix is to add ResourceVersion: versioning.NewVersioning() in NewObjectStoreCluster, same as the namespaced path.

Added a small regression test that calls NewObjectStoreCluster(...).UseResourceVersion() (a nil KV client is fine, that path only touches the in-memory versioning struct). It panics before the fix and passes after.

@aerosouund you said on the issue you'd leave a fix to whoever picked it up, so here's one. Happy to move or rename the test if you'd prefer it elsewhere. Thanks!

The cluster store's inner objectStoreNamespaced literal left the embedded
*versioning.ResourceVersion nil, so the first UseResourceVersion call made
during Create of a cluster-scoped report dereferenced a nil pointer and
panicked at versioning.go:33. This crashed the apiserver request handler for
any ClusterEphemeralReport/ClusterPolicyReport/ClusterReport on the etcd
backend. NewObjectStoreNamespaced already sets this field; mirror it in the
cluster constructor and add a regression test.

Fixes kyverno#352

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Comment thread pkg/storage/etcd/store_test.go Outdated
// NewObjectStoreCluster left the embedded *versioning.ResourceVersion nil. The
// first call to UseResourceVersion (made during Create of a cluster-scoped
// report) then dereferenced that nil pointer and panicked, taking down the
// apiserver request handler. See kyverno/reports-server#352.

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.

That comment is unneeded. Its fair to only leave the test and ensure the fix is present rather than leave the whole context in the comment on the test

@aerosouund

Copy link
Copy Markdown
Member

@arpitjain099
Thanks for working on this. left a small comment

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.05%. Comparing base (7f1511e) to head (0ac02c9).

Additional details and impacted files
@@           Coverage Diff            @@
##            main    #353      +/-   ##
========================================
+ Coverage   0.00%   0.05%   +0.05%     
========================================
  Files         33      33              
  Lines      19095   19096       +1     
========================================
+ Hits           0      11      +11     
+ Misses     19095   19085      -10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ion test

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099

Copy link
Copy Markdown
Author

Removed the comment, the test and fix are unchanged. Thanks!

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.

Creating clustered reports against the etcd backend results in a nil pointer dereference

2 participants