crossplane / crossplane/crossplane-runtime
Deprecate `resource.ClientApplicator`
- Dominant language
- Go
- Stars
- 198
- Forks
- 161
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 9
Description
Edit from @negz: I'd like to drop the `resource.ClientApplicator`. For `*Unstructured` resources we've mostly already replaced it with SSA. For concrete types, I've found a few places where it's been easy to just replace it with `Get` + `Update`. Using https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/controller/controllerutil#CreateOrUpdate would probably be fine too.
Original issue follows:
---
### What happened?
Looking at the claim controller, updating the XR (`cp` in the code), the following race with other actors in the system (controllers, user with kubectl) exists:
1. reconciler [gets latest XR state](https://github.com/crossplane/crossplane/blob/7053ceb47dc867de7904838a1e87924079da8aba/internal/controller/apiextensions/claim/reconciler.go#L395) `cp`
2. reconciler updates in the `cp` whatever it wants to update
3. reconciler [calls Apply](https://github.com/crossplane/crossplane/blob/7053ceb47dc867de7904838a1e87924079da8aba/internal/controller/apiextensions/claim/reconciler.go#L523) with `cp`
- applicator [gets current state via client](https://github.com/crossplane/crossplane-runtime/blob/4374a3b5d1ff58214b118a7cea641230bfbc785f/pkg/resource/api.go#L186)
- applicator [sets RV](https://github.com/crossplane/crossplane-runtime/blob/4374a3b5d1ff58214b118a7cea641230bfbc785f/pkg/resource/api.go#L203C2-L203C68) `cp.RV = current.RV`
- applicator [calls update](https://github.com/crossplane/crossplane-runtime/blob/4374a3b5d1ff58214b118a7cea641230bfbc785f/pkg/resource/api.go#L204) with cp
Assuming between 1 and 3a some client updates the XR out of band, e.g. some other controller, or kubectl. 3c will wipe out that change, won't it?
Above is just one example for that issue. The apply func is widely used in Crossplane.
### How can we reproduce it?
This will likely show up as subtle bugs as this is some kind of time travel, or controllers fighting for their desired state of the world and racing with their informers.
### What environment did it happen in?
Crossplane version: main
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.