1# -*- fill-column: 102 -*-
2
3# This file deals with creating files that get checked in to Git. This is all grouped together in to
4# one file, rather than being closer to the "subject matter" because this is a heinous thing. Output
5# files should not get checked in to Git -- every entry added to to this file is an affront to all
6# that is good and proper. As an exception, some of the Envoy-related stuff is allowed to live in
7# envoy.mk, because that's a whole other bag of gross.
8
9#
10# The main `make generate` entrypoints and listings
11
12# - Let $(generate/files) be a listing of all files or directories that `make generate` will create.
13#
14# - Let $(generate-fast/files) be the subset of $(generate/files) that can be generated "quickly". A
15# file may NOT be considered fast if it uses the builder container, if it uses the network, or if it
16# needs to access the filesystem to evaluate the list of files (as the lines using `$(shell find
17# ...)` do).
18#
19# - Let $(generate/precious) be the subset of $(generate/files) that should not be deleted prior to
20# re-generation.
21
22# Initialize
23generate-fast/files =
24generate/files = $(generate-fast/files)
25generate/precious =
26# Whole directories with rules for each individual file in it
27generate/files += $(patsubst $(OSS_HOME)/api/%.proto, $(OSS_HOME)/pkg/api/%.pb.go , $(shell find $(OSS_HOME)/api/kat/ -name '*.proto')) $(OSS_HOME)/pkg/api/kat/
28generate/files += $(patsubst $(OSS_HOME)/api/%.proto, $(OSS_HOME)/pkg/api/%_grpc.pb.go , $(shell find $(OSS_HOME)/api/kat/ -name '*.proto'))
29generate/files += $(patsubst $(OSS_HOME)/api/%.proto, $(OSS_HOME)/pkg/api/%.pb.go , $(shell find $(OSS_HOME)/api/agent/ -name '*.proto')) $(OSS_HOME)/pkg/api/agent/
30generate/files += $(patsubst $(OSS_HOME)/api/%.proto, $(OSS_HOME)/pkg/api/%_grpc.pb.go , $(shell find $(OSS_HOME)/api/agent/ -name '*.proto'))
31# Whole directories with one rule for the whole directory
32generate/files += $(OSS_HOME)/api/envoy/ # recipe in _cxx/envoy.mk
33generate/files += $(OSS_HOME)/pkg/api/envoy/ # recipe in _cxx/envoy.mk
34generate/files += $(OSS_HOME)/pkg/envoy-control-plane/ # recipe in _cxx/envoy.mk
35# Individual files: Misc
36generate/files += $(OSS_HOME)/DEPENDENCIES.md
37generate/files += $(OSS_HOME)/DEPENDENCY_LICENSES.md
38generate-fast/files += $(OSS_HOME)/CHANGELOG.md
39generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion.go
40generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion-spoke.go
41generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion.go
42generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion-spoke.go
43generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/v3alpha1/zz_generated.conversion-hub.go
44# Individual files: YAML
45generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-crds.yaml.in
46generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-emissaryns.yaml.in
47generate-fast/files += $(OSS_HOME)/manifests/emissary/emissary-defaultns.yaml.in
48generate-fast/files += $(OSS_HOME)/pkg/api/getambassador.io/crds.yaml
49generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/ambassador.yaml
50generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/crds.yaml
51generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/rbac_cluster_scope.yaml
52generate-fast/files += $(OSS_HOME)/python/tests/integration/manifests/rbac_namespace_scope.yaml
53# Individual files: Test TLS Certificates
54generate-fast/files += $(OSS_HOME)/docker/test-auth/authsvc.crt
55generate-fast/files += $(OSS_HOME)/docker/test-auth/authsvc.key
56generate-fast/files += $(OSS_HOME)/docker/test-shadow/shadowsvc.crt
57generate-fast/files += $(OSS_HOME)/docker/test-shadow/shadowsvc.key
58generate-fast/files += $(OSS_HOME)/python/tests/selfsigned.py
59
60generate: ## Update generated sources that get committed to Git
61generate:
62 $(MAKE) generate-clean
63# This (generating specific targets early, then having a separate `_generate`) is a hack. Because the
64# full value of $(generate/files) is based on the listing of files in $(OSS_HOME)/api/, we need to
65# make sure that those directories are fully populated before we evaluate the full $(generate/files).
66 $(MAKE) $(OSS_HOME)/api/envoy
67 $(MAKE) _generate
68_generate:
69 @echo '$(MAKE) $$(generate/files)'; $(MAKE) $(patsubst %/,%,$(generate/files))
70.PHONY: generate _generate
71
72generate-clean: ## Delete generated sources that get committed to Git
73 rm -rf $(filter-out $(generate/precious),$(generate/files))
74 find $(OSS_HOME)/pkg/api/getambassador.io -name 'zz_generated.*.go' -print -delete # generated as a side-effect of other files
75.PHONY: generate-clean
76
77generate-fast: ## Update the subset of generated-sources-that-get-committed-to-Git that can be updated quickly
78generate-fast:
79 $(MAKE) generate-fast-clean
80 $(MAKE) $(patsubst %/,%,$(generate-fast/files))
81.PHONY: generate-fast
82
83generate-fast-clean: ## Delete the subset of generated-sources-that-get-committed-to-Git that can be updated quickly
84 rm -rf $(filter-out $(generate/precious),$(generate-fast/files))
85 find $(OSS_HOME)/pkg/api/getambassador.io -name 'zz_generated.*.go' -print -delete # generated as a side-effect of other files
86.PHONY: generate-fast-clean
87
88#
89# Helper Make functions and variables
90
91# Usage: $(call joinlist,SEPARATOR,LIST)
92# Example: $(call joinlist,/,foo bar baz) => foo/bar/baz
93joinlist=$(if $(word 2,$2),$(firstword $2)$1$(call joinlist,$1,$(wordlist 2,$(words $2),$2)),$2)
94
95comma=,
96
97gomoddir = $(shell cd $(OSS_HOME); go list -mod=readonly $1/... >/dev/null 2>/dev/null; go list -mod=readonly -m -f='{{.Dir}}' $1)
98
99#
100# `make generate` certificate generation
101
102$(OSS_HOME)/docker/test-auth/authsvc.crt: $(tools/testcert-gen)
103 $(tools/testcert-gen) --out-cert=$@ --out-key=/dev/null --hosts=authsvc.datawire.io
104$(OSS_HOME)/docker/test-auth/authsvc.key: $(tools/testcert-gen)
105 $(tools/testcert-gen) --out-cert=/dev/null --out-key=$@ --hosts=authsvc.datawire.io
106
107$(OSS_HOME)/docker/test-shadow/shadowsvc.crt: $(tools/testcert-gen)
108 $(tools/testcert-gen) --out-cert=$@ --out-key=/dev/null --hosts=demosvc.datawire.io
109$(OSS_HOME)/docker/test-shadow/shadowsvc.key: $(tools/testcert-gen)
110 $(tools/testcert-gen) --out-cert=/dev/null --out-key=$@ --hosts=demosvc.datawire.io
111
112$(OSS_HOME)/python/tests/selfsigned.py: %: %.gen $(tools/testcert-gen)
113 $@.gen $(tools/testcert-gen) >$@
114
115#
116# `make generate` protobuf rules
117
118# proto_path is a list of where to look for .proto files.
119proto_path += $(OSS_HOME)/api # input files must be within the path
120
121# The "M{FOO}={BAR}" options map from .proto files to Go package names.
122proto_options/go ?=
123#proto_options/go += Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration
124
125proto_options/go-grpc ?=
126
127$(OSS_HOME)/pkg/api/%.pb.go: $(OSS_HOME)/api/%.proto $(tools/protoc) $(tools/protoc-gen-go)
128 $(tools/protoc) \
129 $(addprefix --proto_path=,$(proto_path)) \
130 --plugin=$(tools/protoc-gen-go) --go_out=$(OSS_HOME)/pkg/api $(addprefix --go_opt=,$(proto_options/go)) \
131 $<
132$(OSS_HOME)/pkg/api/%_grpc.pb.go: $(OSS_HOME)/api/%.proto $(tools/protoc) $(tools/protoc-gen-go-grpc)
133 $(tools/protoc) \
134 $(addprefix --proto_path=,$(proto_path)) \
135 --plugin=$(tools/protoc-gen-go-grpc) --go-grpc_out=$(OSS_HOME)/pkg/api $(addprefix --go-grpc_opt=,$(proto_options/go-grpc)) \
136 $<
137
138clean: _generate_clean
139_generate_clean:
140 rm -rf $(OSS_HOME)/_generate.tmp
141.PHONY: _generate_clean
142
143#
144# `make generate` rules to update generated YAML files (and `zz_generated.*.go` Go files)
145
146# Use `controller-gen` to generate Go & YAML
147#
148# - Enable a generator by setting the
149# `controller-gen/options/GENERATOR_NAME` variable (even to an empty
150# value).
151# - Setting `controller-gen/output/GENERATOR_NAME` for an enabled
152# generator is optional; the default output for each enabled
153# generator is `dir=config/GENERATOR_NAME`.
154# - It is invalid to set `controller-gen/output/GENERATOR_NAME` for a
155# generator that is not enabled.
156#
157#controller-gen/options/webhook +=
158#controller-gen/options/schemapatch += manifests=foo
159#controller-gen/options/rbac += roleName=ambassador
160controller-gen/options/object += headerFile=build-aux/copyright-boilerplate.go.txt
161controller-gen/options/crd += trivialVersions=false # Requires Kubernetes 1.13+
162controller-gen/options/crd += crdVersions=v1 # Requires Kubernetes 1.16+
163controller-gen/output/crd = dir=$@
164$(OSS_HOME)/_generate.tmp/crds: $(tools/controller-gen) build-aux/copyright-boilerplate.go.txt FORCE
165 @printf ' $(CYN)Running controller-gen$(END)\n'
166 rm -rf $@
167 mkdir -p $@
168 cd $(OSS_HOME) && $(tools/controller-gen) \
169 $(foreach varname,$(sort $(filter controller-gen/options/%,$(.VARIABLES))), $(patsubst controller-gen/options/%,%,$(varname))$(if $(strip $($(varname))),:$(call joinlist,$(comma),$($(varname)))) ) \
170 $(foreach varname,$(sort $(filter controller-gen/output/%,$(.VARIABLES))), $(call joinlist,:,output $(patsubst controller-gen/output/%,%,$(varname)) $($(varname))) ) \
171 $(foreach p,$(wildcard ./pkg/api/getambassador.io/v*/),paths=$p...)
172
173$(OSS_HOME)/%/zz_generated.conversion.go: $(tools/conversion-gen) build-aux/copyright-boilerplate.go.txt FORCE
174 rm -f $@ $(@D)/*.scaffold.go
175 GOPATH= GOFLAGS=-mod=mod $(tools/conversion-gen) \
176 --skip-unsafe \
177 --go-header-file=build-aux/copyright-boilerplate.go.txt \
178 --input-dirs=./$* \
179 --output-file-base=zz_generated.conversion
180# Because v1 just aliases v2, conversion-gen will need to be able to see the v2 conversion functions
181# when generating code for v1.
182$(OSS_HOME)/pkg/api/getambassador.io/v1/zz_generated.conversion.go: $(OSS_HOME)/pkg/api/getambassador.io/v2/zz_generated.conversion.go
183
184$(OSS_HOME)/%/handwritten.conversion.scaffold.go: $(OSS_HOME)/%/zz_generated.conversion.go build-aux/conversion-scaffold.go.awk
185 gawk -v pkgname=$(notdir $*) -f build-aux/conversion-scaffold.go.awk <$< | gofmt >$@
186
187$(OSS_HOME)/%/zz_generated.conversion-hub.go: build-aux/conversion-hub.go.awk FORCE
188 rm -f $@
189 gawk -v pkgname=$(notdir $*) -f build-aux/conversion-hub.go.awk $(sort $(wildcard $(@D)/*.go)) | gofmt >$@
190
191$(OSS_HOME)/%/zz_generated.conversion-spoke.go: build-aux/conversion-spoke.go.awk FORCE
192 rm -f $@
193 gawk -v pkgname=$(notdir $*) -f build-aux/conversion-spoke.go.awk $(sort $(wildcard $(@D)/*.go)) | gofmt >$@
194
195$(OSS_HOME)/manifests/emissary/emissary-crds.yaml.in: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
196 $(tools/fix-crds) --target=apiserver-kubectl $(sort $(wildcard $</*.yaml)) >$@
197
198$(OSS_HOME)/python/tests/integration/manifests/crds.yaml: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
199 $(tools/fix-crds) --target=apiserver-kat $(sort $(wildcard $</*.yaml)) >$@
200
201$(OSS_HOME)/pkg/api/getambassador.io/crds.yaml: $(OSS_HOME)/_generate.tmp/crds $(tools/fix-crds)
202 $(tools/fix-crds) --target=internal-validator $(sort $(wildcard $</*.yaml)) >$@
203
204# Names for all the helm-expanded.yaml files (and thence output.yaml and *.yaml.in files)
205helm.name.emissary-emissaryns = emissary-ingress
206helm.name.emissary-defaultns = emissary-ingress
207helm.namespace.emissary-emissaryns = emissary
208helm.namespace.emissary-defaultns = default
209helm.name.emissary-emissaryns-agent = emissary-ingress
210helm.namespace.emissary-emissaryns-agent = emissary
211helm.name.emissary-defaultns-agent = emissary-ingress
212helm.namespace.emissary-defaultns-agent = default
213helm.name.emissary-emissaryns-migration = emissary-ingress
214helm.namespace.emissary-emissaryns-migration = emissary
215helm.name.emissary-defaultns-migration = emissary-ingress
216helm.namespace.emissary-defaultns-migration = default
217
218# IF YOU'RE LOOKING FOR *.yaml: recipes, look in main.mk.
219
220$(OSS_HOME)/k8s-config/%/helm-expanded.yaml: \
221 $(OSS_HOME)/k8s-config/%/values.yaml \
222 $(boguschart_dir)
223 helm template --namespace=$(helm.namespace.$*) --values=$(@D)/values.yaml $(or $(helm.name.$*),$*) $(boguschart_dir) >$@
224$(OSS_HOME)/k8s-config/%/output.yaml: \
225 $(OSS_HOME)/k8s-config/%/helm-expanded.yaml \
226 $(OSS_HOME)/k8s-config/%/require.yaml \
227 $(tools/filter-yaml)
228 $(tools/filter-yaml) $(filter %/helm-expanded.yaml,$^) $(filter %/require.yaml,$^) >$@
229k8s-config.clean:
230 rm -f k8s-config/*/helm-expanded.yaml k8s-config/*/output.yaml
231clean: k8s-config.clean
232
233$(OSS_HOME)/manifests/emissary/%.yaml.in: $(OSS_HOME)/k8s-config/%/output.yaml
234 cp $< $@
235
236$(OSS_HOME)/python/tests/integration/manifests/%.yaml: $(OSS_HOME)/k8s-config/kat-%/output.yaml
237 sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
238
239$(OSS_HOME)/python/tests/integration/manifests/rbac_cluster_scope.yaml: $(OSS_HOME)/k8s-config/kat-rbac-multinamespace/output.yaml
240 sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
241
242$(OSS_HOME)/python/tests/integration/manifests/rbac_namespace_scope.yaml: $(OSS_HOME)/k8s-config/kat-rbac-singlenamespace/output.yaml
243 sed -e 's/«/{/g' -e 's/»/}/g' -e 's/♯.*//g' -e 's/- ←//g' <$< >$@
244
245#
246# Generate report on dependencies
247
248$(OSS_HOME)/DEPENDENCIES.md: $(tools/go-mkopensource) $(tools/py-mkopensource) $(OSS_HOME)/build-aux/go-version.txt $(OSS_HOME)/build-aux/pip-show.txt
249 $(MAKE) $(OSS_HOME)/build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz
250 set -e; { \
251 cd $(OSS_HOME); \
252 $(tools/go-mkopensource) --output-format=txt --package=mod --application-type=external --gotar=build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz; \
253 echo; \
254 { sed 's/^---$$//' $(OSS_HOME)/build-aux/pip-show.txt; echo; } | $(tools/py-mkopensource); \
255 } > $@
256
257$(OSS_HOME)/DEPENDENCY_LICENSES.md: $(tools/go-mkopensource) $(tools/py-mkopensource) $(OSS_HOME)/build-aux/go-version.txt $(OSS_HOME)/build-aux/pip-show.txt
258 $(MAKE) $(OSS_HOME)/build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz
259 echo -e "Emissary-ingress incorporates Free and Open Source software under the following licenses:\n" > $@
260 set -e; { \
261 cd $(OSS_HOME); \
262 $(tools/go-mkopensource) --output-format=txt --package=mod --output-type=json --application-type=external --gotar=build-aux/go$$(cat $(OSS_HOME)/build-aux/go-version.txt).src.tar.gz | jq -r '.licenseInfo | to_entries | .[] | "* [" + .key + "](" + .value + ")"' ; \
263 { sed 's/^---$$//' $(OSS_HOME)/build-aux/pip-show.txt; echo; } | $(tools/py-mkopensource) --output-type=json | jq -r '.licenseInfo | to_entries | .[] | "* [" + .key + "](" + .value + ")"'; \
264 } | sort | uniq | sed -e 's/\[\([^]]*\)]()/\1/' >> $@
265
266#
267# Misc. other `make generate` rules
268
269$(OSS_HOME)/CHANGELOG.md: $(OSS_HOME)/docs/CHANGELOG.tpl $(OSS_HOME)/docs/releaseNotes.yml
270 docker run --rm \
271 -v $(OSS_HOME)/docs/CHANGELOG.tpl:/tmp/CHANGELOG.tpl \
272 -v $(OSS_HOME)/docs/releaseNotes.yml:/tmp/releaseNotes.yml \
273 hairyhenderson/gomplate --verbose --file /tmp/CHANGELOG.tpl --datasource relnotes=/tmp/releaseNotes.yml > CHANGELOG.md
View as plain text