Skip to content

CNF-22825: Consolidate around klog/v2#314

Open
sebrandon1 wants to merge 1 commit into
openshift:masterfrom
sebrandon1:remove_extra_loggers
Open

CNF-22825: Consolidate around klog/v2#314
sebrandon1 wants to merge 1 commit into
openshift:masterfrom
sebrandon1:remove_extra_loggers

Conversation

@sebrandon1

@sebrandon1 sebrandon1 commented Sep 22, 2025

Copy link
Copy Markdown
Member

I was messing around into some other repos and saw there was a logr being included here that wasn't widely used. To remove an extra dependency, I just consolidated the calls to logr with calls to the existing klog/v2.

Similar to:

Summary by CodeRabbit

  • Refactor
    • Standardized logging across the istio-csr controller by moving to Kubernetes klog with structured InfoS/ErrorS output, updating reconcile start/error/success messages and resource-specific reconciliation logs (certificates, deployments, RBAC, services, service accounts, network policies, and status updates).
  • Tests
    • Updated controller test utilities to remove an extra logging test dependency and improve test helper behavior for clearer failures.

@coderabbitai

coderabbitai Bot commented Sep 22, 2025

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Logging in the istio-csr controller was changed from a stored logr.Logger to direct k8s.io/klog/v2 usage. The reconciler field and its test setup were removed, and reconcile, resource, RBAC, installer, and utility logs now use klog structured logging.

Changes

Istio CSR logging migration

