Skip to content

CNF-23094: Propagate context through pkg/utils public API#1187

Open
sebrandon1 wants to merge 1 commit into
ComplianceAsCode:masterfrom
sebrandon1:CNF-23094/context-propagation-pkg-utils
Open

CNF-23094: Propagate context through pkg/utils public API#1187
sebrandon1 wants to merge 1 commit into
ComplianceAsCode:masterfrom
sebrandon1:CNF-23094/context-propagation-pkg-utils

Conversation

@sebrandon1
Copy link
Copy Markdown

@sebrandon1 sebrandon1 commented Apr 23, 2026

Summary

  • Add ctx context.Context parameter to all pkg/utils functions that make Kubernetes API calls: GetObjectIfFound, ValidatePriorityClassExist, HaveOutdatedRemediations, NewRuleMetadataCache, and GetKCFromMC
  • Replace context.TODO() with the passed context in those functions
  • Update all callers across 8 packages to pass context (using context.TODO() temporarily where the caller does not yet have ctx available)
  • Update unit tests to pass context.Background()

Context

This is the first PR in a package-by-package effort to replace context.TODO() with proper context propagation across the compliance-operator (CNF-23094). Starting with pkg/utils since it is the smallest package (5 instances) and its exported functions are called by many other packages.

Callers that do not yet have ctx in their function signatures temporarily use context.TODO() — those will be updated in subsequent per-package PRs.

Test plan

  • make vet passes
  • Unit tests updated and passing locally
  • CI e2e tests

@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

openshift-ci-robot commented Apr 23, 2026

@sebrandon1: This pull request references CNF-23094 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 "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Add ctx context.Context parameter to all pkg/utils functions that make Kubernetes API calls: GetObjectIfFound, ValidatePriorityClassExist, HaveOutdatedRemediations, NewRuleMetadataCache, and GetKCFromMC
  • Replace context.TODO() with the passed context in those functions
  • Update all callers across 8 packages to pass context (using context.TODO() temporarily where the caller does not yet have ctx available)
  • Update unit tests to pass context.Background()

Context

This is the first PR in a package-by-package effort to replace context.TODO() with proper context propagation across the compliance-operator (CNF-23094). Starting with pkg/utils since it is the smallest package (5 instances) and its exported functions are called by many other packages.

Callers that do not yet have ctx in their function signatures temporarily use context.TODO() — those will be updated in subsequent per-package PRs.

Test plan

  • make vet passes
  • Unit tests updated and passing locally
  • CI e2e tests

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.

@openshift-ci openshift-ci Bot requested review from jhrozek and taimurhafeez April 23, 2026 16:36
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 23, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

openshift-ci Bot commented Apr 23, 2026

Hi @sebrandon1. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@github-actions
Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1187-d9f19257259c35eaa8b3c6b6c9678a621c86733d

Replace context.TODO() with a ctx parameter in all pkg/utils
functions that make Kubernetes API calls. Callers that already
have context available now pass it through; remaining callers
use context.TODO() temporarily until their packages are updated.

Additionally:
- Wire backoff.WithContext so retries in GetObjectIfFound
  respect context cancellation
- Hoist ValidatePriorityClassExist out of the per-node loop
  in nodeScanTypeHandler.createScanWorkload to avoid redundant
  API calls
@sebrandon1 sebrandon1 force-pushed the CNF-23094/context-propagation-pkg-utils branch from d9f1925 to 8a46dc4 Compare April 23, 2026 16:44
@github-actions
Copy link
Copy Markdown

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1187-8a46dc4f29aead1a2514a0cbaeb7bc0deb4beab7

@sebrandon1
Copy link
Copy Markdown
Author

@yuumasato Could you please /ok-to-test this PR when you get a chance? Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants