Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Zimin <alexandr.zimin@flant.com>
  • Loading branch information
AleksZimin committed May 26, 2024
1 parent e5150e5 commit 34cba03
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ func RunLocalStorageClassWatcherController(
func RunEventReconcile(ctx context.Context, cl client.Client, log logger.Logger, scList *v1.StorageClassList, lsc *v1alpha1.LocalStorageClass) (bool, error) {
recType, err := identifyReconcileFunc(scList, lsc)
if err != nil {
log.Error(err, fmt.Sprintf("[runEventReconcile] unable to identify reconcile func for the LocalStorageClass %s", lsc.Name))
upError := updateLocalStorageClassPhase(ctx, cl, lsc, FailedStatusPhase, err.Error())
if upError != nil {
upError = fmt.Errorf("[runEventReconcile] unable to update the LocalStorageClass %s status: %w", lsc.Name, upError)
err = errors.Join(err, upError)
}
return true, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func shouldReconcileByUpdateFunc(scList *v1.StorageClassList, lsc *v1alpha1.Loca
return false, nil

} else {
err := fmt.Errorf("a storage class %s does not belong to %s provisioner", sc.Name, LocalStorageClassProvisioner)
err := fmt.Errorf("a storage class %s already exists and does not belong to %s provisioner", sc.Name, LocalStorageClassProvisioner)
return false, err
}
}
Expand Down Expand Up @@ -473,6 +473,10 @@ func updateLocalStorageClassPhase(
lsc.Status.Phase = phase
lsc.Status.Reason = reason

if !slices.Contains(lsc.Finalizers, LocalStorageClassFinalizerName) {
lsc.Finalizers = append(lsc.Finalizers, LocalStorageClassFinalizerName)
}

// TODO: add retry logic
err := cl.Update(ctx, lsc)
if err != nil {
Expand Down
Loading

0 comments on commit 34cba03

Please sign in to comment.