Lossy map functions
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia leggendo le definizioni di MapFunc e EnqueueRequestsFromMapFunc e il comportamento circostante di EventHandler in controller-runtime. Esamina gli esempi di utilizzo collegati e la discussione su una progettazione concordata e tollerante ai guasti per il mapping. Il lavoro è completato quando il progetto dispone di un approccio definito per gli errori di mapping, oltre all’implementazione e ai test corrispondenti, invece di una semplice soluzione alternativa proposta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Preface
This relates to a conversation I brought up at the community meeting on 2022-09-08, @camilamacedo86 and @jmrodri suggested I create an issue so we can discuss it further.
Background
Currently in controller-runtime we have the following tools:
type MapFunc func(client.Object) []reconcile.Request
func EnqueueRequestsFromMapFunc(fn MapFunc) EventHandler {
return &enqueueRequestsFromMapFunc{
toRequests: fn,
}
}
With these it's possible to express a Watch() on one source.Kind which enqueues objects of another kind by some arbitrary relation:
ctrl.NewControllerManagedBy(mgr).Watches(
&source.Kind{Type: &customapi.Tree},
handler.EnqueueRequestsFromMapFunc(r.mapFruitsFromTree),
)
Now ideally you use metav1.ObjectReference when dealing with relationships between objects, however it can sometimes be the case that you need to use the API client or some other utility that may produce an error to map the related objects, e.g.:
func (r *myReconciler) mapFruitsFromTree(tree client.Object) []reconcile.Request {
var fruits customapi.FruitList
if err := r.client.List(context.Background(), &fruits); err != nil {
r.log.WithError(err).Error("error listing fruits")
return nil
}
var req []reconcile.Request
for _, fruit := range fruits.Items {
if isRelated(tree, fruit) {
req = append(req, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: fruit.Namespace,
Name: fruit.Name,
},
})
}
}
return req
}
In these cases it would appear there is effectively no provisions to handle error conditions.
This kind of implementation and use case is not uncommon. I was able to find several examples of notable open source projects which are using it this way:
- https://github.com/projectcontour/contour/blob/2e758465348d8ebc32b037fbc5ce899e36cf036f/internal/controller/gateway.go#L124
- https://github.com/kumahq/kuma/blob/abd89b44c5ee3bf5b57c13d7379b3c2b15ed5aba/pkg/plugins/runtime/k8s/controllers/configmap_controller.go#L100
- https://github.com/cert-manager/cert-manager/blob/e82c72cff03dda703ca918d32ab11f719edfcd88/pkg/controller/cainjector/indexers.go#L40
- https://github.com/Kong/kubernetes-ingress-controller/blob/185f9d7c842869179dda844e6a28926468657b7f/internal/controllers/gateway/gateway_controller.go#L178
Problem
The EnqueueRequestsFromMapFunc generator for EventHandlers has no concept of handling errors that may occur when making the mapping. As such in the example above and all the links provided for projects which are doing this that process is currently "lossy": that is to say, it appears the machinery could effectively end up dropping an enqueued object from the queue if a failure occurred during the mapping process.
For a specific example using the Tree and Fruit sample above: if the object listing produces an error (e.g. performed at a time when the API server is having trouble and cache can't be used) this failure means that the Tree object is consumed from the queue but the related objects don't get enqueued. This would cause the resource state to become "stuck" and this wont heal without adding some other mechanism to re-queue it, or some unrelated action to re-trigger it.
Exploring Solutions
The purpose of this issue is to ask for community guidance on an existing or new provision to support this kind of mapping in a manner that is fault tolerant and can heal from an error.
Some of the workarounds that I have conceived of are:
- using object references as mentioned above (wont work in all cases)
- some fallback process which would actively re-enqueue all relevant objects (messy, costly)
- watching a custom backup
source.Channelwhere objects are re-enqueued in an implementation-specific manner (clunky)
So far I think the third option there might be the most effective strategy with what we have today, but ideally what I would like to see is the ability to cleanly trigger a re-queue from within the mapping function as part of the function return. I would very much appreciate community feedback on this.
- Lingua principale
- Go
- Stelle
- 3k
- Fork
- 1.3k
- Merge medio
- 1g 7h
- PR unite (30g)
- 48
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di kubernetes-sigs/controller-runtime
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
kubernetes-sigs/controller-runtime#3704 ·
I maintainer di solito rispondono entro 1 giorno
-
lifecycle/rotten
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
kubernetes-sigs/controller-runtime#3537 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Read-your-writes consistency is not applied to unstructured objects written with Update or PatchForse già presa @7616e5a9c573ffb221843a498885ab0f l’ha presa 1 giorno fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 25/100
kubernetes-sigs/controller-runtime#3702 ·
I maintainer di solito rispondono entro 1 giorno
-
Client and DynamicRESTMapper keep a kind's old scope after its CRD is recreated with a different `scope`Forse già presa @AdamMagued l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
kubernetes-sigs/controller-runtime#3671 ·
I maintainer di solito rispondono entro 1 giorno
-
ReadYourWrite doesn't correctly deal with mutating requests removing the last finalizerForse già presa @AdamMagued l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
kubernetes-sigs/controller-runtime#3670 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di kubernetes-sigs/controller-runtime
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
expr-lang/expr#1037 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
provider-key submission
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
opentofu/registry#6740 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nightgauge/nightgauge#3713 ·
I maintainer di solito rispondono entro 1 giorno
-
fix: restore GitHub issue templates and check their license headersForse già presa @slievrly l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni