Read-your-writes consistency is not applied to unstructured objects written with Update or Patch

Abierto
#3,702 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@7616e5a9c573ffb221843a498885ab0f ya está trabajando en esto.

Desde el 27/11/2026.

  • #3703 de @7616e5a9c573ffb221843a498885ab0f — abierto

Evaluación

Dificultad
1/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
go

Línea de trabajo

Read pkg/client/consistency.go, especially writeTargetFor and representationIDForObj, then inspect TestConsistentFakeClient for the proposed unstructured cases. The issue reports an open linked pull request (#3703), so the work is already under way; completion is demonstrated by those tests failing on the current behavior and passing with the fix.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

With Cache.Unstructured: true and EnableReadYourWritesConsistency: true, a Get or List of an *unstructured.Unstructured does not wait for an earlier Create, Update, Patch, Status().Update or Status().Patch of the same object made through the same client. The read returns whatever the cache has, so it can be older than the client's own write.

Cause

The consistent client keys its write barriers and consistency handlers by GVK plus representation (typed, unstructured, or PartialObjectMetadata).

Reads pick the representation from the object's Go type:

https://github.com/kubernetes-sigs/controller-runtime/blob/1e19b8e06116d06d05dc518c6632817cef14e083/pkg/client/consistency.go#L104-L113

Writes go through writeTargetFor. Its case Object: branch, which handles everything that isn't an apply configuration or PartialObjectMetadata, always uses representationIDTyped:

https://github.com/kubernetes-sigs/controller-runtime/blob/1e19b8e06116d06d05dc518c6632817cef14e083/pkg/client/consistency.go#L330-L339

So an unstructured Update records its resource version under the typed key, and the following unstructured Get looks under the unstructured key, finds no barrier and no minimum resource version, and returns straight away. Only writes made with client.ApplyConfigurationFromUnstructured are recorded as unstructured.

Why the tests don't catch it

The envtest suite has an "unstructured" context, but its client doesn't set Cache.Unstructured: true:

https://github.com/kubernetes-sigs/controller-runtime/blob/1e19b8e06116d06d05dc518c6632817cef14e083/pkg/client/consistency_envtest_test.go#L115-L122

Unstructured reads therefore bypass the cache and hit the API server, so they pass either way. TestConsistentFakeClient only uses typed objects.

How we hit it

We enabled the option in Crossplane, which reads and writes composite resources as unstructured objects with Update and Patch, to stop a reconciler acting on a cached object that was missing its own previous status write. The stale reads kept happening. The controller_runtime_client_consistency_wait_duration_seconds histogram for get showed no waits in the 10ms to 100ms range at all.

With the change below the stale reads stopped.

Fix

 	case Object:
 		gvk, err := apiutil.GVKForObject(t, scheme)
 		if err != nil {
 			return gvkAndRepresentation{}, types.NamespacedName{}, nil, nil, fmt.Errorf("failed to get GVK for object %T: %w", obj, err)
 		}
-		return gvkAndRepresentation{gvk: gvk, representation: representationIDTyped},
+		return gvkAndRepresentation{gvk: gvk, representation: representationIDForObj(t)},

I have this with unstructured cases added to TestConsistentFakeClient; they fail on main and pass with the change. I can open a PR.

Versions

Seen on v0.25.2. The code is the same in v0.25.3 and on main at 1e19b8e0.

Lenguaje dominante
Go
Estrellas
3k
Forks
1.3k
Merge medio
1 d 7 h
PR fusionados (30 d)
48

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de kubernetes-sigs/controller-runtime

Todos los issues de kubernetes-sigs/controller-runtime

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.