Skip to content

🌱 Add unit tests for SetupPullSecretCache - #3219

Open
andretorresdg wants to merge 1 commit into
operator-framework:mainfrom
andretorresdg:test-pullsecretcache
Open

andretorresdg wants to merge 1 commit into
operator-framework:mainfrom
andretorresdg:test-pullsecretcache

Conversation

@andretorresdg

@andretorresdg andretorresdg commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

pullsecretcache.SetupPullSecretCache is called from both cmd/operator-controller and cmd/catalogd and decides which ServiceAccounts and Secrets the managers cache, and therefore which pull secrets they can read. It had no tests.

This adds a table-driven test for the three configurations:

  • no global pull secret: all Secrets in the service account namespace;
  • global pull secret in the service account namespace: still all Secrets there (the global secret must not narrow that namespace down to one name);
  • global pull secret in another namespace: all Secrets in the service account namespace, plus only the named Secret in the other namespace.

It also checks that only the operator's own ServiceAccount is cached (by name) and that existing ByObject entries are kept. Selectors are compared as values, not with String(), because labels.Everything()/labels.Nothing() (and the fields equivalents) both render as "".

Tests only, no production code changes.

How I tested

  • go test -race -cover ./internal/shared/util/pullsecretcache/: passes, 100% statement coverage.
  • Mutation check: 8 hand-made mutants of pullsecretcache.go (dropping the same-namespace guard, wrong name or namespace for the global secret, dropping the ServiceAccount name filter, Nothing() selectors, removing the Secret entry), all caught by the test.
  • go tool golangci-lint run ./internal/shared/util/pullsecretcache/...: 0 issues.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Summary by CodeRabbit

  • Tests
    • Added coverage for pull-secret cache setup with no global secret, a secret in the service-account namespace, and a secret in another namespace.

SetupPullSecretCache decides which ServiceAccounts and Secrets the
operator-controller and catalogd managers cache, and therefore which
pull secrets they can read, but it had no tests.

Cover the three configurations: no global pull secret, a global pull
secret in the service account namespace (which must not narrow the
"all Secrets" cache of that namespace to one name), and a global pull
secret in another namespace (cached by name only). Also check that
only the operator's own ServiceAccount is cached and that unrelated
ByObject entries are preserved.

Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
@netlify

netlify Bot commented Dec 1, 2026

Copy link
Copy Markdown

👷 Deploy request for olmv1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c65b9e5

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Tests were added for SetupPullSecretCache. They cover cases with no global pull secret, a pull secret in the service-account namespace, and a pull secret in another namespace.

Changes: Pull secret cache tests

Layer / File(s) Summary
Cache configuration tests
internal/shared/util/pullsecretcache/pullsecretcache_test.go
Test helpers locate cache entries and compare selectors. Table-driven tests check existing ConfigMap entries, service-account selection, and Secret namespace and field selectors across three cases.

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

Change: Other

Suggested reviewers: tmshort

Merge Risk: Minimal · up to c65b9

This change adds tests for pull secret cache configuration and does not alter runtime behavior. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "🌱 Add unit tests for SetupPullSecretCache" matches the main change. The PR adds only a test function, TestSetupPullSecretCache, for pullsecretcache.SetupPullSecretCache, and makes no produc…
Description check Passed The description covers the purpose and motivation, the three tested configurations, the ServiceAccount name check, the ByObject preservation check, and the author-reported test, mutation, and lint res…
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.
Full details: Title check

Explanation

The title "🌱 Add unit tests for SetupPullSecretCache" matches the main change. The PR adds only a test function, TestSetupPullSecretCache, for pullsecretcache.SetupPullSecretCache, and makes no production code changes. The 🌱 prefix follows the repository's 'other' icon convention.

Full details: Description check

Explanation

The description covers the purpose and motivation, the three tested configurations, the ServiceAccount name check, the ByObject preservation check, and the author-reported test, mutation, and lint results. It follows the template's Description section and includes the Reviewer Checklist. The checklist items remain unchecked, and the description does not link a related GitHub issue. These gaps are minor and do not affect the assessment.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b427e11-2bb3-4607-ac3f-a99ac96dba02
Commits

Reviewing files that changed from the base of the PR and between 4cab3cf and c65b9e5.

Files selected for processing: 1

  • internal/shared/util/pullsecretcache/pullsecretcache_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@openshift-ci
openshift-ci Bot requested review from dtfranz and perdasilva December 1, 2026 15:55
@openshift-ci

openshift-ci Bot commented Dec 1, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign grokspawn 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

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.

1 participant