Skip to content

Commit bf01489

Browse files
authored
Update makefile and client-go (#842)
1 parent 68c5886 commit bf01489

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1243
-1615
lines changed

Makefile

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,51 @@ build-dubboctl:
2222
.PHONY: clone-sample
2323
clone-sample:
2424
mkdir -p bin
25-
cp -r samples bin/samples
25+
cp -r samples bin/samples
26+
27+
# allow optional per-repo overrides
28+
-include Makefile.overrides.mk
29+
30+
# Set the environment variable BUILD_WITH_CONTAINER to use a container
31+
# to build the repo. The only dependencies in this mode are to have make and
32+
# docker. If you'd rather build with a local tool chain instead, you'll need to
33+
# figure out all the tools you need in your environment to make that work.
34+
export BUILD_WITH_CONTAINER ?= 0
35+
36+
ifeq ($(BUILD_WITH_CONTAINER),1)
37+
38+
# An export free of arguments in a Makefile places all variables in the Makefile into the
39+
# environment. This is needed to allow overrides from Makefile.overrides.mk.
40+
export
41+
42+
RUN = ./tools/scripts/run.sh
43+
44+
MAKE_DOCKER = $(RUN) make --no-print-directory -e -f Makefile.core.mk
45+
46+
%:
47+
@$(MAKE_DOCKER) $@
48+
49+
default:
50+
@$(MAKE_DOCKER)
51+
52+
shell:
53+
@$(RUN) /bin/bash
54+
55+
.PHONY: default shell
56+
57+
else
58+
59+
# If we are not in build container, we need a workaround to get environment properly set
60+
# Write to file, then include
61+
$(shell mkdir -p out)
62+
$(shell $(shell pwd)/tools/scripts/setup_env.sh envfile > out/.env)
63+
include out/.env
64+
# An export free of arguments in a Makefile places all variables in the Makefile into the
65+
# environment. This behavior may be surprising to many that use shell often, which simply
66+
# displays the existing environment
67+
export
68+
69+
export GOBIN ?= $(GOPATH)/bin
70+
include Makefile.core.mk
71+
72+
endif

Makefile.common.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tidy-go:
2+
@find -name go.mod -execdir go mod tidy \;
3+
4+
mod-download-go:
5+
@-GOFLAGS="-mod=readonly" find -name go.mod -execdir go mod download \;
6+
# go mod tidy is needed with Golang 1.16+ as go mod download affects go.sum
7+
# https://github.com/golang/go/issues/43994
8+
@find -name go.mod -execdir go mod tidy \;
9+
10+
format-go: tidy-go
11+
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} common/scripts/format_go.sh
12+
13+
.PHONY: format-go tidy-go mod-download-go

Makefile.core.mk

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
gen: generate-k8s-client tidy-go
2+
3+
clean: clean-k8s-client
4+
5+
applyconfiguration_gen = applyconfiguration-gen
6+
kubetype_gen = kubetype-gen
7+
deepcopy_gen = deepcopy-gen
8+
client_gen = client-gen
9+
lister_gen = lister-gen
10+
informer_gen = informer-gen
11+
12+
empty:=
13+
space := $(empty) $(empty)
14+
comma := ,
15+
16+
kube_dubbo_source_packages = $(subst $(space),$(empty), \
17+
./api/networking/v1alpha3 \
18+
)
19+
20+
kube_base_output_package = client-go/pkg
21+
kube_api_base_package = $(kube_base_output_package)/apis
22+
kube_api_packages = $(subst $(space),$(empty), \
23+
$(kube_api_base_package)/networking/v1alpha3 \
24+
)
25+
26+
kube_api_applyconfiguration_packages = $(kube_api_packages),k8s.io/apimachinery/pkg/apis/meta/v1
27+
kube_clientset_package = $(kube_base_output_package)/clientset
28+
kube_clientset_name = versioned
29+
kube_listers_package = $(kube_base_output_package)/listers
30+
kube_informers_package = $(kube_base_output_package)/informers
31+
kube_applyconfiguration_package = $(kube_base_output_package)/applyconfiguration
32+
33+
kube_go_header_text = header.go.txt
34+
35+
ifeq ($(IN_BUILD_CONTAINER),1)
36+
# k8s code generators rely on GOPATH, using $GOPATH/src as the base package
37+
# directory. Using --output-base . does not work, as that ends up generating
38+
# code into ./<package>, e.g. ./client-go/pkg/apis/... To work
39+
# around this, we'll just let k8s generate the code where it wants and copy
40+
# back to where it should have been generated.
41+
move_generated=([ -d $(GOPATH)/src/$(kube_base_output_package)/ ] && cp -r $(GOPATH)/src/$(kube_base_output_package)/ client-go/ && rm -rf $(GOPATH)/src/$(kube_base_output_package)/) || true
42+
else
43+
# nothing special for local builds
44+
move_generated=
45+
endif
46+
47+
rename_generated_files=\
48+
for dir in $(subst client-go/, $(empty), $(subst $(comma), $(space), $(kube_api_packages)) $(kube_clientset_package) $(kube_listers_package) $(kube_informers_package)); do \
49+
if [ -d "$$dir" ]; then \
50+
find "$$dir" -name '*.go' -and -not -name 'doc.go' -and -not -name '*.gen.go' -type f -exec sh -c 'mv "$$1" "$${1%.go}".gen.go' - '{}' \; ; \
51+
fi \
52+
done
53+
54+
55+
# Kubernetes deepcopy gen directly sets values of our types. Our types are protos; it is illegal to do this for protos.
56+
# However, we don't even need this anyways -- each individual field is explicitly copied already.
57+
# Remove the line doing this illegal operation.
58+
fixup_generated_files=\
59+
find . -name "*.deepcopy.gen.go" -type f -exec sed -i '' -e '/\*out = \*in/d' {} +
60+
61+
.PHONY: generate-k8s-client
62+
generate-k8s-client:
63+
# generate kube api type wrappers for dubbo types
64+
@GODEBUG=gotypesalias=0 $(kubetype_gen) --input-dirs $(kube_dubbo_source_packages) --output-package $(kube_api_base_package) -h $(kube_go_header_text)
65+
@$(move_generated)
66+
# generate deepcopy for kube api types
67+
@$(deepcopy_gen) --input-dirs $(kube_api_packages) -O zz_generated.deepcopy -h $(kube_go_header_text)
68+
# generate ssa for kube api types
69+
@$(applyconfiguration_gen) --input-dirs $(kube_api_applyconfiguration_packages) --output-package $(kube_applyconfiguration_package) -h $(kube_go_header_text)
70+
# generate clientsets for kube api types
71+
@$(client_gen) --clientset-name $(kube_clientset_name) --input-base "" --input $(kube_api_packages) --output-package $(kube_clientset_package) -h $(kube_go_header_text) --apply-configuration-package $(kube_applyconfiguration_package)
72+
# generate listers for kube api types
73+
@$(lister_gen) --input-dirs $(kube_api_packages) --output-package $(kube_listers_package) -h $(kube_go_header_text)
74+
# generate informers for kube api types
75+
@$(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)
76+
@$(move_generated)
77+
@$(rename_generated_files)
78+
@$(fixup_generated_files)
79+
80+
.PHONY: clean-k8s-client
81+
clean-k8s-client:
82+
# remove generated code
83+
@rm -rf client-go/pkg
84+
85+
include Makefile.common.mk

