Controller-runtime: Updating an Istio VirtualService requires resourceVersion

Created on 19 Dec 2019  路  2Comments  路  Source: kubernetes-sigs/controller-runtime

I'm managing an Istio VirtualService in my controller. However I am unable to update it without manually specifying the resourceVersion. Why is this required when none of the other resources in my controller need it? I'm using kubebuilder and controller-runtime v0.4.0.

2019-12-19T15:56:43.469Z        ERROR   controller-runtime.controller   Reconciler error        {"controller": "route", "request": "test-4lncn2/my-route", "error": "virtualservices.networking.istio.io \"my-route\" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update"}

Most helpful comment

The standard update in Kubernetes is a "conditional update". In a conditional update, the resource version of the update request is checked to see if it matches the stored resource version. If it does, the update proceeds. If not, the update fails. It's roughly analogous to a CompareAndSwap operation.

Some resources also allow "unconditional updates", in which resourceVersion is not set on the update request, and thus the update always goes through. No custom resources support unconditional updates, and VirtualService is a custom resource.

If you really want to mimic an unconditional update, I believe a PATCH operation should suffice.

All 2 comments

The standard update in Kubernetes is a "conditional update". In a conditional update, the resource version of the update request is checked to see if it matches the stored resource version. If it does, the update proceeds. If not, the update fails. It's roughly analogous to a CompareAndSwap operation.

Some resources also allow "unconditional updates", in which resourceVersion is not set on the update request, and thus the update always goes through. No custom resources support unconditional updates, and VirtualService is a custom resource.

If you really want to mimic an unconditional update, I believe a PATCH operation should suffice.

Great answer - thanks!

Was this page helpful?
0 / 5 - 0 ratings