Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
facchettos committed May 13, 2024
1 parent 262b11d commit 0e6e0de
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/controllers/resources/persistentvolumes/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ func (s *persistentVolumeSyncer) Sync(ctx *synccontext.SyncContext, pObj client.
return ctrl.Result{}, ctx.VirtualClient.Delete(ctx.Context, vObj)
}

syncBack := true
if !s.useFakePersistentVolumes && vPersistentVolume.Spec.ClaimRef == nil && pPersistentVolume.Spec.ClaimRef != nil && pPvc == nil {
syncBack = false
}
// check if there is a corresponding virtual pvc
if syncBack {
if s.useFakePersistentVolumes || vPersistentVolume.Spec.ClaimRef != nil || pPersistentVolume.Spec.ClaimRef == nil || pPvc != nil {
updatedObj := s.translateUpdateBackwards(vPersistentVolume, pPersistentVolume, vPvc)
if updatedObj != nil {
ctx.Log.Infof("update virtual persistent volume %s, because spec has changed", vPersistentVolume.Name)
Expand Down Expand Up @@ -285,10 +281,14 @@ func (s *persistentVolumeSyncer) shouldSync(ctx context.Context, pObj *corev1.Pe

pPvc := &corev1.PersistentVolumeClaim{}
err = s.physicalClient.Get(ctx, types.NamespacedName{Namespace: pObj.Spec.ClaimRef.Namespace, Name: pObj.Spec.ClaimRef.Name}, pPvc)
if kerrors.IsNotFound(err) {
switch {
case kerrors.IsNotFound(err):
return true, vPvc, nil, nil
} else if err != nil {
return true, vPvc, nil, err
case kerrors.IsForbidden(err):
// we don't own the physical pvc here so we don't sync
return false, vPvc, nil, nil
case err != nil:
return false, vPvc, nil, err
}

return true, vPvc, pPvc, nil
Expand Down

0 comments on commit 0e6e0de

Please sign in to comment.