Skip to content

Conversation

@ziyang-lin-404
Copy link
Contributor

@ziyang-lin-404 ziyang-lin-404 commented Jan 16, 2026

Summary

  • Remove hardcoded Development: true from zap.Options for production-appropriate logging
  • Add status change detection to ScalityUIComponentExposer to avoid unnecessary API calls
  • Add GenerationChangedPredicate for ScalityUI watch to prevent unnecessary reconcile triggers

Problem

  1. Verbose debug logs in production: The Kubebuilder scaffold sets Development: true by default, causing verbose debug logs in production environments.

  2. Unnecessary status updates: ScalityUIComponentExposer was calling Status().Update() on every reconcile, even when status hadn't changed, causing:

    • Extra API Server load
    • Unnecessary etcd writes
    • Potential cascade of watch events
  3. Unnecessary reconcile triggers: ScalityUI status changes were triggering ScalityUIComponentExposer reconciliation, even though Exposer only depends on ScalityUI.Spec.Networks.

Changes

1. cmd/main.go

// Before
opts := zap.Options{
    Development: true,
}

// After
opts := zap.Options{}

2. reconcile_context.go

  • Added oldStatus field to store original status
  • Added SetOldStatus() and GetOldStatus() methods
  • Added ExtendedState interface

3. controller.go

  • Save oldStatus after fetching CR: currentState.SetOldStatus(cr.Status.DeepCopy())
  • Added GenerationChangedPredicate to ScalityUI watch

4. status.go

  • updateStatus() now compares oldStatus with current status before calling API
  • Added conditionsEqual() function to compare conditions (ignoring LastTransitionTime)

How to enable debug logging

# Development mode (console format + debug level + stacktraces)
./manager --zap-devel

# Or just adjust log level
./manager --zap-log-level=debug

# In Kubernetes deployment
spec:
  containers:
  - name: manager
    args:
    - --zap-devel

Copilot AI review requested due to automatic review settings January 16, 2026 15:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the ScalityUIComponentExposer controller to reduce unnecessary reconciliation triggers and API calls, and disables verbose debug logging in production. The changes improve performance by preventing excessive API server load and etcd writes.

Changes:

  • Removed hardcoded Development: true from zap logging configuration to enable production-appropriate logging
  • Added status change detection to skip unnecessary status updates when conditions haven't changed
  • Added GenerationChangedPredicate to ScalityUI watch to prevent reconciliation on status-only changes

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
cmd/main.go Removed Development mode from default zap options to reduce verbose logging
internal/controller/scalityuicomponentexposer/reconcile_context.go Added oldStatus tracking and ExtendedState interface for status comparison
internal/controller/scalityuicomponentexposer/controller.go Added oldStatus capture and GenerationChangedPredicate for ScalityUI watches
internal/controller/scalityuicomponentexposer/status.go Implemented status change detection and conditionsEqual helper function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove hardcoded `Development: true` from zap.Options to use production
  logging configuration by default (JSON format, info level)
- Add status change detection to avoid unnecessary API calls when status
  conditions haven't changed
- Add GenerationChangedPredicate for ScalityUI watch to prevent reconcile
  triggers from ScalityUI status changes

To enable debug logging when needed:
- Use `--zap-devel` flag for development mode
- Use `--zap-log-level=debug` for debug level only
@ziyang-lin-404 ziyang-lin-404 force-pushed the improvement/reduce-excessive-reconciliation-and-logging branch from 24a2087 to d326cb1 Compare January 16, 2026 15:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@ziyang-lin-404 ziyang-lin-404 merged commit 0aec4c4 into main Jan 16, 2026
2 checks passed
@ziyang-lin-404 ziyang-lin-404 deleted the improvement/reduce-excessive-reconciliation-and-logging branch January 16, 2026 16:25
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.

3 participants