-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.codegen.template
68 lines (57 loc) · 3.28 KB
/
Makefile.codegen.template
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
CLIENTSET_GENERATOR_VERSION := kubernetes-1.15.12
GEN_APIDOCS_VERSION := v0.0.0-20190912061656-a61bc210ee54
OPENAPI_GEN_VERSION := 36ebc4887cdc
CODEGEN_VERSION := v0.0.1
INPUT_PKG=pkg/api
OUTPUT_PKG=pkg/api
GROUP_WITH_VERSIONS=crds.jenkinsx.io:v1alpha1
GO_PKG=github.com/jenkins-x/project
ISOLATED_GOPATH := ${HOME}/.jx/codegen
CODE_GEN_BIN_NAME := ${ISOLATED_GOPATH}/bin/codegen
# Generate go code using generate directives in files and kubernetes code generation
# Anything generated by this target should be checked in
generate: generate-clean install-codegen generate-openapi generate-client ## Generate the Go code (crds, mocks, openapi, client)
@$(MAKE) fmt
@echo "Generation complete"
codegen-install:
GOPATH=${ISOLATED_GOPATH} rm -f ${GOPATH}/bin/codegen
GOPATH=${ISOLATED_GOPATH} $(GO) get github.com/jenkins-x/jx-codegen/cmd/codegen@$(CODEGEN_VERSION)
generate-codegen: codegen-clean codegen-install codegen-clientset codegen-openapi
@$(MAKE) codegen-fmt
@echo "Generation complete"
generate-client: codegen-clientset codegen-fmt ## Generate the client
codegen-clientset: codegen-install ## Generate the k8s types and clients
@echo "Generating Kubernetes Clients for ${INPUT_PKG} in ${OUTPUT_PKG} for ${GROUP_WITH_VERSIONS}"
$(CODE_GEN_BIN_NAME) --generator-version $(CLIENTSET_GENERATOR_VERSION) clientset --output-package=${OUTPUT_PKG} --input-package=${INPUT_PKG} --group-with-version=${GROUP_WITH_VERSIONS}
# Generated docs are not checked in
generate-docs: codegen-install ## Generate the docs
@echo "Generating HTML docs for Kubernetes Clients"
$(CODE_GEN_BIN_NAME) --generator-version $(GEN_APIDOCS_VERSION) docs
generate-openapi: codegen-openapi codegen-fmt
codegen-openapi:
@echo "Generating OpenAPI structs for Kubernetes Clients"
$(CODE_GEN_BIN_NAME) openapi --generator-version $(OPENAPI_GEN_VERSION) --output-package=${OUTPUT_PKG} --input-package=${GO_PKG}/${INPUT_PKG} --group-with-version=${GROUP_WITH_VERSIONS} --open-api-dependency "k8s.io/apimachinery:pkg/apis:meta:v1" --open-api-dependency "k8s.io/apimachinery:pkg/api:resource:" --open-api-dependency "k8s.io/apimachinery:pkg/util:intstr:" --open-api-dependency "k8s.io/api::batch:v1" --open-api-dependency "k8s.io/api::core:v1" --open-api-dependency "k8s.io/api::rbac:v1" --open-api-dependency "k8s.io/apiextensions-apiserver:pkg/apis:apiextensions:v1beta1"
stash:
# Making sure repo has no outstanding changes
git stash
# Verifies that generated code is in sync with implementation
verify-generation-complete: stash generate ## Verify the generated code is up to date
# exclude pkg/client/openapi/k8s_io_apimachinery_intstr_unversioned/openapi_generated.go since it can differs in amount of empty lines in header
$(eval CHANGED = $(shell git ls-files --modified -- . ':(exclude)pkg/client/openapi/k8s_io_apimachinery_intstr_unversioned/openapi_generated.go'))
@if [ "$(CHANGED)" == "" ]; \
then \
echo "All generated files up to date"; \
else \
echo "Code generation is out of date"; \
echo "$(CHANGED)"; \
git diff; \
exit 1; \
fi
codegen-fmt: ## Format the code
$(eval FORMATTED = $(shell $(GO) fmt ./...))
@if [ "$(FORMATTED)" == "" ]; \
then \
echo "All Go files properly formatted"; \
else \
echo "Fixed formatting for: $(FORMATTED)"; \
fi