Skip to content

Conversation

@diafour
Copy link
Member

@diafour diafour commented Oct 28, 2025

Description

  • Add maintenance mode for DVCR Deployment.
  • Add auto-cleanup schedule setting in ModuleConfig.
  • Add 'auto-cleanup check' command to dvcr-cleaner to get all images eligible for cleanup.

Internals:

  • Add hook to switch DVCR into maintenance mode depending on Secret created by controller.
  • Refactor cron source, make it independent on gc manager. Start maintenance mode by cron source.
  • Add condition on Deployment/dvcr to get maintenance mode state, e.g. auto-cleanup state.
  • Maintenance mode keep dvcr in RO mode, so VM with mounted images should able to reboot.
  • Also, postpone importer and uploader Pods creation for new cvi/vi/vd until auto-cleanup finishes.

Why do we need it, and what problem does it solve?

ClusterVirtualImage/VirtualImage/VirtualDisk deletion in cluster should free space on DVCR storage.

What is the expected result?

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

section: core
type: feature
summary: Auto-cleanup for dvcr storage with configurable schedule in ModuleConfig.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 28, 2025

Reviewer's Guide

This PR implements an auto-cleanup feature for DVCR storage by introducing a maintenance mode toggled via a Kubernetes Secret, refactoring the CronSource to enqueue cleanup jobs independently, extending the dvcr-cleaner tool with new run and check commands, and updating Helm charts and module configuration to support scheduled cleanup and read‐only maintenance.

ER diagram for DVCR auto-cleanup eligible images

erDiagram
    ClusterVirtualImage {
        string name
    }
    VirtualImage {
        string namespace
        string name
    }
    VirtualDisk {
        string namespace
        string name
        string phase
    }
    RegistryImage {
        string type
        string namespace
        string name
        string path
    }
    ClusterVirtualImage ||--o| RegistryImage : "has image"
    VirtualImage ||--o| RegistryImage : "has image"
    VirtualDisk ||--o| RegistryImage : "has image"
Loading

Class diagram for CronSource and ObjectLister refactor

classDiagram
    class CronSource {
        - schedule: cron.Schedule
        - objLister: ObjectLister
        - log: *log.Logger
        - clock: clock.Clock
        + Start(ctx, queue)
        + enqueueObjects(ctx, queueAddFunc)
    }
    class ObjectLister {
        + List(ctx, now): []client.Object
    }
    class ObjectListerImpl {
        - ListFunc: func(ctx, now) ([]client.Object, error)
        + List(ctx, now): []client.Object
    }
    CronSource --> ObjectLister
    ObjectLister <|-- ObjectListerImpl
Loading

Class diagram for dvcr-cleaner auto-cleanup commands

classDiagram
    class AutoCleanupCmd {
        + run
        + check
    }
    class autoCleanupRunCmd {
        + autoCleanupRun(cmd, args)
    }
    class autoCleanupCheckCmd {
        + autoCleanupCheck(cmd, args)
    }
    class registry {
        + RemoveImages(images)
        + ExecGarbageCollect()
        + StorageStats()
        + ListImagesAll()
    }
    class kubernetes {
        + NewVirtualizationClient()
        + ListAllPossibleImages(ctx)
    }
    AutoCleanupCmd --> autoCleanupRunCmd
    AutoCleanupCmd --> autoCleanupCheckCmd
    autoCleanupRunCmd --> registry
    autoCleanupCheckCmd --> registry
    autoCleanupRunCmd --> kubernetes
    autoCleanupCheckCmd --> kubernetes
Loading

Class diagram for DVCR maintenance controller and handlers

classDiagram
    class Reconciler {
        - handlers: []Handler
        - client: client.Client
        + Reconcile(ctx, req)
        + SetupController(ctx, mgr, ctr)
    }
    class Handler {
        + Handle(ctx, deploy)
    }
    class LifeCycleHandler {
        - client: client.Client
        + Handle(ctx, deploy)
    }
    class Watcher {
        + Watch(mgr, ctr)
    }
    class DVCRDeploymentWatcher {
        - client: client.Client
        + Watch(mgr, ctr)
    }
    class CronWatcher {
        + Watch(mgr, ctr)
    }
    Reconciler --> Handler
    Handler <|-- LifeCycleHandler
    Reconciler --> Watcher
    Watcher <|-- DVCRDeploymentWatcher
    Watcher <|-- CronWatcher
Loading

File-Level Changes

Change Details Files
Decouple CronSource from GC manager by introducing ObjectLister
  • Define ObjectLister interface and ObjectListerImpl
  • Provide constructors NewObjectLister and NewSingleObjectLister
  • Update CronSource to use ObjectLister instead of SourceGCManager
  • Rename addObjects to enqueueObjects and adjust scheduling logic
  • Change controller setup to pass schedule string and build ObjectLister
