Skip to content

Commit

Permalink
feat(vi): add info represents quota exceed state (#594)
Browse files Browse the repository at this point in the history
Signed-off-by: Valeriy Khorunzhin <[email protected]>
  • Loading branch information
eofff authored Jan 15, 2025
1 parent 63647e1 commit 0b3f4b5
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/core/v1alpha2/vicondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
StorageClassNotReady ReadyReason = "StorageClassNotReady"
// Ready indicates that the import process is complete and the `VirtualImage` is ready for use.
Ready ReadyReason = "Ready"
// QuotaExceeded indicates that the VirtualImage is reached project quotas and can not be provisioned.
QuotaExceeded ReadyReason = "QuotaExceeded"

// Lost indicates that the underlying PersistentVolumeClaim has been lost and the `VirtualImage` can no longer be used.
Lost ReadyReason = "PVCLost"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func (ds HTTPDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualImage
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(condition):
log.Info("Image provisioning finished: clean up")
Expand Down Expand Up @@ -342,6 +347,13 @@ func (ds HTTPDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualImage
Message("DVCR Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (ds ObjectRefDataSource) StoreToPVC(ctx context.Context, vi *virtv2.Virtual
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(condition):
log.Info("Disk provisioning finished: clean up")
Expand Down Expand Up @@ -211,6 +216,13 @@ func (ds ObjectRefDataSource) StoreToPVC(ctx context.Context, vi *virtv2.Virtual
Message("PVC Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func (ds ObjectRefVirtualDisk) StoreToPVC(ctx context.Context, vi *virtv2.Virtua
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(cb.Condition()):
log.Info("Disk provisioning finished: clean up")
Expand Down Expand Up @@ -282,6 +287,13 @@ func (ds ObjectRefVirtualDisk) StoreToPVC(ctx context.Context, vi *virtv2.Virtua
Message("PVC Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ func (ds ObjectRefDataVirtualImageOnPVC) StoreToPVC(ctx context.Context, vi, viR
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(cb.Condition()):
log.Info("Disk provisioning finished: clean up")
Expand Down Expand Up @@ -271,6 +276,13 @@ func (ds ObjectRefDataVirtualImageOnPVC) StoreToPVC(ctx context.Context, vi, viR
Message("PVC Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func (ds RegistryDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualI
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(condition):
log.Info("Disk provisioning finished: clean up")
Expand Down Expand Up @@ -223,6 +228,13 @@ func (ds RegistryDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualI
Message("PVC Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,7 @@ func setQuotaExceededPhaseCondition(cb *conditions.ConditionBuilder, phase *virt
cb.Message(fmt.Sprintf("Quota exceeded: %s; Retry in %d minute.", err, retryPeriod))
return reconcile.Result{RequeueAfter: retryPeriod * time.Minute}
}

const (
DVQoutaNotExceededConditionType cdiv1.DataVolumeConditionType = "QuotaNotExceeded"
)
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (ds UploadDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualIma
return reconcile.Result{}, err
}

var quotaNotExceededCondition *cdiv1.DataVolumeCondition
if dv != nil {
quotaNotExceededCondition = service.GetDataVolumeCondition(DVQoutaNotExceededConditionType, dv.Status.Conditions)
}

switch {
case isDiskProvisioningFinished(condition):
log.Info("Disk provisioning finished: clean up")
Expand Down Expand Up @@ -265,6 +270,13 @@ func (ds UploadDataSource) StoreToPVC(ctx context.Context, vi *virtv2.VirtualIma
Message("PVC Provisioner not found: create the new one.")

return reconcile.Result{Requeue: true}, nil
case quotaNotExceededCondition != nil && quotaNotExceededCondition.Status == corev1.ConditionFalse:
vi.Status.Phase = virtv2.ImagePending
cb.
Status(metav1.ConditionFalse).
Reason(vicondition.QuotaExceeded).
Message(quotaNotExceededCondition.Message)
return reconcile.Result{}, nil
case pvc == nil:
vi.Status.Phase = virtv2.ImageProvisioning
cb.
Expand Down

0 comments on commit 0b3f4b5

Please sign in to comment.