Skip to content

Conversation

@Isteb4k
Copy link
Contributor

@Isteb4k Isteb4k commented Nov 1, 2025

Description

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

@Isteb4k Isteb4k self-assigned this Nov 1, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 1, 2025

Reviewer's Guide

This pull request refactors the VirtualMachine controller architecture to improve performance by introducing a new 'supervm' controller that dynamically manages per-namespace VM controllers, optimizes logger instantiation, and restructures related code and tests accordingly.

Sequence diagram for dynamic creation of per-namespace VM controllers

sequenceDiagram
  participant S as "supervm Controller"
  participant Q as "Request Queue"
  participant VM as "Namespaced VM Controller"
  participant K as "Kubernetes Manager"
  actor U as "User"

  U->>S: Create/Update VirtualMachine in namespace N
  S->>Q: Push reconcile.Request for namespace N
  S->>S: Check if controller for N exists
  alt Controller for N does not exist
    S->>K: Setup new Namespaced VM Controller for N
    S->>VM: Pass queue for namespace N
    S->>Q: Store queue for N
  end
  S->>Q: Push reconcile.Request to queue for N
  Q->>VM: Forward reconcile.Request
  VM->>K: Reconcile VirtualMachine
Loading

Class diagram for logger instantiation refactor

classDiagram
  class Logger {
    +With(...)
  }
  class Factory {
    +func(controllerName string) *Logger
  }
  Logger <|-- Factory
  class logFactory_Factory {
    +func(controllerName string) *Logger
  }
  logFactory_Factory --|> Logger
Loading

Class diagram for supervm Reconciler and Handler

classDiagram
  class Reconciler {
    -client: Client
    -handlers: []Handler
    +SetupController(...)
    +Reconcile(...)
    +factory()
    +statusGetter(obj)
  }
  class Handler {
    +Handle(ctx, vm)
  }
  Reconciler --> Handler : uses
Loading

File-Level Changes

Change Details Files
Introduced a new 'supervm' controller to manage per-namespace VM controllers dynamically, delegating reconciliation to namespaced controllers via a semaphore handler.
  • Added 'supervm' package with controller, reconciler, internal handlers, and watcher logic.
  • Implemented dynamic instantiation of per-namespace VM controllers using a semaphore handler and request queue.
  • Moved and adapted webhook, defaulter, and validator logic for the new controller structure.
images/virtualization-artifact/cmd/virtualization-controller/main.go
images/virtualization-artifact/pkg/controller/supervm/vm_controller.go
images/virtualization-artifact/pkg/controller/supervm/vm_reconciler.go
images/virtualization-artifact/pkg/controller/supervm/internal/semaphore.go
images/virtualization-artifact/pkg/controller/supervm/internal/defaulter/virtual_machine_class_name.go
images/virtualization-artifact/pkg/controller/supervm/internal/watcher/super_watcher.go
Refactored the original 'vm' controller to support unmanaged, per-namespace operation and decoupled its setup from the main controller loop.
  • Modified 'vm_controller.go' to accept namespace and queue parameters, enabling dynamic instantiation.
  • Replaced direct resource watches with a custom source for request injection from the supervm controller.
  • Removed metrics and webhook setup from the per-namespace controller.
images/virtualization-artifact/pkg/controller/vm/vm_controller.go
images/virtualization-artifact/pkg/controller/vm/vm_reconciler.go
Centralized and optimized logger instantiation using a factory pattern for controller loggers.
  • Replaced repeated logger construction with a shared logger factory function.
  • Updated all controller initializations to use the new logger factory.
images/virtualization-artifact/pkg/logger/logger.go
images/virtualization-artifact/cmd/virtualization-controller/main.go
Moved and updated internal logic and tests for defaulters and validators to align with the new controller structure.
  • Relocated defaulter and validator code from 'vm/internal' to 'supervm/internal'.
  • Added/updated unit tests for the new defaulter logic.
images/virtualization-artifact/pkg/controller/supervm/internal/defaulter/defaulters_suite_test.go
images/virtualization-artifact/pkg/controller/supervm/internal/validators/affinity_validator_test.go
images/virtualization-artifact/pkg/controller/supervm/internal/validators/block_device_refs_validator_test.go
images/virtualization-artifact/pkg/controller/supervm/internal/validators/first_block_device_validator_test.go
Introduced custom watcher sources to facilitate communication between the supervm and per-namespace controllers.
  • Added 'SuperSource' and 'NamespacedSource' implementations for custom event propagation between controllers.
images/virtualization-artifact/pkg/controller/vm/internal/watcher/super_watcher.go
images/virtualization-artifact/pkg/controller/supervm/internal/watcher/super_watcher.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Isteb4k Isteb4k marked this pull request as draft November 1, 2025 11:15
@Isteb4k Isteb4k added this to the v1.2.0 milestone Nov 1, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Isteb4k Isteb4k force-pushed the chore/vm/increase-performance branch from ff29e41 to c0ebfbf Compare November 1, 2025 11:17
Signed-off-by: Isteb4k <dmitry.rakitin@flant.com>
@Isteb4k Isteb4k force-pushed the chore/vm/increase-performance branch from c0ebfbf to 63a652b Compare November 1, 2025 11:24
danilrwx and others added 4 commits November 1, 2025 16:22
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Isteb4k <dmitry.rakitin@flant.com>
Signed-off-by: Isteb4k <dmitry.rakitin@flant.com>
@Isteb4k Isteb4k force-pushed the chore/vm/increase-performance branch from a752e24 to 35d56b5 Compare November 1, 2025 16:00
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