images/virtualization-artifact/pkg/controller/gc/cron_source.go
images/virtualization-artifact/pkg/controller/gc/cron_source_test.go
images/virtualization-artifact/pkg/controller/gc/gc_controller.go
images/virtualization-artifact/pkg/controller/vm/gc.go
images/virtualization-artifact/pkg/controller/vmop/gc.go
Extend Helm chart for DVCR maintenance mode
  • Define dvcr.resources and dvcr.resources.maintenance helpers
  • Add dvcr-maintenance container in deployment when maintenance flag is true
  • Introduce dvcr.isMaintenance helper and maintenance‐specific envs, volumeMounts
  • Adjust pod autoscaling strategy to single‐replica Recreate during maintenance
  • Update configMap templates to enable read‐only mode in maintenance
templates/dvcr/deployment.yaml
templates/dvcr/_helpers.tpl
templates/dvcr/configmap.yaml
templates/dvcr/configmap-cleanup.yaml
Add dvcr-maintenance hook to toggle maintenance mode via Secret
  • Register a hook watching Secret/dvcr-maintenance in module namespace
  • Parse secret annotation to determine maintenance state
  • Set values.virtualization.internal.dvcr.maintenanceEnabled accordingly
images/hooks/pkg/hooks/dvcr-maintenance/hook.go
Implement DVCR maintenance controller and watchers
  • Create dvcr-maintenance controller scaffold with Reconciler and handlers
  • Add watcher for Deployment/dvcr changes and cron events
  • Wire up cronSource for periodic cleanup scheduling
images/virtualization-artifact/pkg/controller/dvcr-maintenance/dvcr_maintenance_controller.go
images/virtualization-artifact/pkg/controller/dvcr-maintenance/dvcr_maintenance_reconciler.go
images/virtualization-artifact/pkg/controller/dvcr-maintenance/internal/watcher/dvcr_deployment.go
images/virtualization-artifact/pkg/controller/dvcr-maintenance/internal/watcher/cron.go
Add AutoCleanup Cobra command in dvcr-cleaner
  • Introduce AutoCleanupCmd with run and check subcommands
  • Implement autoCleanup logic to find and remove absent images
  • Report freed space and optional termination message
  • Register AutoCleanupCmd in main.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/auto_cleanup.go
images/dvcr-artifact/cmd/dvcr-cleaner/main.go
Abstract registry and Kubernetes operations for cleanup
  • Move garbage-collect exec to registry.ExecGarbageCollect
  • Implement registry.ListImagesAll and RemoveImages functions
  • Add storage.FSBytes for Linux and stub for other OS
  • Provide Kubernetes client with ListAllPossibleImages for cluster resources
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/registry/list.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/registry/remove.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/registry/gc.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/registry/storage_stats.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/storage/stats_linux.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/storage/stats_other.go
images/dvcr-artifact/cmd/dvcr-cleaner/cmd/kubernetes/list.go
Expose autoCleanupSchedule and maintenanceMode in ModuleConfig and settings
  • Add autoCleanupSchedule property in openapi schemas and docs
  • Include maintenanceMode and DVCR_AUTO_CLEANUP_SCHEDULE env vars
  • Update values.yaml defaults for maintenanceMode
  • Extend dvcr.Settings struct with AutoCleanupSchedule
openapi/config-values.yaml
openapi/doc-ru-config-values.yaml
openapi/values.yaml
templates/virtualization-controller/_helpers.tpl
images/virtualization-artifact/pkg/dvcr/dvcr.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

@diafour diafour added this to the v1.2.0 milestone Oct 29, 2025
@diafour diafour force-pushed the feat/core/dvcr-autocleanup branch from fd87859 to d4a5cb2 Compare November 1, 2025 13:04
- Add maintenance mode for DVCR Deployment.
- Add auto-cleanup schedule setting in ModuleConfig.
- Add 'auto-cleanup check' command to dvcr-cleaner to get all images eligible for cleanup.

Internals:
- Add hook to switch DVCR into maintenance mode depending on Secret created by controller.
- Refactor cron source, make it independent on gc manager. Start maintenance mode by cron source.
- Add condition on Deployment/dvcr to get maintenance mode state, e.g. auto-cleanup state.
- Maintenance mode keep dvcr in RO mode, so VM with mounted images should able to reboot.
- Also, postpone importer and uploader Pods creation for new cvi/vi/vd until auto-cleanup finishes.

Signed-off-by: Ivan Mikheykin <[email protected]>
@diafour diafour force-pushed the feat/core/dvcr-autocleanup branch from 9edd70c to e38efc3 Compare November 5, 2025 17:08
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.

2 participants