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

Aperta
#3,702 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@7616e5a9c573ffb221843a498885ab0f ci sta già lavorando.

Dal 27/11/2026.

  • #3703 di @7616e5a9c573ffb221843a498885ab0f — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
3k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
48

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di kubernetes-sigs/controller-runtime

Tutte le issue di kubernetes-sigs/controller-runtime

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.