clientgofix is a tool for adjusting k8s.io/client-go invocations for k8s.io/client-go v0.18.0+ versions.
It can be run on a codebase before or after updating the k8s.io/client-go dependency.
See https://git.k8s.io/enhancements/keps/sig-api-machinery/20200123-client-go-ctx.md for more context.
Automatic adjustments:
- Inserts a
context.TODO()argument where required - Inserts an empty options struct argument where required (like
metav1.UpdateOptions{}) - Dereferences existing
*metav1.DeleteOptionsarguments - Replaces existing nil
*metav1.DeleteOptionsarguments withmetav1.DeleteOptions{} - Adds
contextandmetav1imports where required (deconflicting with existing import and declaration names)
Manual adjustments required:
- Context parameters passed to
rest.Request#Contextmust be manually moved to the requestDo()invocation.
To install:
git clone https://github.com/kubernetes-sigs/clientgofix.git
cd clientgofix
make installTo use:
cd /path/to/project
clientgofix ./pkg/to/fixOptions:
-
Multiple packages or a recursive package spec can be provided:
clientgofix ./pkg1 ./pkg2clientgofix ./...
-
Files are rewritten in place by default. Set
-overwrite=falseto write to peer tmp files. -
If errors are encountered processing a file, writing is skipped by default. Set
-write-on-error=trueto write the file even when errors are encountered.