Skip to content

NO-JIRA: Guard nil dereference in CachedConfigMapGetter and CachedSecretGetter - #2378

Open
sanchezl wants to merge 1 commit into
openshift:masterfrom
sanchezl:fix-cached-getter-nil-panic
Open

NO-JIRA: Guard nil dereference in CachedConfigMapGetter and CachedSecretGetter#2378
sanchezl wants to merge 1 commit into
openshift:masterfrom
sanchezl:fix-cached-getter-nil-panic

Conversation

@sanchezl

@sanchezl sanchezl commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • CachedConfigMapGetter.ConfigMaps() and CachedSecretGetter.Secrets() chain method calls on the return value of InformersFor(), which returns nil for unregistered namespaces. This produces an unhelpful nil-pointer panic with no diagnostic context.
  • Added a nil check before chaining, matching the pattern already used by the lister wrappers in informers.go (configMapLister.ConfigMaps, secretLister.Secrets, podLister.Pods) which panic with a message identifying the missing namespace.
  • Added unit tests for the new behavior.

Test plan

  • go test ./pkg/operator/v1helpers/... passes
  • make verify passes

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of configuration and secret lookups for namespaces that are not registered.
    • Missing namespaces now produce a clear, actionable error instead of an ambiguous failure.
    • Registered namespaces continue to retrieve configuration and secret data as expected.
  • Tests

    • Added coverage for missing and registered namespace scenarios, including multiple namespace configurations.

CachedConfigMapGetter.ConfigMaps() and CachedSecretGetter.Secrets()
chain method calls on the return value of InformersFor(), which returns
nil for unregistered namespaces. This produces an unhelpful nil-pointer
panic with no diagnostic context.

Add a nil check before chaining, matching the pattern already used by
the lister wrappers in informers.go (configMapLister.ConfigMaps, etc.)
which panic with a message identifying the missing namespace.
@sanchezl sanchezl changed the title Guard nil dereference in CachedConfigMapGetter and CachedSecretGetter NO-JIRA: Guard nil dereference in CachedConfigMapGetter and CachedSecretGetter Jul 24, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 24, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@sanchezl: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

  • CachedConfigMapGetter.ConfigMaps() and CachedSecretGetter.Secrets() chain method calls on the return value of InformersFor(), which returns nil for unregistered namespaces. This produces an unhelpful nil-pointer panic with no diagnostic context.
  • Added a nil check before chaining, matching the pattern already used by the lister wrappers in informers.go (configMapLister.ConfigMaps, secretLister.Secrets, podLister.Pods) which panic with a message identifying the missing namespace.
  • Added unit tests for the new behavior.

Test plan

  • go test ./pkg/operator/v1helpers/... passes
  • make verify passes

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

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 700249ee-f65a-47ad-b293-8bb6f69c8a26

📥 Commits

Reviewing files that changed from the base of the PR and between e4053a9 and 350fdfb.

📒 Files selected for processing (2)
  • pkg/operator/v1helpers/core_getters.go
  • pkg/operator/v1helpers/core_getters_test.go

Walkthrough

The cached ConfigMap and Secret getters now validate namespace informer availability and panic with a formatted missing-namespace message. Tests cover missing and registered namespaces, multiple fake informer configurations, and exact panic-message matching.

Changes

Cached getter validation

Layer / File(s) Summary
Add namespace informer guards
pkg/operator/v1helpers/core_getters.go
ConfigMap and Secret getters check for a missing namespace informer before creating the corresponding lister and panic with the namespace-specific message.
Test registered and missing namespaces
pkg/operator/v1helpers/core_getters_test.go
Tests verify panic messages for unregistered namespaces and successful calls for registered namespaces, including table-driven fake informer coverage and a panic assertion helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding nil guards to CachedConfigMapGetter and CachedSecretGetter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The added test names are static and descriptive; no titles embed generated, date, or environment-specific values.
Test Structure And Quality ✅ Passed Not a Ginkgo suite; the new unit tests are table-driven, isolated, and include a panic-message helper with no cluster ops or timeouts needed.
Microshift Test Compatibility ✅ Passed Added tests are standard unit tests with fake clients; no Ginkgo e2e tests or MicroShift-unsupported APIs/features were introduced.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The added tests are plain Go unit tests with fake clientsets/informers, not Ginkgo e2e specs, and they make no multi-node or SNO-sensitive assumptions.
Topology-Aware Scheduling Compatibility ✅ Passed Only namespace informer lookup and tests changed; no manifests, replicas, affinity, node selectors, or topology logic were introduced.
Ote Binary Stdout Contract ✅ Passed No stdout writes appear in any process-level code; the PR only changes getter logic and standard unit tests, with no main/init/TestMain/fixture setup output.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added tests are plain Go unit tests, not Ginkgo e2e specs, and they contain no IPv4 or external-connectivity assumptions.
No-Weak-Crypto ✅ Passed Touched files only add namespace nil-checks and tests; no weak crypto, custom crypto, or secret/token comparisons were introduced.
Container-Privileges ✅ Passed PR only changes Go getters/tests; no container privilege settings or manifests were added in the diff.
No-Sensitive-Data-In-Logs ✅ Passed No new logging of sensitive data found; added panics only include the namespace name, and tests don't log secrets or PII.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
openshift-ci Bot requested review from deads2k and p0lyn0mial July 24, 2026 20:05
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sanchezl
Once this PR has been reviewed and has the lgtm label, please assign bertinatto for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@sanchezl: all tests passed!

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

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