Lossy map functions
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza leyendo las definiciones de MapFunc y EnqueueRequestsFromMapFunc y el comportamiento circundante de EventHandler en controller-runtime. Revisa los ejemplos de uso enlazados y la discusión sobre un diseño acordado y tolerante a fallos para el mapeo. Se considera terminado cuando el proyecto tiene un enfoque decidido para los errores de mapeo, junto con la implementación y las pruebas correspondientes, en lugar de solo una solución alternativa propuesta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 3k
- Forks
- 1.3k
- Merge medio
- 1 d 7 h
- PR fusionados (30 d)
- 48
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de kubernetes-sigs/controller-runtime
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
kubernetes-sigs/controller-runtime#3704 ·
Los mantenedores suelen responder en 1 día
-
lifecycle/rotten
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
kubernetes-sigs/controller-runtime#3537 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Read-your-writes consistency is not applied to unstructured objects written with Update or PatchPosiblemente ocupada @7616e5a9c573ffb221843a498885ab0f la tomó hace 1 día. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 25/100
kubernetes-sigs/controller-runtime#3702 ·
Los mantenedores suelen responder en 1 día
-
Client and DynamicRESTMapper keep a kind's old scope after its CRD is recreated with a different `scope`Posiblemente ocupada @AdamMagued la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
kubernetes-sigs/controller-runtime#3671 ·
Los mantenedores suelen responder en 1 día
-
ReadYourWrite doesn't correctly deal with mutating requests removing the last finalizerPosiblemente ocupada @AdamMagued la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
kubernetes-sigs/controller-runtime#3670 · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de kubernetes-sigs/controller-runtime
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
OneBusAway/watchdog#470 ·
Los mantenedores suelen responder en 1 día
-
area: session
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
charmbracelet/crush#4484 ·
Los mantenedores suelen responder en 1 día
-
[Resource]: HearthAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
hesreallyhim/awesome-claude-code#3713 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
expr-lang/expr#1037 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Provider Key: Sauberr/neckrezAbiertoprovider-key submission
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
opentofu/registry#6740 · 1 comentario ·
Los mantenedores suelen responder en 1 día