Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/core/v1alpha2/vdcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
InUseType Type = "InUse"
// MigratingType indicates that the virtual disk is in the process of migrating data from one volume to another (during the migration of a local disk or migration to another storage class).
MigratingType Type = "Migrating"
// DeletingType indicates whether the VirtualDisk deletion can be completed.
DeletingType Type = "Deleting"
)

type (
Expand All @@ -55,6 +57,8 @@ type (
InUseReason string
// MigratingReason represents the various reasons for the Migration condition type.
MigratingReason string
// DeletingReason represents the various reasons for the Deleting condition type.
DeletingReason string
)

func (s DatasourceReadyReason) String() string {
Expand Down Expand Up @@ -85,6 +89,10 @@ func (s MigratingReason) String() string {
return string(s)
}

func (s DeletingReason) String() string {
return string(s)
}

const (
// DatasourceReady indicates that the datasource is ready for use, allowing the import process to start.
DatasourceReady DatasourceReadyReason = "DatasourceReady"
Expand Down Expand Up @@ -189,3 +197,10 @@ const (
SnapshottingInProgressReason MigratingReason = "SnapshottingInProgress"
StorageClassNotFoundReason MigratingReason = "StorageClassNotFound"
)

const (
// DeletionBlockedByProtection indicates that the VirtualDisk cannot be deleted while it is protected.
DeletionBlockedByProtection DeletingReason = "DeletionBlockedByProtection"
// DeletionCleanupPending indicates that the VirtualDisk cleanup is still in progress.
DeletionCleanupPending DeletingReason = "CleanupPending"
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package internal

import (
"context"
"log/slog"
"time"

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand All @@ -44,12 +45,13 @@ func (h DeletionHandler) Handle(ctx context.Context, cvi *v1alpha2.ClusterVirtua
log := logger.FromContext(ctx).With(logger.SlogHandler(deletionHandlerName))

if cvi.DeletionTimestamp != nil {
requeue, err := h.sources.CleanUp(ctx, cvi)
requeue, reason, err := h.sources.CleanUp(ctx, cvi)
if err != nil {
return reconcile.Result{}, err
}

if requeue {
log.Info("ClusterVirtualImage cleanup is pending", slog.String("reason", reason))
return reconcile.Result{RequeueAfter: time.Second}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, cvi *v1alpha2.ClusterVirtu
ObservedGeneration: cvi.Status.ObservedGeneration,
}

_, err := h.sources.CleanUp(ctx, cvi)
_, _, err := h.sources.CleanUp(ctx, cvi)
if err != nil {
return reconcile.Result{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirtualI
return reconcile.Result{}, err
}

_, err = CleanUp(ctx, cvi, ds)
_, _, err = CleanUp(ctx, cvi, ds)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -220,15 +220,15 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirtualI
return reconcile.Result{RequeueAfter: time.Second}, nil
}

func (ds HTTPDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
func (ds HTTPDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)

requeue, err := ds.importerService.CleanUp(ctx, supgen)
requeue, reason, err := ds.importerService.CleanUp(ctx, supgen)
if err != nil {
return false, err
return false, "", err
}

return requeue, nil
return requeue, reason, nil
}

func (ds HTTPDataSource) Validate(_ context.Context, _ *v1alpha2.ClusterVirtualImage) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
type Importer interface {
Start(ctx context.Context, settings *importer.Settings, obj client.Object, sup supplements.Generator, caBundle *datasource.CABundle, opts ...service.Option) error
StartWithPodSetting(ctx context.Context, settings *importer.Settings, sup supplements.Generator, caBundle *datasource.CABundle, podSettings *importer.PodSettings, opts ...service.Option) error
CleanUp(ctx context.Context, sup supplements.Generator) (bool, error)
CleanUpSupplements(ctx context.Context, sup supplements.Generator) (bool, error)
CleanUp(ctx context.Context, sup supplements.Generator) (bool, string, error)
CleanUpSupplements(ctx context.Context, sup supplements.Generator) (bool, string, error)
GetPod(ctx context.Context, sup supplements.Generator) (*corev1.Pod, error)
DeletePod(ctx context.Context, obj client.Object, controllerName string, sup supplements.Generator) (bool, error)
Protect(ctx context.Context, pod *corev1.Pod, sup supplements.Generator) error
Expand All @@ -49,7 +49,7 @@ type Importer interface {

type Uploader interface {
Start(ctx context.Context, settings *uploader.Settings, obj client.Object, sup supplements.Generator, caBundle *datasource.CABundle, opts ...service.Option) error
CleanUp(ctx context.Context, sup supplements.Generator) (bool, error)
CleanUp(ctx context.Context, sup supplements.Generator) (bool, string, error)
GetPod(ctx context.Context, sup supplements.Generator) (*corev1.Pod, error)
GetIngress(ctx context.Context, sup supplements.Generator) (*netv1.Ingress, error)
GetService(ctx context.Context, sup supplements.Generator) (*corev1.Service, error)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVir
return reconcile.Result{}, err
}

_, err = CleanUp(ctx, cvi, ds)
_, _, err = CleanUp(ctx, cvi, ds)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -294,25 +294,25 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVir
return reconcile.Result{RequeueAfter: time.Second}, nil
}

func (ds ObjectRefDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
viRefResult, err := ds.viOnPvcSyncer.CleanUp(ctx, cvi)
func (ds ObjectRefDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
viRefRequeue, viRefReason, err := ds.viOnPvcSyncer.CleanUp(ctx, cvi)
if err != nil {
return false, err
return false, "", err
}

vdRefResult, err := ds.vdSyncer.CleanUp(ctx, cvi)
vdRefRequeue, vdRefReason, err := ds.vdSyncer.CleanUp(ctx, cvi)
if err != nil {
return false, err
return false, "", err
}

supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)

objRefRequeue, err := ds.importerService.CleanUp(ctx, supgen)
objRefRequeue, objRefReason, err := ds.importerService.CleanUp(ctx, supgen)
if err != nil {
return false, err
return false, "", err
}

return viRefResult || vdRefResult || objRefRequeue, nil
return viRefRequeue || vdRefRequeue || objRefRequeue, service.MergeCleanUpReasons(viRefReason, vdRefReason, objRefReason), nil
}

func (ds ObjectRefDataSource) Validate(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *v1alpha2.ClusterVi
return reconcile.Result{}, err
}

_, err = CleanUp(ctx, cvi, ds)
_, _, err = CleanUp(ctx, cvi, ds)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -216,9 +216,17 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *v1alpha2.ClusterVi
return reconcile.Result{RequeueAfter: time.Second}, nil
}

func (ds ObjectRefVirtualDisk) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
func (ds ObjectRefVirtualDisk) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)
return ds.importerService.DeletePod(ctx, cvi, controllerName, supgen)
deleted, err := ds.importerService.DeletePod(ctx, cvi, controllerName, supgen)
if err != nil {
return false, "", err
}
if !deleted {
return false, "", nil
}

return true, "waiting for object-ref importer Pod deletion", nil
}

func (ds ObjectRefVirtualDisk) getEnvSettings(cvi *v1alpha2.ClusterVirtualImage, sup supplements.Generator, volumeMode *corev1.PersistentVolumeMode) *importer.Settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,42 +319,42 @@ func (ds ObjectRefVirtualDiskSnapshot) Sync(ctx context.Context, cvi *v1alpha2.C
func (ds ObjectRefVirtualDiskSnapshot) CleanUpSupplements(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (reconcile.Result, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, cvi.Spec.DataSource.ObjectRef.Namespace, cvi.UID)

importerRequeue, err := ds.importerService.CleanUpSupplements(ctx, supgen)
importerRequeue, importerReason, err := ds.importerService.CleanUpSupplements(ctx, supgen)
if err != nil {
return reconcile.Result{}, err
}

diskRequeue, err := ds.diskService.CleanUpSupplements(ctx, supgen)
diskRequeue, diskReason, err := ds.diskService.CleanUpSupplements(ctx, supgen)
if err != nil {
return reconcile.Result{}, err
}

pvcCleanupRequeue, err := ds.diskService.CleanUp(ctx, supgen)
pvcCleanupRequeue, pvcCleanupReason, err := ds.diskService.CleanUp(ctx, supgen)
if err != nil {
return reconcile.Result{}, err
}

if importerRequeue || diskRequeue || pvcCleanupRequeue {
if reason := service.MergeCleanUpReasons(importerReason, diskReason, pvcCleanupReason); reason != "" || importerRequeue || diskRequeue || pvcCleanupRequeue {
return reconcile.Result{RequeueAfter: time.Second}, nil
} else {
return reconcile.Result{}, nil
}
}

func (ds ObjectRefVirtualDiskSnapshot) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
func (ds ObjectRefVirtualDiskSnapshot) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, cvi.Spec.DataSource.ObjectRef.Namespace, cvi.UID)

importerRequeue, err := ds.importerService.CleanUp(ctx, supgen)
importerRequeue, importerReason, err := ds.importerService.CleanUp(ctx, supgen)
if err != nil {
return false, err
return false, "", err
}

diskRequeue, err := ds.diskService.CleanUp(ctx, supgen)
diskRequeue, diskReason, err := ds.diskService.CleanUp(ctx, supgen)
if err != nil {
return false, err
return false, "", err
}

return importerRequeue || diskRequeue, nil
return importerRequeue || diskRequeue, service.MergeCleanUpReasons(importerReason, diskReason), nil
}

func (ds ObjectRefVirtualDiskSnapshot) getEnvSettings(cvi *v1alpha2.ClusterVirtualImage, sup supplements.Generator, volumeMode *corev1.PersistentVolumeMode) *importer.Settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *v1alpha2.Clu
return reconcile.Result{}, err
}

_, err = CleanUp(ctx, cvi, ds)
_, _, err = CleanUp(ctx, cvi, ds)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -205,9 +205,17 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *v1alpha2.Clu
return reconcile.Result{RequeueAfter: time.Second}, nil
}

func (ds ObjectRefVirtualImageOnPvc) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
func (ds ObjectRefVirtualImageOnPvc) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, cvi.Namespace, cvi.UID)
return ds.importerService.DeletePod(ctx, cvi, controllerName, supgen)
deleted, err := ds.importerService.DeletePod(ctx, cvi, controllerName, supgen)
if err != nil {
return false, "", err
}
if !deleted {
return false, "", nil
}

return true, "waiting for object-ref importer Pod deletion", nil
}

func (ds ObjectRefVirtualImageOnPvc) getEnvSettings(cvi *v1alpha2.ClusterVirtualImage, sup supplements.Generator) *importer.Settings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirt
return reconcile.Result{}, err
}

_, err = CleanUp(ctx, cvi, ds)
_, _, err = CleanUp(ctx, cvi, ds)
if err != nil {
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *v1alpha2.ClusterVirt
return reconcile.Result{RequeueAfter: time.Second}, nil
}

func (ds RegistryDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, error) {
func (ds RegistryDataSource) CleanUp(ctx context.Context, cvi *v1alpha2.ClusterVirtualImage) (bool, string, error) {
supgen := supplements.NewGenerator(annotations.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)

return ds.importerService.CleanUp(ctx, supgen)
Expand Down
Loading
Loading