Skip to content

Commit

Permalink
feat(vd): requeue for exceeded quota error
Browse files Browse the repository at this point in the history
1. Refactored the virtual disk controller. SourceHandlers now return reconcile.Result.
2. If a "quota exceeded" error appears, we make additional attempts with a one-minute interval. If after 30 minutes it still doesn't succeed, the phase is set to Failed.

Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k authored Oct 24, 2024
1 parent 2ae87b8 commit 6d047c3
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ func (s DiskService) GetVolumeSnapshot(ctx context.Context, name, namespace stri
return helper.FetchObject(ctx, types.NamespacedName{Name: name, Namespace: namespace}, s.client, &vsv1.VolumeSnapshot{})
}

func (s DiskService) GetVirtualImage(ctx context.Context, name, namespace string) (*virtv2.VirtualImage, error) {
return helper.FetchObject(ctx, types.NamespacedName{Name: name, Namespace: namespace}, s.client, &virtv2.VirtualImage{})
}

func (s DiskService) GetClusterVirtualImage(ctx context.Context, name string) (*virtv2.ClusterVirtualImage, error) {
return helper.FetchObject(ctx, types.NamespacedName{Name: name}, s.client, &virtv2.ClusterVirtualImage{})
}

func (s DiskService) ListVirtualDiskSnapshots(ctx context.Context, namespace string) ([]virtv2.VirtualDiskSnapshot, error) {
var vdSnapshots virtv2.VirtualDiskSnapshotList
err := s.client.List(ctx, &vdSnapshots, &client.ListOptions{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (r
}
}

requeue, err := ds.Sync(ctx, vd)
result, err := ds.Sync(ctx, vd)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to sync virtual disk data source %s: %w", ds.Name(), err)
}

return reconcile.Result{Requeue: requeue}, nil
return result, nil
}

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 @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
Expand All @@ -49,7 +50,7 @@ func NewBlankDataSource(
}
}

func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (bool, error) {
func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (reconcile.Result, error) {
log, ctx := logger.GetDataSourceContext(ctx, blankDataSource)

condition, _ := service.GetCondition(vdcondition.ReadyType, vd.Status.Conditions)
Expand All @@ -58,11 +59,11 @@ func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (boo
supgen := supplements.NewGenerator(common.VDShortName, vd.Name, vd.Namespace, vd.UID)
dv, err := ds.diskService.GetDataVolume(ctx, supgen)
if err != nil {
return false, err
return reconcile.Result{}, err
}
pvc, err := ds.diskService.GetPersistentVolumeClaim(ctx, supgen)
if err != nil {
return false, err
return reconcile.Result{}, err
}

switch {
Expand All @@ -74,12 +75,12 @@ func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (boo
// Protect Ready Disk and underlying PVC.
err = ds.diskService.Protect(ctx, vd, nil, pvc)
if err != nil {
return false, err
return reconcile.Result{}, err
}

err = ds.diskService.Unprotect(ctx, dv)
if err != nil {
return false, err
return reconcile.Result{}, err
}

return CleanUpSupplements(ctx, vd, ds)
Expand All @@ -95,29 +96,29 @@ func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (boo
if err != nil {
setPhaseConditionToFailed(&condition, &vd.Status.Phase, err)

return false, err
return reconcile.Result{}, err
}

source := ds.getSource()

err = ds.diskService.Start(ctx, diskSize, vd.Spec.PersistentVolumeClaim.StorageClass, source, vd, supgen)

if updated, err := setPhaseConditionFromStorageError(err, vd, &condition); err != nil || updated {
return false, err
return reconcile.Result{}, err
}

vd.Status.Phase = virtv2.DiskProvisioning
condition.Status = metav1.ConditionFalse
condition.Reason = vdcondition.Provisioning
condition.Message = "PVC Provisioner not found: create the new one."

return true, nil
return reconcile.Result{Requeue: true}, nil
case pvc == nil:
vd.Status.Phase = virtv2.DiskProvisioning
condition.Status = metav1.ConditionFalse
condition.Reason = vdcondition.Provisioning
condition.Message = "PVC not found: waiting for creation."
return true, nil
return reconcile.Result{Requeue: true}, nil
case ds.diskService.IsImportDone(dv, pvc):
log.Info("Import has completed", "dvProgress", dv.Status.Progress, "dvPhase", dv.Status.Phase, "pvcPhase", pvc.Status.Phase)

Expand All @@ -138,19 +139,19 @@ func (ds BlankDataSource) Sync(ctx context.Context, vd *virtv2.VirtualDisk) (boo

err = ds.diskService.Protect(ctx, vd, dv, pvc)
if err != nil {
return false, err
return reconcile.Result{}, err
}
sc, err := ds.diskService.GetStorageClass(ctx, pvc.Spec.StorageClassName)
if updated, err := setPhaseConditionFromStorageError(err, vd, &condition); err != nil || updated {
return false, err
return reconcile.Result{}, err
}
if err = setPhaseConditionForPVCProvisioningDisk(ctx, dv, vd, pvc, sc, &condition, ds.diskService); err != nil {
return false, err
return reconcile.Result{}, err
}
return false, nil
return reconcile.Result{}, nil
}

return true, nil
return reconcile.Result{Requeue: true}, nil
}

func (ds BlankDataSource) CleanUp(ctx context.Context, vd *virtv2.VirtualDisk) (bool, error) {
Expand All @@ -164,15 +165,15 @@ func (ds BlankDataSource) CleanUp(ctx context.Context, vd *virtv2.VirtualDisk) (
return requeue, nil
}

func (ds BlankDataSource) CleanUpSupplements(ctx context.Context, vd *virtv2.VirtualDisk) (bool, error) {
func (ds BlankDataSource) CleanUpSupplements(ctx context.Context, vd *virtv2.VirtualDisk) (reconcile.Result, error) {
supgen := supplements.NewGenerator(common.VDShortName, vd.Name, vd.Namespace, vd.UID)

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

return requeue, nil
return reconcile.Result{Requeue: requeue}, nil
}

func (ds BlankDataSource) Validate(_ context.Context, _ *virtv2.VirtualDisk) error {
Expand Down
Loading

0 comments on commit 6d047c3

Please sign in to comment.