* Fix codegen to work outside GOPATH
* Fix ReconcilerEvent handling of %w format strings
Using fmt.Errorf(...).Error() means we get %w's translated to %v's for
printing
* Add possibility to implement a deletion handler in a reconciler.
ObserveFinalizeKind is not guaranteed to be called for every resource
that gets deleted, even if they do have a finalizer. The leader can race
the observers in removing the finalizer so the observers would not even
see the deletion.
Using the OnDelete handler on the informer is equally racy in that it
can trigger the deletion handler while a potential "normal" reconcile is
still in-flight.
This adds an ObserveDeletedKind handler that can be implemented by
reconcilers. The events still go via the workQueue, so proper order and
deduplication is guaranteed. Observation is guaranteed as well. In most
if not all cases, this handler should replace the ObserveFinalizeKind
handler.
* Move interface to its own file
* Fix license
* Fix comment
* Fix#2003
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
* Removed useless newline
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
* Removed useless check
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
* Now we don't have any newlines anymore
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
* add filtered InformerFactory and informers which only list and watch resources with the given labels
* rename to RegisterFilteredInformers
* generated files
* typo
* update per comments
* rename file
* rm old files
This change introduces a new `controller.NewSkipKey` method to designate certain reconciliations as "skipped".
The primary motivation for this is to squelch useless logging on non-leader replicas, which currently report success with trivial latency.
I have plumbed this through existing reconcilers and the code-gen so most things downstream should get this for free. In places where a key is observed, I do not mark the reconcile as skipped as the reconciler did some processing for which the awareness of side-effects and reported latency may be interesting.
This uses the presence of the config key to determine whether
this is an injection context, and if it is not, the panic
message includes a notice about injection context behavior.
* use const when gen reconciler
* move to reconciler common
Signed-off-by: RyderXia <ryder.xia@sap.com>
* update
Signed-off-by: RyderXia <ryder.xia@sap.com>
* Add an option to skip automated status updates in a reconciler.
This option is necessary to be able to create reconcilers like Serving's labeler, that is purely adding labels to resources. If that fails, the new automated observed generation handling changes the status and that gets written to the API currently, which is not desired.
* Flip the bool.
* Abort reconcilation on finalizer patch errors.
This aborts reconcilation if finalizers could not be patched correctly with an error and thus it retries.
We shouldn't start a reconcilation if we haven't been able to correctly add the finalizer first. Otherwise we could get into a weird spot where the resources are created before the finalizer and in a very degenerate case the finalizer wouldn't even be executed. Also, the current code has a bug where if the patch fails the resource coming back from the patch (essentially an empty object) is passed into ReconcileKind, causing headaches.
The same imo goes for removing a finalizer. Failing to remove a finalizer blocks the resource forever, thus we should retry if that happens too.
* Add generated code.
* Some nits in the genreconciler
- make sure we allocate proper amount of slice space
- `t:=t` is needed only if you're doing goroutines in the loop
- extract constants outside of the loops.
- reformat
* meh, I was wrong
* generate krshaped logic
* add logic to the tag
* Update injection/README.md
Co-authored-by: Matt Moore <mattmoor@vmware.com>
* move var to reconciler
Co-authored-by: Matt Moore <mattmoor@vmware.com>
* Add the ability to override controller agent name
- controller can set agent name via context. If nothing is set then
controller falls back to default controller agent name
* Check if context name is not nil and can be casted to string before returning.
* Create EventRecorder after we determine the controller agent name
* Address comments
Signed-off-by: Andrew Su <asu@pivotal.io>
* Remove check for if recorder is nil
Co-authored-by: Andrew Su <asu@pivotal.io>
This changes the names we give workqueues in genreconciler to avoid collisions when multiple reconcilers in a single process use the same generated reconciler base.
There are a few examples of this in serving, both route and configuration have collisions. Right now I think this mainly affects metrics published by the workqueues, but I noticed this leveraging the same for resource lock naming.