Client and DynamicRESTMapper keep a kind's old scope after its CRD is recreated with a different `scope`
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- go, kubernetes
- Área
- infrastructure
Línea de trabajo
Start in pkg/client/apiutil/restmapper.go to see how a group's mappings are cached and only reloaded on NoMatch, and check whether meta.ResettableRESTMapper can be satisfied there. Then read getResource in pkg/client/client_rest_resources.go to see how resourceByType pins a GVK's resourceMeta for the client's lifetime and how a mapper generation or per-GVK eviction could make it re-resolve. Done means a CRD recreated with a different spec.scope is picked up by a client sharing the invalidated mapper, with tests covering both Cluster→Namespaced and the reverse.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
(re-raising #3303)
Problem
#3303 described this precisely and closed as rotten with no fix. We hit it independently, as did Crossplane users
(crossplane/crossplane#6736), so we are re-raising it with a concrete, small proposal.
When a CRD is deleted and recreated under the same GroupVersionKind with a different spec.scope (Cluster ↔
Namespaced), a long-running controller-runtime client keeps addressing the old path until the process restarts:
client.ClientcachesresourceMeta, mapping included, per GVK inresourceByTypeand never invalidates it
(pkg/client/client_rest_resources.go,getResource).DynamicRESTMapperreloads a group only onNoMatch(pkg/client/apiutil/restmapper.go). A recreate keeps the kind
matching, so the stale scope is never reloaded.
Symptoms: writes to a now-namespaced kind go to the cluster path and 404 ("the server could not find the requested
resource"). The reverse direction fails with "an empty namespace may not be set when a resource name is provided".
Informers built from the mapper inherit the wrong scope too.
This is an edge case, since scope is effectively immutable. But it is the ONLY way to change scope, and systems that
manage CRDs programmatically (Crossplane XRDs, operators that generate CRDs) do it at runtime.
Proposal (small, opt-in)
- Mapper invalidation. Add to the dynamic RESTMapper a way to drop one group's cached mappings, so that the next
lookup reloads it. For example, an exportedInvalidateGroup(group string), orReset()for the whole mapper,
satisfyingmeta.ResettableRESTMapper(some tooling already expects that interface). - Client follows the mapper. Either key
resourceByTypeentries to a mapper generation that bumps on every reload
or invalidation, so a stale entry re-resolves, or have the client drop its entry for a GVK when the mapper is
invalidated for that GVK's group.
With (1) and (2), a controller that watches its CRDs, as Crossplane's XRD reconciler does, can call
InvalidateGroup on a recreate, and every client sharing that mapper follows. Nothing changes for anyone who never
calls it. That answers the "not too invasive" bar from #3303.
The watch question from #3303: informers created after the invalidation use the new scope. Already-running informers
for the old scope must be torn down by their owner, as they already are when a CRD is deleted. The mapper change only
guarantees that the new ones are right.
Reproduction
Reproduced through Crossplane, which changes XRD scope this way: on Crossplane v2.5.0-rc.1 and v2.4.3 (Kubernetes v1.37.0, kind), after an XRD is deleted and recreated with scope: Namespaced, a new XR gets no finalizer and no conditions for as long as the process runs (checked at 30, 60 and 120 s), and is reconciled within seconds of a restart. A Crossplane issue with the full output will link here. A plain-CRD version:
create a CRD with scope Cluster; start a manager and Get or List the kind; delete the CRD; recreate it with scope
Namespaced; Create a namespaced object through the same client and observe the 404 at the cluster path; restart and
observe success.
We are willing to send the PR.
This issue was drafted with AI assistance (Claude) from our own observation and a reading of the controller-runtime
source; a human reviewed it before posting.
- 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
-
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
-
With UsePriorityQueue=false, a stopped controller starts queued reconciles after cancellationPosiblemente ocupada @hcrosse la tomó hace 14 días. Abiertokind/bug
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
kubernetes-sigs/controller-runtime#3664 ·
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