Skip to content

Comments

CCXDEV-15829: subscription gathering#1235

Open
opokornyy wants to merge 2 commits intoopenshift:masterfrom
opokornyy:CCXDEV-15829-subscription-cr
Open

CCXDEV-15829: subscription gathering#1235
opokornyy wants to merge 2 commits intoopenshift:masterfrom
opokornyy:CCXDEV-15829-subscription-cr

Conversation

@opokornyy
Copy link
Contributor

This PR implements a new gatherer that collects data from all Subscription CRs present in the cluster.

Categories

  • Bugfix
  • Data Enhancement
  • Feature
  • Backporting
  • Others (CI, Infrastructure, Documentation)

Sample Archive

  • docs/insights-archive-sample/config/subscriptions/community-kubevirt-hyperconverged.json

Documentation

  • None

Unit Tests

  • pkg/gatherers/clusterconfig/gather_subscription_test.go

Privacy

Yes. There are no sensitive data in the newly collected information.

Changelog

Breaking Changes

No

References

CCXDEV-15829

This commit implements a new gatherer that
collects data from all Subscription CRs
present in the cluster.

Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
Signed-off-by: Ondrej Pokorny <opokorny@redhat.com>
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Feb 19, 2026
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Feb 19, 2026

@opokornyy: This pull request references CCXDEV-15829 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

This PR implements a new gatherer that collects data from all Subscription CRs present in the cluster.

Categories

  • Bugfix
  • Data Enhancement
  • Feature
  • Backporting
  • Others (CI, Infrastructure, Documentation)

Sample Archive

  • docs/insights-archive-sample/config/subscriptions/community-kubevirt-hyperconverged.json

Documentation

  • None

Unit Tests

  • pkg/gatherers/clusterconfig/gather_subscription_test.go

Privacy

Yes. There are no sensitive data in the newly collected information.

Changelog

Breaking Changes

No

References

CCXDEV-15829

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Walkthrough

Introduces operator subscription gathering capability to the cluster configuration gatherer. Adds a sample Subscription manifest, implements the GatherSubscription method to collect subscription resources across namespaces via the dynamic client, registers the gatherer function, and includes comprehensive test coverage.

Changes

Cohort / File(s) Summary
Sample Configuration
docs/insights-archive-sample/config/subscriptions/community-kubevirt-hyperconverged.json
Adds a new Subscription manifest defining the kubevirt hyperconverged operator with automatic installation and updates from the community operators marketplace.
Subscription Gatherer Implementation
pkg/gatherers/clusterconfig/clusterconfig_gatherer.go, pkg/gatherers/clusterconfig/gather_subscription.go
Registers the new subscriptions gatherer function and implements GatherSubscription method that retrieves all Operator Subscriptions across namespaces via the dynamic client, removes status fields from each resource, and returns records with names prefixed as config/subscriptions/.
Subscription Gatherer Tests
pkg/gatherers/clusterconfig/gather_subscription_test.go
Adds comprehensive test coverage for the gatherSubscriptions function, validating correct record counts, proper naming, status field removal while preserving essential fields (apiVersion, kind, metadata, spec), and behavior across multiple namespaces and empty scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from BaiyangZhou and ncaak February 19, 2026 09:52
@openshift-ci
Copy link

