Skip to content

CM-1038: Replace istiocsr type-specific decoders with generic DecodeObjBytes#418

Open
sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
sebrandon1:replace-decoders-with-generic
Open

CM-1038: Replace istiocsr type-specific decoders with generic DecodeObjBytes#418
sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
sebrandon1:replace-decoders-with-generic

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented May 6, 2026

Summary

  • Remove 8 type-specific decode*ObjBytes functions from the istiocsr package (~95 lines) and replace all 22 call sites with the existing generic common.DecodeObjBytes[T] helper
  • Cache the ServiceAccount name at init time to avoid redundant YAML deserialization on every reconcile cycle
  • Aligns the istiocsr package with the pattern already used by the trustmanager package

Test plan

  • Unit tests pass (go test ./pkg/controller/istiocsr/...)
  • Build succeeds (go build ./pkg/controller/istiocsr/)
  • No new lint issues introduced
  • CI checks pass

Jira: https://redhat.atlassian.net/browse/CM-1038

Summary by CodeRabbit

Release Notes

  • Refactor
    • Consolidated object decoding logic across multiple IstioCSR controller components to use a unified decoder.
    • Introduced asset-based caching for service account name retrieval.

…bjBytes

Remove 8 type-specific decode*ObjBytes functions from the istiocsr
package and replace all call sites with the existing generic
common.DecodeObjBytes[T] helper, matching the pattern already used
by the trustmanager package.

Cache the ServiceAccount name at init time to avoid redundant YAML
deserialization on every reconcile cycle.
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 6, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented May 6, 2026

@sebrandon1: This pull request references CM-1038 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 task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Remove 8 type-specific decode*ObjBytes functions from the istiocsr package (~95 lines) and replace all 22 call sites with the existing generic common.DecodeObjBytes[T] helper
  • Cache the ServiceAccount name at init time to avoid redundant YAML deserialization on every reconcile cycle
  • Aligns the istiocsr package with the pattern already used by the trustmanager package

Test plan

  • Unit tests pass (go test ./pkg/controller/istiocsr/...)
  • Build succeeds (go build ./pkg/controller/istiocsr/)
  • No new lint issues introduced
  • CI checks pass

Jira: https://redhat.atlassian.net/browse/CM-1038

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
Copy Markdown

coderabbitai Bot commented May 6, 2026

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: 7215de7d-d58d-452f-9ceb-85ae4e621e74

📥 Commits

Reviewing files that changed from the base of the PR and between a2e7514 and b622911.

📒 Files selected for processing (7)
  • pkg/controller/istiocsr/certificates.go
  • pkg/controller/istiocsr/deployments.go
  • pkg/controller/istiocsr/rbacs.go
  • pkg/controller/istiocsr/serviceaccounts.go
  • pkg/controller/istiocsr/services.go
  • pkg/controller/istiocsr/test_utils.go
  • pkg/controller/istiocsr/utils.go

Walkthrough

This PR refactors the IstioCSR controller to consolidate object decoding across seven files by replacing multiple specific helper functions with a single generic common.DecodeObjBytes utility. It also introduces caching of the ServiceAccount name to avoid repeated decoding during initialization.

Changes

Decoding Consolidation

Layer / File(s) Summary
Caching foundation
pkg/controller/istiocsr/utils.go
Adds cachedServiceAccountName variable initialized during init() by decoding an embedded ServiceAccount asset; removes ~90 lines of unused code.
Core object decoding
pkg/controller/istiocsr/certificates.go, pkg/controller/istiocsr/deployments.go, pkg/controller/istiocsr/serviceaccounts.go, pkg/controller/istiocsr/services.go
All getter functions replace bespoke decode helpers with common.DecodeObjBytes[T](codecs, SchemeGroupVersion, asset) pattern.
RBAC decoding & caching
pkg/controller/istiocsr/rbacs.go
All RBAC resource getters (ClusterRole, ClusterRoleBinding, Role, RoleBinding, and their Leases variants) switch to generic common.DecodeObjBytes; createOrApplyRBACResource now uses cachedServiceAccountName instead of inline decoding.
Test utilities
pkg/controller/istiocsr/test_utils.go
All test helper functions updated to use generic common.DecodeObjBytes[T] for Certificate, ClusterRole, ClusterRoleBinding, Deployment, Role, RoleBinding, Service, and ServiceAccount; adds import for common package.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (11 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: replacing eight type-specific decoder functions with a generic DecodeObjBytes helper across the istiocsr package.
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 Check applies only to Ginkgo tests. istiocsr uses standard Go tests. PR modified no test files. No test names contain dynamic content.
Test Structure And Quality ✅ Passed PR modifies production code and test_utils.go (test helper utility). No Ginkgo test files were modified. The custom check for Ginkgo test quality is not applicable to this PR.
Microshift Test Compatibility ✅ Passed PR does not add any new Ginkgo e2e tests. Changes are limited to controller code refactoring and unit test helpers. No e2e test code introduced, so check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests are being added. This PR refactors the istiocsr controller by replacing type-specific decoders with generic helpers. The check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed This PR refactors decoder functions and introduces no new scheduling constraints. No manifests are modified in ways that affect topology compatibility. Only OS-agnostic nodeSelector exists.
Ote Binary Stdout Contract ✅ Passed No stdout violations found. Init block safely adds schemes and caches ServiceAccount name. No fmt.Print/println/klog writes detected.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR adds no new Ginkgo e2e tests. It refactors unit test helpers in the controller package using a generic decoder. Check not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot requested review from bharath-b-rh and mytreya-rh May 6, 2026 16:16
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 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 bharath-b-rh 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
Contributor

openshift-ci Bot commented May 6, 2026

@sebrandon1: 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