Makefile.overrides.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BUILD_WITH_CONTAINER ?= 1

api/networking/v1alpha3/destination_rule.pb.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/networking/v1alpha3/destination_rule.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ import "networking/v1alpha3/virtual_service.proto";
2828

2929
option go_package = "/api/networking/v1alpha3";
3030

31+
// <!-- crd generation tags
32+
// +cue-gen:DestinationRule:groupName:networking.dubbo.apache.org
33+
// +cue-gen:DestinationRule:versions:v1alpha3
34+
// +cue-gen:DestinationRule:annotations:helm.sh/resource-policy=keep
35+
// +cue-gen:DestinationRule:labels:app=dubbo-planet,chart=dubbo,heritage=Tiller,release=dubbo
36+
// +cue-gen:DestinationRule:subresource:status
37+
// +cue-gen:DestinationRule:scope:Namespaced
38+
// +cue-gen:DestinationRule:resource:categories=dubbo,networking,shortNames=dr
39+
// +cue-gen:DestinationRule:printerColumn:name=Host,type=string,JSONPath=.spec.host,description="The name of a service from the service registry"
40+
// +cue-gen:DestinationRule:printerColumn:name=Age,type=date,JSONPath=.metadata.creationTimestamp,description="CreationTimestamp is a timestamp
41+
// representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations.
42+
// Clients may not set this value. It is represented in RFC3339 form and is in UTC.
43+
// Populated by the system. Read-only. Null for lists. For more information, see [Kubernetes API Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata)"
44+
// +cue-gen:DestinationRule:preserveUnknownFields:false
45+
// -->
3146
//
3247
// <!-- go code generation tags
3348
// +kubetype-gen

api/networking/v1alpha3/virtual_service.pb.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/networking/v1alpha3/virtual_service.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ import "google/protobuf/wrappers.proto";
2424

2525
option go_package = "/api/networking/v1alpha3";
2626

27+
// <!-- crd generation tags
28+
// +cue-gen:VirtualService:groupName:networking.dubbo.apache.org
29+
// +cue-gen:VirtualService:versions:v1alpha3
30+
// +cue-gen:VirtualService:annotations:helm.sh/resource-policy=keep
31+
// +cue-gen:VirtualService:labels:app=dubbo-planet,chart=dubbo,heritage=Tiller,release=dubbo
32+
// +cue-gen:VirtualService:subresource:status
33+
// +cue-gen:VirtualService:scope:Namespaced
34+
// +cue-gen:VirtualService:resource:categories=dubbo,networking,shortNames=vs
35+
// +cue-gen:VirtualService:printerColumn:name=Hosts,type=string,JSONPath=.spec.hosts,description="The destination hosts to which traffic is being sent"
36+
// +cue-gen:VirtualService:printerColumn:name=Age,type=date,JSONPath=.metadata.creationTimestamp,description="CreationTimestamp is a timestamp
37+
// representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations.
38+
// Clients may not set this value. It is represented in RFC3339 form and is in UTC.
39+
// Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata"
40+
// +cue-gen:VirtualService:preserveUnknownFields:false
41+
// -->
2742
//
2843
// <!-- go code generation tags
2944
// +kubetype-gen

client-go/pkg/apis/networking/v1alpha3/doc.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client-go/pkg/apis/networking/v1alpha3/register.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)