openshift-ci bot commented Feb 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: opokornyy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/gatherers/clusterconfig/gather_subscription.go`:
- Around line 64-71: The record path for collected Subscriptions uses only
rc.GetName() which can collide across namespaces; update the record creation in
the loop that iterates subscriptionList.Items so the Name uses both namespace
and name (e.g., fmt.Sprintf("config/subscriptions/%s/%s", rc.GetNamespace(),
rc.GetName())) when constructing the record.Record for
record.ResourceMarshaller{Resource: &subscriptionList.Items[i]}. Also add a
unit/integration test that creates two Subscription objects with the same name
in different namespaces and confirms both records are produced with distinct
paths to prevent overwrite/collision.

Comment on lines +64 to +71
for i, rc := range subscriptionList.Items {
// Drop status field that is not needed
delete(subscriptionList.Items[i].Object, "status")

records = append(records, record.Record{
Name: fmt.Sprintf("config/subscriptions/%s", rc.GetName()),
Item: record.ResourceMarshaller{Resource: &subscriptionList.Items[i]},
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check naming conventions for config/subscriptions and other namespaced resources
echo "=== Looking for config/subscriptions references ==="
rg -n --type=go -C2 'config/subscriptions' 

echo -e "\n=== Checking for other namespaced resource patterns ==="
rg -n --type=go 'config/[a-z]+/.*GetNamespace' 

echo -e "\n=== Looking for test files related to gather_subscription ==="
fd -e "test" | xargs grep -l "gather_subscription\|config/subscriptions" 2>/dev/null

echo -e "\n=== Checking if other resources include namespace in path ==="
rg -n --type=go 'GetNamespace.*fmt.Sprintf\|fmt.Sprintf.*GetNamespace' pkg/gatherers/clusterconfig

Repository: openshift/insights-operator

Length of output: 1839


🏁 Script executed:

#!/bin/bash
# Examine the gather_subscription.go file to understand the context better
echo "=== Full context of gather_subscription.go around lines 64-71 ==="
cat -n pkg/gatherers/clusterconfig/gather_subscription.go | sed -n '55,80p'

echo -e "\n=== Check the resource type definition ==="
rg -n "type.*Subscription" --type=go | head -20

Repository: openshift/insights-operator

Length of output: 808


🏁 Script executed:

#!/bin/bash
# Check if Subscriptions are namespace-scoped or cluster-scoped
echo "=== Looking for Subscription resource metadata/schema ==="
rg -n "Subscription" --type=go pkg/gatherers/clusterconfig/ -A5 -B5 | head -60

echo -e "\n=== Check for any test files that might validate the path format ==="
find . -name "*subscription*test*" -o -name "*test*subscription*" 2>/dev/null | head -10

Repository: openshift/insights-operator

Length of output: 5007


🏁 Script executed:

#!/bin/bash
# Check how the subscriptions are fetched - cluster or namespace scoped
echo "=== Full gatherSubscriptions function ==="
cat -n pkg/gatherers/clusterconfig/gather_subscription.go | sed -n '46,75p'

echo -e "\n=== Check dynamic client usage for list parameters ==="
rg -n "\.List\(" pkg/gatherers/clusterconfig/gather_subscription.go -A3 -B3

Repository: openshift/insights-operator

Length of output: 1390


🏁 Script executed:

#!/bin/bash
# Compare with other namespace-scoped resources to see naming patterns
echo "=== Look for other gatherers that handle namespaced resources ==="
ls -la pkg/gatherers/clusterconfig/gather_*.go | head -20

echo -e "\n=== Check for patterns in other gatherers with namespace ==="
rg -n "GetNamespace()" pkg/gatherers/clusterconfig/ --type=go | head -20

echo -e "\n=== Examine one example: check gather_pod or similar ==="
rg -n "config/.*GetNamespace\|config/.*fmt.Sprintf.*namespace" pkg/gatherers/clusterconfig/ --type=go

Repository: openshift/insights-operator

Length of output: 4789


🏁 Script executed:

#!/bin/bash
# Check what the test expects for the record path
echo "=== Check test expectations for path format ==="
cat -n pkg/gatherers/clusterconfig/gather_subscription_test.go | sed -n '80,150p'

echo -e "\n=== Look for assertions on record names ==="
rg -n "config/subscriptions\|Record{" pkg/gatherers/clusterconfig/gather_subscription_test.go -A3 -B1

Repository: openshift/insights-operator

Length of output: 2888


🏁 Script executed:

#!/bin/bash
# Check the test assertions more carefully
echo "=== Full test assertions section ==="
cat -n pkg/gatherers/clusterconfig/gather_subscription_test.go | sed -n '147,200p'

echo -e "\n=== Check if test validates record names ==="
grep -n "expectedRecordName\|assert.*Name" pkg/gatherers/clusterconfig/gather_subscription_test.go

Repository: openshift/insights-operator

Length of output: 2772


🏁 Script executed:

#!/bin/bash
# Check if the two subscriptions in the test have the same name or different names
echo "=== Check subscription names and namespaces in test YAML ==="
cat -n pkg/gatherers/clusterconfig/gather_subscription_test.go | sed -n '21,75p'

Repository: openshift/insights-operator

Length of output: 2143


Include namespace in Subscription record path to prevent collisions.

The code collects Subscriptions from all namespaces but uses only the Subscription name in the archive path. If two namespaces contain the same Subscription name, records will collide and data will be lost. This pattern is inconsistent with how other namespace-scoped resources are handled throughout the codebase (e.g., config/pdbs/{namespace}/{name}, config/logging/{namespace}/{name}, config/machines/{namespace}/{name}).

Update line 69 to include namespace in the path and add test coverage for same-named Subscriptions across different namespaces.

Proposed fix
-			Name: fmt.Sprintf("config/subscriptions/%s", rc.GetName()),
+			Name: fmt.Sprintf("config/subscriptions/%s/%s", rc.GetNamespace(), rc.GetName()),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for i, rc := range subscriptionList.Items {
// Drop status field that is not needed
delete(subscriptionList.Items[i].Object, "status")
records = append(records, record.Record{
Name: fmt.Sprintf("config/subscriptions/%s", rc.GetName()),
Item: record.ResourceMarshaller{Resource: &subscriptionList.Items[i]},
})
for i, rc := range subscriptionList.Items {
// Drop status field that is not needed
delete(subscriptionList.Items[i].Object, "status")
records = append(records, record.Record{
Name: fmt.Sprintf("config/subscriptions/%s/%s", rc.GetNamespace(), rc.GetName()),
Item: record.ResourceMarshaller{Resource: &subscriptionList.Items[i]},
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/gatherers/clusterconfig/gather_subscription.go` around lines 64 - 71, The
record path for collected Subscriptions uses only rc.GetName() which can collide
across namespaces; update the record creation in the loop that iterates
subscriptionList.Items so the Name uses both namespace and name (e.g.,
fmt.Sprintf("config/subscriptions/%s/%s", rc.GetNamespace(), rc.GetName())) when
constructing the record.Record for record.ResourceMarshaller{Resource:
&subscriptionList.Items[i]}. Also add a unit/integration test that creates two
Subscription objects with the same name in different namespaces and confirms
both records are produced with distinct paths to prevent overwrite/collision.

@openshift-ci
Copy link

openshift-ci bot commented Feb 19, 2026

@opokornyy: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/lint 1976451 link true /test lint
ci/prow/e2e-gcp-ovn-techpreview 1976451 link true /test e2e-gcp-ovn-techpreview

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants