-
Notifications
You must be signed in to change notification settings - Fork 115
/
Makefile.core.mk
137 lines (117 loc) · 5.49 KB
/
Makefile.core.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
default: all
all: clean gen build verify
gen: generate-k8s-client tidy-go mirror-licenses
gen-check: clean gen check-clean-repo
build: build-k8s-client
verify: verify-k8s-client
clean: clean-k8s-client
########################
# kubernetes code generators
########################
applyconfiguration_gen = applyconfiguration-gen
kubetype_gen = kubetype-gen
deepcopy_gen = deepcopy-gen
client_gen = client-gen
lister_gen = lister-gen
informer_gen = informer-gen
empty:=
space := $(empty) $(empty)
comma := ,
# source packages to scan for kubetype-gen tags
kube_istio_source_packages = $(subst $(space),$(empty), \
istio.io/api/extensions/v1alpha1, \
istio.io/api/networking/v1alpha3, \
istio.io/api/networking/v1beta1, \
istio.io/api/networking/v1, \
istio.io/api/security/v1beta1, \
istio.io/api/security/v1, \
istio.io/api/telemetry/v1alpha1, \
istio.io/api/telemetry/v1 \
)
# base output package for generated files
kube_base_output_package = istio.io/client-go/pkg
# base output package for kubernetes types, register, etc...
kube_api_base_package = $(kube_base_output_package)/apis
# source packages to scan for kubernetes generator tags, e.g. deepcopy-gen, client-gen, etc.
# these should correspond to the output packages from kubetype-gen
kube_api_packages = $(subst $(space),$(empty), \
$(kube_api_base_package)/extensions/v1alpha1, \
$(kube_api_base_package)/networking/v1alpha3, \
$(kube_api_base_package)/networking/v1beta1, \
$(kube_api_base_package)/networking/v1, \
$(kube_api_base_package)/security/v1beta1, \
$(kube_api_base_package)/security/v1, \
$(kube_api_base_package)/telemetry/v1alpha1, \
$(kube_api_base_package)/telemetry/v1 \
)
# this is needed to properly generate ssa functions
kube_api_applyconfiguration_packages = $(kube_api_packages),k8s.io/apimachinery/pkg/apis/meta/v1
# base output package used by kubernetes client-gen
kube_clientset_package = $(kube_base_output_package)/clientset
# clientset name used by kubernetes client-gen
kube_clientset_name = versioned
# base output package used by kubernetes lister-gen
kube_listers_package = $(kube_base_output_package)/listers
# base output package used by kubernetes informer-gen
kube_informers_package = $(kube_base_output_package)/informers
# base output package used by kubernetes applyconfiguration-gen
kube_applyconfiguration_package = $(kube_base_output_package)/applyconfiguration
# file header text
kube_go_header_text = header.go.txt
ifeq ($(IN_BUILD_CONTAINER),1)
# k8s code generators rely on GOPATH, using $GOPATH/src as the base package
# directory. Using --output-base . does not work, as that ends up generating
# code into ./<package>, e.g. ./istio.io/client-go/pkg/apis/... To work
# around this, we'll just let k8s generate the code where it wants and copy
# back to where it should have been generated.
move_generated=cp -r $(GOPATH)/src/$(kube_base_output_package)/ . && rm -rf $(GOPATH)/src/$(kube_base_output_package)/
else
# nothing special for local builds
move_generated=
endif
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' - '{}' \;
.PHONY: generate-k8s-client
generate-k8s-client:
# generate kube api type wrappers for istio types
@KUBETYPE_GOLANG_PROTOBUF=true $(kubetype_gen) --input-dirs $(kube_istio_source_packages) --output-package $(kube_api_base_package) -h $(kube_go_header_text)
@$(move_generated)
# generate deepcopy for kube api types
@$(deepcopy_gen) --input-dirs $(kube_api_packages) -O zz_generated.deepcopy -h $(kube_go_header_text)
# generate ssa for kube api types
@$(applyconfiguration_gen) --input-dirs $(kube_api_applyconfiguration_packages) --output-package $(kube_applyconfiguration_package) -h $(kube_go_header_text)
# generate clientsets for kube api types
@$(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)
# generate listers for kube api types
@$(lister_gen) --input-dirs $(kube_api_packages) --output-package $(kube_listers_package) -h $(kube_go_header_text)
# generate informers for kube api types
@$(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)
.PHONY: build-k8s-client verify-k8s-client
build-k8s-client:
# building k8s client
@go build ./pkg/...
verify-k8s-client:
# verifying generated client code
@go build ./cmd/...
.PHONY: clean-k8s-client
clean-k8s-client:
# remove generated code
@rm -rf pkg/
lint: lint-all
include common/Makefile.common.mk