Skip to content

Commit

Permalink
fix(vi,cvi): fix pod errors handling
Browse files Browse the repository at this point in the history
Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k authored Jun 26, 2024
1 parent 2c05d75 commit 21be7cd
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma

ds.logger.Info("Create importer pod...", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
cvi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu

ds.logger.Info("Ready", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
cvi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua

ds.logger.Info("Create importer pod...", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
cvi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ func (ds UploadDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualI

ds.logger.Info("Create uploader pod...", "cvi", cvi.Name, "progress", cvi.Status.Progress, "pod.phase", nil)
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
cvi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = cvicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ func (ds HTTPDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (boo

ds.logger.Info("Create importer pod...", "vi", vi.Name, "progress", vi.Status.Progress, "pod.phase", "nil")
case cc.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
vi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = vicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage)

ds.logger.Info("Ready", "vi", vi.Name, "progress", vi.Status.Progress, "pod.phase", "nil")
case cc.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
vi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = vicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ func (ds RegistryDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage)

ds.logger.Info("Create importer pod...", "vi", vi.Name, "progress", vi.Status.Progress, "pod.phase", "nil")
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
vi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = vicondition.Ready
condition.Message = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ func (ds UploadDataSource) Sync(ctx context.Context, vi *virtv2.VirtualImage) (b

ds.logger.Info("Create uploader pod...", "vi", vi.Name, "progress", vi.Status.Progress, "pod.phase", nil)
case common.IsPodComplete(pod):
err = ds.statService.CheckPod(pod)
if err != nil {
vi.Status.Phase = virtv2.ImageFailed

switch {
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return false, nil
default:
return false, err
}
}

condition.Status = metav1.ConditionTrue
condition.Reason = vicondition.Ready
condition.Message = ""
Expand Down

0 comments on commit 21be7cd

Please sign in to comment.