Rotem Tamir
1 min readMar 24, 2019

--

Super helpful, thanks for this! Just a suggestion for making this more accurate, as it appears to be one of the only resources online on this topic.

In the time between your List() and Watch() API calls new resources can be added/modified/deleted. If your goal is to maintain a state consistent with the cluster, you must account for this gap.

The canonical way, suggested by the Kubernetes docs[1], is to utilize the ResourceVersion field. Every resource in the k8s API has a resource version. When you LIST your PVCs you get back a resource version for the PVC list. When you start to WATCH the list, you can supply that resource version in the v1.ListOptions object.

Kubernetes will start playing the changes from this revision and not from the current latest.

Otherwise, awesome write-up, thanks again!

[1] https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes

--

--

Rotem Tamir
Rotem Tamir

No responses yet