Layer / File(s) Summary
Controller lifecycle logging
pkg/controller/istiocsr/controller.go, pkg/controller/istiocsr/test_utils.go
Removed the reconciler logger field and test logger initialization, and switched controller-level reconcile logs and error handling to klog structured calls.
Resource reconciliation logs
pkg/controller/istiocsr/certificates.go, pkg/controller/istiocsr/deployments.go, pkg/controller/istiocsr/services.go, pkg/controller/istiocsr/serviceaccounts.go, pkg/controller/istiocsr/networkpolicies.go
Replaced resource reconciliation logs with klog.V(...).InfoS(...) while keeping the same branch structure and messages.
RBAC reconciliation logs
pkg/controller/istiocsr/rbacs.go
Switched RBAC reconciliation, status update, and role-ref modification logs to klog.ErrorS(...) and klog.V(...).InfoS(...).
Install and utility logging
pkg/controller/istiocsr/install_istiocsr.go, pkg/controller/istiocsr/utils.go
Updated installer error/success logs and utility status/annotation logs to use klog structured output.
Support imports
pkg/controller/istiocsr/*.go
Added k8s.io/klog/v2 imports where needed and removed the go-logr/testr test dependency.

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: consolidating controller logging around klog/v2.
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 No Ginkgo-style test titles were added or changed in the PR; the only touched test file is a helper, and the package’s tests use stdlib testing.
Test Structure And Quality ✅ Passed No Ginkgo tests were changed; the only test helper update adds t.Helper() and removes testr. Package tests are standard testing.T table tests, so the Ginkgo checklist is not applicable.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the diff only changes controller logging/test helpers and contains no unsupported MicroShift APIs or features.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the diff only changes controller logging/helpers and contains no It/Describe/Context/When blocks or SNO-sensitive test logic.
Topology-Aware Scheduling Compatibility ✅ Passed PASS: The commit only swaps logr calls for klog logging; no changes to replicas, affinities, nodeSelectors, tolerations, or topology logic were introduced.
Ote Binary Stdout Contract ✅ Passed Changed files only alter reconciler/test-helper logging; no main/init/TestMain/BeforeSuite stdout writes or klog redirection changes were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e specs were added; the diff only touches controller logging/helpers and contains no It/Describe/Context blocks or network assumptions.
No-Weak-Crypto ✅ Passed Touched files only switch logging; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret/token compares. RSA/x509 usage is cert-test/parsing only.
Container-Privileges ✅ Passed PR touches only controller Go files; no K8s/container manifest changes or explicit privileged settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed PASS: The PR only swaps loggers; reviewed log sites emit names, namespaces, or generic errors, with no passwords/tokens/PII/customer data added.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 97ab881 and 1508734.

⛔ Files ignored due to path filters (2)
  • vendor/github.com/go-logr/logr/testr/testr.go is excluded by !vendor/**, !**/vendor/**
  • vendor/modules.txt is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (4)
  • go.mod (1 hunks)
  • pkg/controller/istiocsr/controller.go (2 hunks)
  • pkg/controller/istiocsr/test_utils.go (2 hunks)
  • pkg/operator/setup_manager.go (2 hunks)
🔇 Additional comments (2)
go.mod (1)

93-93: Incorrect — github.com/go-logr/logr does not need to be a direct dependency.

No source file imports github.com/go-logr/logr; ctrllog.SetLogger(klog.Background()) is used in pkg/operator/setup_manager.go:36 and a klog.Logger field is used in pkg/controller/istiocsr/controller.go:51, so logr is pulled in transitively and go mod tidy correctly leaves it marked // indirect.

Likely an incorrect or invalid review comment.

pkg/operator/setup_manager.go (1)

34-37: ctrllog.SetLogger(klog.Background()) won’t compile. Use klogr.New().

SetLogger expects a logr.Logger. klog.Background() returns klog.Logger. Use the klog-backed logr.

-	// Use klog/v2 as the global logr.Logger for controller-runtime.
-	// Prefer klog.Background() over deprecated klogr.
-	ctrllog.SetLogger(klog.Background())
+	// Use klogr (klog-backed logr.Logger) for controller-runtime.
+	ctrllog.SetLogger(klogr.New())

Likely an incorrect or invalid review comment.

Comment thread pkg/controller/istiocsr/controller.go Outdated
Comment thread pkg/controller/istiocsr/test_utils.go Outdated
Comment thread pkg/operator/setup_manager.go Outdated
@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from 1508734 to c3d8740 Compare October 24, 2025 18:11
@openshift-ci

openshift-ci Bot commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

[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 mytreya-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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/controller/istiocsr/install_istiocsr.go (1)

28-30: Incomplete logging migration on line 28.

This line still uses r.log.Error while all other logging calls in this function (and across the PR) have been migrated to klog. This inconsistency should be addressed.

Apply this diff to complete the migration:

-	r.log.Error(err, "failed to reconcile network policy resources")
+	klog.ErrorS(err, "failed to reconcile network policy resources")
♻️ Duplicate comments (1)
pkg/controller/istiocsr/controller.go (1)

21-21: Past review comment no longer applicable - approach has changed.

The previous review flagged a type mismatch with storing ctrl.Log.WithName(...) in a klog.Logger field. The current implementation resolves this by removing the log field entirely and using direct klog calls throughout the controller. This approach aligns with the PR objective to consolidate around klog/v2 and remove the logr dependency.

Note: This means controller-scoped logging context (previously provided by WithName) is no longer captured, but this appears intentional for the consolidation effort.

Also applies to: 47-53

🧹 Nitpick comments (1)
pkg/controller/istiocsr/controller.go (1)

146-149: Avoid creating synthetic errors solely for logging.

Creating fmt.Errorf("invalid label format") just to satisfy klog.ErrorS's signature is awkward. Since this is a validation failure rather than an operational error, consider using klog.V(2).InfoS with a warning message instead, or pass nil as the error parameter if you prefer ErrorS.

Apply this diff to use structured info logging:

-				klog.ErrorS(fmt.Errorf("invalid label format"), "label value not in expected format",
+				klog.V(2).InfoS("label value not in expected format",
 					"labelName", IstiocsrResourceWatchLabelName,
 					"labelValue", value,
 					"resource", obj.GetName())
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 1508734 and c3d8740.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/go-logr/logr/testr/testr.go is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (11)
  • go.mod (1 hunks)
  • pkg/controller/istiocsr/certificates.go (3 hunks)
  • pkg/controller/istiocsr/controller.go (11 hunks)
  • pkg/controller/istiocsr/deployments.go (4 hunks)
  • pkg/controller/istiocsr/install_istiocsr.go (3 hunks)
  • pkg/controller/istiocsr/rbacs.go (16 hunks)
  • pkg/controller/istiocsr/serviceaccounts.go (3 hunks)
  • pkg/controller/istiocsr/services.go (3 hunks)
  • pkg/controller/istiocsr/test_utils.go (0 hunks)
  • pkg/controller/istiocsr/utils.go (3 hunks)
  • pkg/operator/setup_manager.go (2 hunks)
💤 Files with no reviewable changes (1)
  • pkg/controller/istiocsr/test_utils.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • go.mod
🔇 Additional comments (11)
pkg/operator/setup_manager.go (1)

14-14: LGTM! Past review comment addressed correctly.

The import has been updated to use the klogr adapter, and the logger initialization correctly supplies a klog/v2-backed logr.Logger to controller-runtime via klogr.New(). The explanatory comment is also helpful.

Also applies to: 33-34

pkg/controller/istiocsr/rbacs.go (1)

8-8: LGTM! Consistent migration to klog/v2 structured logging.

The logging calls have been properly migrated from r.log to klog's structured logging API (ErrorS/InfoS with key-value pairs), with appropriate verbosity levels.

Also applies to: 24-24, 66-66

pkg/controller/istiocsr/serviceaccounts.go (1)

7-7: LGTM! Logging migration aligns with the PR objective.

The file properly imports klog/v2 and uses structured logging with appropriate verbosity levels.

Also applies to: 18-18, 29-29

pkg/controller/istiocsr/deployments.go (1)

18-18: LGTM! Logging migration is complete and consistent.

The deployment reconciliation logging has been properly migrated to klog/v2 structured logging with appropriate verbosity levels.

Also applies to: 42-42, 53-53, 559-559

pkg/controller/istiocsr/certificates.go (1)

8-8: LGTM! Certificate reconciliation logging properly migrated.

The logging calls correctly use klog/v2 structured logging with appropriate verbosity levels.

Also applies to: 25-25, 36-36

pkg/controller/istiocsr/install_istiocsr.go (1)

33-33: LGTM! These logging calls have been properly migrated.

The migration to klog.ErrorS and klog.V().InfoS is consistent with the PR objective.

Also applies to: 38-38, 43-43, 48-48, 53-53, 63-63

pkg/controller/istiocsr/services.go (1)

7-7: LGTM! Service reconciliation logging properly migrated.

The logging migration to klog/v2 is consistent and uses appropriate structured logging patterns.

Also applies to: 37-37, 48-48

pkg/controller/istiocsr/utils.go (1)

17-17: LGTM! Utility function logging properly migrated.

The logging calls in status updates and instance validation have been correctly migrated to klog/v2 structured logging.

Also applies to: 53-53, 410-410

pkg/controller/istiocsr/controller.go (3)

108-119: LGTM!

The constructor correctly reflects the removal of the log field and properly initializes the remaining Reconciler fields.


217-245: LGTM!

The structured logging calls in the Reconcile function are well-formed, use appropriate verbosity levels, and provide clear context for reconciliation events.


260-322: LGTM!

The logging throughout processReconcileRequest properly uses structured logging, appropriate verbosity levels, and provides comprehensive observability for reconciliation state changes and error conditions.

@bharath-b-rh

Copy link
Copy Markdown
Contributor

/retest

@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from c3d8740 to d663ec0 Compare January 26, 2026 18:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/controller/istiocsr/install_istiocsr.go (1)

24-27: Incomplete migration causes build failure.

Line 25 still uses r.log.Error() but the log field does not exist in the Reconciler struct. This causes a build error.

Other error logging statements in this same file have already been migrated to klog.ErrorS(), but this one was missed.

🐛 Proposed fix
 	if err := r.createOrApplyNetworkPolicies(istiocsr, resourceLabels, istioCSRCreateRecon); err != nil {
-		r.log.Error(err, "failed to reconcile network policy resources")
+		klog.ErrorS(err, "failed to reconcile network policy resources")
 		return err
 	}

Note: The same issue exists in networkpolicies.go (lines 17, 64, 80, 86) which uses r.log.V().Info() and also needs migration to the klog equivalent.

🧹 Nitpick comments (1)
pkg/controller/istiocsr/rbacs.go (1)

142-143: Consider simplifying error logging pattern.

Creating inline errors with fmt.Errorf() solely for logging is unconventional. Consider logging without wrapping in an error:

-		klog.ErrorS(fmt.Errorf("error updating clusterrole name in status"), "status update error", "istiocsr", istiocsr.GetNamespace())
+		klog.V(1).InfoS("unable to determine clusterrole name for status update", "istiocsr", istiocsr.GetNamespace())

However, since this preserves existing behavior and works correctly, this is optional.

Also applies to: 232-233

@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from d663ec0 to 9f039a8 Compare April 8, 2026 19:14
@sebrandon1 sebrandon1 changed the title Consolidate around klog/v2 CNF-22825: Consolidate around klog/v2 Apr 8, 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 Apr 8, 2026
@openshift-ci-robot

openshift-ci-robot commented Apr 8, 2026

Copy link
Copy Markdown

@sebrandon1: This pull request references CNF-22825 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:

I was messing around into some other repos and saw there was a logr being included here that wasn't widely used. To remove an extra dependency, I just consolidated the calls to logr with calls to the existing klog/v2.

Similar to:

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.

@sebrandon1

Copy link
Copy Markdown
Member Author

/retest ci/prow/e2e-operator

@sebrandon1

Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from 9f039a8 to 7caf980 Compare May 6, 2026 15:13
@openshift-ci-robot

openshift-ci-robot commented May 6, 2026

Copy link
Copy Markdown

@sebrandon1: This pull request references CNF-22825 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:

I was messing around into some other repos and saw there was a logr being included here that wasn't widely used. To remove an extra dependency, I just consolidated the calls to logr with calls to the existing klog/v2.

Similar to:

Summary by CodeRabbit

  • Refactor
  • Standardized logging infrastructure across the istio-csr controller to improve code consistency and maintainability. Changes affect certificate, deployment, RBAC, service, network policy, and resource management reconciliation components.

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.

@sebrandon1

Copy link
Copy Markdown
Member Author

/retest

@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from 7caf980 to 1f36ca8 Compare May 14, 2026 19:07
@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from 1f36ca8 to e2d1fa2 Compare May 29, 2026 15:51
@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch 2 times, most recently from f34619f to bffa04a Compare June 15, 2026 16:25
@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch 2 times, most recently from a866ed7 to 226088b Compare June 24, 2026 19:51
@sebrandon1

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

Remove the logr.Logger field from the istiocsr Reconciler struct and
replace all r.log calls with direct klog/v2 structured logging calls.
This eliminates the go-logr/logr/testr dependency from the istiocsr
package and consolidates logging on the existing klog/v2 dependency.
@sebrandon1 sebrandon1 force-pushed the remove_extra_loggers branch from 226088b to ffa9f64 Compare July 6, 2026 21:17
@sebrandon1

Copy link
Copy Markdown
Member Author

Rebased onto current master (was 9 months stale). Cherry-picked the klog consolidation commit cleanly. All tests pass with 84.6% coverage on istiocsr package.

@openshift-ci

openshift-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@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.

3 participants