Skip to content

Commit

Permalink
Add coverage for Route controller failure paths. (#1508)
Browse files Browse the repository at this point in the history
This introduces new functionality to our `TableTest` to enable a `Row` to provide `clientgotesting.ReactionFunc`s to induce failures during API requests through the fake clients.  For example:

```go
// Induce a failure creating revisions.
WantErr: true,
WithReactors: []clientgotesting.ReactionFunc{
    InduceFailure("create", "revisions"),
},
```

Fixes: #1501
  • Loading branch information
mattmoor authored and google-prow-robot committed Jul 6, 2018
1 parent 1ddb7b4 commit a7140e6
Show file tree
Hide file tree
Showing 5 changed files with 712 additions and 41 deletions.
6 changes: 0 additions & 6 deletions pkg/controller/route/cruds.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@ func (c *Controller) reconcilePlaceholderService(ctx context.Context, route *v1a
// Update the Status of the route. Caller is responsible for checking
// for semantic differences before calling.
func (c *Controller) updateStatus(ctx context.Context, route *v1alpha1.Route) (*v1alpha1.Route, error) {
logger := logging.FromContext(ctx)

existing, err := c.routeLister.Routes(route.Namespace).Get(route.Name)
if err != nil {
logger.Warn("Failed to update route status", zap.Error(err))
c.Recorder.Eventf(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to get current status for route %q: %v", route.Name, err)
return nil, err
}
// If there's nothing to update, just return.
Expand All @@ -122,8 +118,6 @@ func (c *Controller) updateStatus(ctx context.Context, route *v1alpha1.Route) (*
// TODO: for CRD there's no updatestatus, so use normal update.
updated, err := c.ServingClientSet.ServingV1alpha1().Routes(route.Namespace).Update(existing)
if err != nil {
logger.Warn("Failed to update route status", zap.Error(err))
c.Recorder.Eventf(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update status for route %q: %v", route.Name, err)
return nil, err
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ func (c *Controller) Reconcile(key string) error {
// cache may be stale and we don't want to overwrite a prior update
// to status with this stale state.
} else if _, err := c.updateStatus(ctx, route); err != nil {
logger.Warn("Failed to update route status", zap.Error(err))
c.Recorder.Eventf(route, corev1.EventTypeWarning, "UpdateFailed",
"Failed to update status for route %q: %v", route.Name, err)
return err
}
return err
Expand Down
Loading

0 comments on commit a7140e6

Please sign in to comment.