From 7f805d8e1a14666b392039aadf9a64a37e7ac679 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Wed, 1 Oct 2025 15:02:45 -0600 Subject: [PATCH] Unistore: Add comment on how RV checks are working (#111898) --- pkg/storage/unified/apistore/store.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/storage/unified/apistore/store.go b/pkg/storage/unified/apistore/store.go index 51422b4ff25..a6c37c00dab 100644 --- a/pkg/storage/unified/apistore/store.go +++ b/pkg/storage/unified/apistore/store.go @@ -533,6 +533,18 @@ func (s *Storage) GuaranteedUpdate( if err != nil { return err } + // NOTE: by default, the RV will **not** be set in the preconditions (it is removed here: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go#L187) + // instead, the RV check is done with the object from the request itself. + // + // the object from the request is retrieved in the tryUpdate function (we use the generic k8s store one). this function calls the UpdateObject function here: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go#L653 + // and that will run a series of transformations: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/registry/rest/update.go#L219 + // + // the specific transformations it runs depends on what type of update it is. + // for patch, the transformers are set here and use the patchBytes from the request: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go#L697 + // for put, it uses the object from the request here: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go#L163 + // + // after those transformations, the RV will then be on the object so that the RV check can properly be done here: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go#L662 + // it will be compared to the current object that we pass in below from storage. if preconditions != nil && preconditions.ResourceVersion != nil { req.ResourceVersion, err = strconv.ParseInt(*preconditions.ResourceVersion, 10, 64) if err != nil {