Skip to content

Commit

Permalink
codegen: fix DeepCopy races
Browse files Browse the repository at this point in the history
Fixes istio/api#3019

The deepcopygen we use is from Kubernetes. Its not quite suitable for
our types due to our usage of protobuf, which has limitations on
dereferencing pointer types. This causes race conditions in concurrent
usage of the DeepCopy function.

This is possible to trigger with real Istio (found by running Istio in a
live cluster with `-race`, though our current tests happen to not
trigger things I guess), as well as other usage of istio/client-go (as
the reporter found).

I ran istio/istio with this change and found all tests continue to pass,
and running in a live cluster no longer fails
  • Loading branch information
howardjohn committed Dec 12, 2024
1 parent 6bad57d commit 830bc1c
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 64 deletions.
7 changes: 7 additions & 0 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ rename_generated_files=\
find $(subst istio.io/client-go/, $(empty), $(subst $(comma), $(space), $(kube_api_packages)) $(kube_clientset_package) $(kube_listers_package) $(kube_informers_package)) \
-name '*.go' -and -not -name 'doc.go' -and -not -name '*.gen.go' -type f -exec sh -c 'mv "$$1" "$${1%.go}".gen.go' - '{}' \;

# Kubernetes deepcopy gen directly sets values of our types. Our types our protos; it is illegal to do this for protos.
# However, we don't even need this anyways -- each individual field is explicitly copied already.
# Remove this line.
fixup_generated_files=\
find . -name "*.deepcopy.gen.go" -type f | xargs sed -i -e '/\*out = \*in/d'

.PHONY: generate-k8s-client
generate-k8s-client:
# generate kube api type wrappers for istio types
Expand All @@ -117,6 +123,7 @@ generate-k8s-client:
@$(informer_gen) --input-dirs $(kube_api_packages) --versioned-clientset-package $(kube_clientset_package)/$(kube_clientset_name) --listers-package $(kube_listers_package) --output-package $(kube_informers_package) -h $(kube_go_header_text)
@$(move_generated)
@$(rename_generated_files)
@$(fixup_generated_files)

.PHONY: build-k8s-client verify-k8s-client
build-k8s-client:
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/extensions/v1alpha1/zz_generated.deepcopy.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions pkg/apis/networking/v1/zz_generated.deepcopy.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions pkg/apis/networking/v1alpha3/zz_generated.deepcopy.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 830bc1c

Please sign in to comment.