Skip to content

Commit

Permalink
Ignore special errors in codegen for events
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor committed Jul 30, 2021
1 parent 3826bb2 commit 6f322d7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions client/injection/kube/reconciler/core/v1/namespace/reconciler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions client/injection/kube/reconciler/core/v1/secret/reconciler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions codegen/cmd/injection-gen/generators/reconciler_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ func (g *reconcilerReconcilerGenerator) GenerateType(c *generator.Context, t *ty
Package: "knative.dev/pkg/reconciler",
Name: "DoObserveFinalizeKind",
}),
"controllerIsSkipKey": c.Universe.Function(types.Name{
Package: "knative.dev/pkg/controller",
Name: "IsSkipKey",
}),
"controllerIsRequeueKey": c.Universe.Function(types.Name{
Package: "knative.dev/pkg/controller",
Name: "IsRequeueKey",
}),
}

sw.Do(reconcilerInterfaceFactory, m)
Expand Down Expand Up @@ -517,8 +525,14 @@ func (r *reconcilerImpl) Reconcile(ctx {{.contextContext|raw}}, key string) erro
return nil
}
logger.Errorw("Returned an error", zap.Error(reconcileEvent))
r.Recorder.Event(resource, {{.corev1EventTypeWarning|raw}}, "InternalError", reconcileEvent.Error())
if {{ .controllerIsSkipKey|raw }}(reconcileEvent) {
// This is a wrapped error, don't emit an event.
} else if ok, _ := {{ .controllerIsRequeueKey|raw }}(reconcileEvent); ok {
// This is a wrapped error, don't emit an event.
} else {
logger.Errorw("Returned an error", zap.Error(reconcileEvent))
r.Recorder.Event(resource, {{.corev1EventTypeWarning|raw}}, "InternalError", reconcileEvent.Error())
}
return reconcileEvent
}
Expand Down

0 comments on commit 6f322d7

Please sign in to comment.