forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-codegen.sh
executable file
·65 lines (54 loc) · 2.54 KB
/
update-codegen.sh
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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
SCRIPT_ROOT="$(dirname "${SCRIPT_DIR}")"
GEN_VER=$( awk '/k8s.io\/code-generator/ { print $2 }' "${SCRIPT_ROOT}/go.mod" )
KUBE_OPEN_API_VER=$( awk '/k8s.io\/kube-openapi/ { print $2 }' "${SCRIPT_ROOT}/go.mod" )
CODEGEN_PKG=$(mktemp -d -t "code-generator-${GEN_VER}.XXX")/code-generator
git clone --depth 1 --branch "$GEN_VER" https://github.com/kubernetes/code-generator "$CODEGEN_PKG"
(
cd "$CODEGEN_PKG"
go get k8s.io/kube-openapi/pkg/common@"$KUBE_OPEN_API_VER"
)
# Remove previously generated code
rm -rf "${SCRIPT_ROOT}/controller/gen/client/clientset/*"
rm -rf "${SCRIPT_ROOT}/controller/gen/client/listeners/*"
rm -rf "${SCRIPT_ROOT}/controller/gen/client/informers/*"
crds=(serviceprofile:v1alpha2 server:v1beta1 serverauthorization:v1beta1 link:v1alpha1 policy:v1alpha1 policy:v1beta3 externalworkload:v1beta1)
for crd in "${crds[@]}"
do
crd_path=$(tr : / <<< "$crd")
rm -f "${SCRIPT_ROOT}/controller/gen/apis/${crd_path}/zz_generated.deepcopy.go"
done
# shellcheck disable=SC1091
source "${CODEGEN_PKG}/kube_codegen.sh"
# Create a symlink so that the root of the repo is inside github.com/linkerd/linkerd2.
# This is required because the codegen scripts expect it.
mkdir -p "${SCRIPT_ROOT}/github.com/linkerd"
ln -s "$(realpath "${SCRIPT_ROOT}")" "${SCRIPT_ROOT}/github.com/linkerd/linkerd2"
kube::codegen::gen_helpers \
--boilerplate "${SCRIPT_ROOT}/controller/gen/boilerplate.go.txt" \
github.com/linkerd/linkerd2/controller/gen/apis
if [[ -n "${API_KNOWN_VIOLATIONS_DIR:-}" ]]; then
report_filename="${API_KNOWN_VIOLATIONS_DIR}/codegen_violation_exceptions.list"
if [[ "${UPDATE_API_KNOWN_VIOLATIONS:-}" == "true" ]]; then
update_report="--update-report"
fi
fi
kube::codegen::gen_openapi \
--output-pkg github.com/linkerd/linkerd2/controller/gen \
--output-dir "${SCRIPT_ROOT}/controller/gen/client" \
--report-filename "${report_filename:-"/dev/null"}" \
${update_report:+"${update_report}"} \
--boilerplate "${SCRIPT_ROOT}/controller/gen/boilerplate.go.txt" \
github.com/linkerd/linkerd2/controller/gen/apis
kube::codegen::gen_client \
--with-watch \
--output-pkg github.com/linkerd/linkerd2/controller/gen/client \
--output-dir "${SCRIPT_ROOT}/controller/gen/client" \
--boilerplate "${SCRIPT_ROOT}/controller/gen/boilerplate.go.txt" \
github.com/linkerd/linkerd2/controller/gen/apis
# Once the code has been generated, we can remove the symlink.
rm -rf "${SCRIPT_ROOT}/github.com"