Skip to content

Commit

Permalink
Fail DevWorkspaces when DevWorkspaceRouting controller sees error
Browse files Browse the repository at this point in the history
Mark DevWorkspaceRoutings as failed if any of the sync operations
returns an UnrecoverableSyncError rather than ignoring it and treating
it as a transient error (i.e. retrying).

This allows workspaces to fail with a meaningful message more quickly,
rather than waiting for timeout and failing then.

Signed-off-by: Angel Misevski <[email protected]>
  • Loading branch information
amisevsk committed Oct 24, 2023
1 parent 800f386 commit 3bda263
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/devfile/devworkspace-operator/pkg/config"
"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
"github.com/devfile/devworkspace-operator/pkg/provision/sync"

"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -185,6 +186,10 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.

servicesInSync, clusterServices, err := r.syncServices(instance, services)
if err != nil {
failError := &sync.UnrecoverableSyncError{}
if errors.As(err, &failError) {
return reconcile.Result{}, r.markRoutingFailed(instance, err.Error())
}
reqLogger.Error(err, "Error syncing services")
return reconcile.Result{Requeue: true}, r.reconcileStatus(instance, nil, nil, false, "Preparing services")
} else if !servicesInSync {
Expand All @@ -199,6 +204,10 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
if infrastructure.IsOpenShift() {
routesInSync, clusterRoutes, err := r.syncRoutes(instance, routes)
if err != nil {
failError := &sync.UnrecoverableSyncError{}
if errors.As(err, &failError) {
return reconcile.Result{}, r.markRoutingFailed(instance, err.Error())
}
reqLogger.Error(err, "Error syncing routes")
return reconcile.Result{Requeue: true}, r.reconcileStatus(instance, nil, nil, false, "Preparing routes")
} else if !routesInSync {
Expand All @@ -209,6 +218,10 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
} else {
ingressesInSync, clusterIngresses, err := r.syncIngresses(instance, ingresses)
if err != nil {
failError := &sync.UnrecoverableSyncError{}
if errors.As(err, &failError) {
return reconcile.Result{}, r.markRoutingFailed(instance, err.Error())
}
reqLogger.Error(err, "Error syncing ingresses")
return reconcile.Result{Requeue: true}, r.reconcileStatus(instance, nil, nil, false, "Preparing ingresses")
} else if !ingressesInSync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *DevWorkspaceRoutingReconciler) syncIngresses(routing *controllerv1alpha
ingressesInSync = false
continue
case *sync.UnrecoverableSyncError:
return false, nil, t.Cause
return false, nil, t
default:
return false, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/controller/devworkspacerouting/sync_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *DevWorkspaceRoutingReconciler) syncRoutes(routing *controllerv1alpha1.D
routesInSync = false
continue
case *sync.UnrecoverableSyncError:
return false, nil, t.Cause
return false, nil, t
default:
return false, nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *DevWorkspaceRoutingReconciler) syncServices(routing *controllerv1alpha1
servicesInSync = false
continue
case *sync.UnrecoverableSyncError:
return false, nil, t.Cause
return false, nil, t
default:
return false, nil, err
}
Expand Down

0 comments on commit 3bda263

Please sign in to comment.