Skip to content

Commit

Permalink
feat(vi,cvi): requeue for exceeded quota error
Browse files Browse the repository at this point in the history
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 28, 2024
1 parent adfa084 commit 56a26c6
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 1,039 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func NewDeletionHandler(sources *source.Sources) *DeletionHandler {

func (h DeletionHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
if cvi.DeletionTimestamp != nil {
requeue, err := h.sources.CleanUp(ctx, cvi)
result, err := h.sources.CleanUp(ctx, cvi)
if err != nil {
return reconcile.Result{}, err
}

if requeue {
return reconcile.Result{Requeue: true}, nil
if !result.IsZero() {
return result, nil
}

controllerutil.RemoveFinalizer(cvi, virtv2.FinalizerCVICleanup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func (h LifeCycleHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtual
return reconcile.Result{}, fmt.Errorf("data source runner not found for type: %s", cvi.Spec.DataSource.Type)
}

requeue, err := ds.Sync(ctx, cvi)
result, err := ds.Sync(ctx, cvi)
if err != nil {
return reconcile.Result{}, err
}

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package source
import (
"context"
"errors"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
Expand Down Expand Up @@ -54,7 +56,7 @@ func NewHTTPDataSource(
}
}

func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (bool, error) {
func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
log, ctx := logger.GetDataSourceContext(ctx, "http")

condition, _ := service.GetCondition(cvicondition.ReadyType, cvi.Status.Conditions)
Expand All @@ -63,7 +65,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
supgen := supplements.NewGenerator(common.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)
pod, err := ds.importerService.GetPod(ctx, supgen)
if err != nil {
return false, err
return reconcile.Result{}, err
}

switch {
Expand All @@ -79,7 +81,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
// Unprotect import time supplements to delete them later.
err = ds.importerService.Unprotect(ctx, pod)
if err != nil {
return false, err
return reconcile.Result{}, err
}

return CleanUp(ctx, cvi, ds)
Expand All @@ -92,15 +94,24 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma

envSettings := ds.getEnvSettings(cvi, supgen)
err = ds.importerService.Start(ctx, envSettings, cvi, supgen, datasource.NewCABundleForCVMI(cvi.Spec.DataSource))
var requeue bool
requeue, err = setPhaseConditionForImporterStart(&condition, &cvi.Status.Phase, err)
if err != nil {
return false, err
switch {
case err == nil:
// OK.
case common.ErrQuotaExceeded(err):
return setQuotaExceededPhaseCondition(&condition, &cvi.Status.Phase, err, cvi.CreationTimestamp), nil
default:
setPhaseConditionToFailed(&condition, &cvi.Status.Phase, fmt.Errorf("unexpected error: %w", err))
return reconcile.Result{}, err
}

cvi.Status.Phase = virtv2.ImageProvisioning
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.Provisioning
condition.Message = "DVCR Provisioner not found: create the new one."

log.Info("Create importer pod...", "progress", cvi.Status.Progress, "pod.phase", "nil")

return requeue, nil
return reconcile.Result{Requeue: true}, nil
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
Expand All @@ -111,9 +122,9 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
return reconcile.Result{}, nil
default:
return false, err
return reconcile.Result{}, err
}
}

Expand All @@ -140,20 +151,20 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
return reconcile.Result{}, nil
default:
return false, err
return reconcile.Result{}, err
}
}

err = ds.importerService.Protect(ctx, pod)
if err != nil {
return false, err
return reconcile.Result{}, err
}

condition.Status = metav1.ConditionFalse
Expand All @@ -168,18 +179,18 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
log.Info("Provisioning...", "progress", cvi.Status.Progress, "pod.phase", pod.Status.Phase)
}

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

func (ds HTTPDataSource) CleanUp(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (bool, error) {
func (ds HTTPDataSource) CleanUp(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
supgen := supplements.NewGenerator(common.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)

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

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

func (ds HTTPDataSource) Validate(_ context.Context, _ *virtv2.ClusterVirtualImage) error {
Expand Down

This file was deleted.

Loading

0 comments on commit 56a26c6

Please sign in to comment.