forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
executable file
·79 lines (65 loc) · 3 KB
/
generate.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Based of of gateway-api codegen (https://github.com/kubernetes-sigs/gateway-api/blob/main/hack/update-codegen.sh)
# generate deep copy and clients for our api.
# In this project, clients mostly used as fakes for testing.
set -o errexit
set -o nounset
set -o pipefail
set -x
readonly ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE}")"/.. && pwd)"
readonly OUTPUT_PKG=github.com/kgateway-dev/kgateway/v2/pkg/client
readonly APIS_PKG=github.com/kgateway-dev/kgateway/v2
readonly CLIENTSET_NAME=versioned
readonly CLIENTSET_PKG_NAME=clientset
readonly VERSIONS=( v1alpha1 )
# well known dirs for codegen, should be cleaned before fresh gen
readonly OPENAPI_GEN_DIR=pkg/generated/openapi
readonly APPLY_CFG_DIR=api/applyconfiguration
readonly CLIENT_GEN_DIR=pkg/client
readonly CRD_DIR=install/helm/kgateway-crds/templates
# manifests dir only used for outputting rbac artifacts and existing file will be overwritten so no need to clean
readonly MANIFESTS_DIR=install/helm/kgateway/templates
echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME} for versions:" "${VERSIONS[@]}"
API_INPUT_DIRS_SPACE=""
API_INPUT_DIRS_COMMA=""
for VERSION in "${VERSIONS[@]}"
do
API_INPUT_DIRS_SPACE+="${APIS_PKG}/api/${VERSION} "
API_INPUT_DIRS_COMMA+="${APIS_PKG}/api/${VERSION},"
done
API_INPUT_DIRS_SPACE="${API_INPUT_DIRS_SPACE%,}" # drop trailing space
API_INPUT_DIRS_COMMA="${API_INPUT_DIRS_COMMA%,}" # drop trailing comma
go tool register-gen --output-file zz_generated.register.go ${API_INPUT_DIRS_SPACE}
go tool controller-gen crd:maxDescLen=0 object rbac:roleName=kgateway paths="${APIS_PKG}/api/${VERSION}" \
output:crd:artifacts:config=${ROOT_DIR}/${CRD_DIR} output:rbac:artifacts:config=${ROOT_DIR}/${MANIFESTS_DIR}
# throw away
new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")"
go tool openapi-gen \
--output-file zz_generated.openapi.go \
--report-filename "${new_report}" \
--output-dir "${ROOT_DIR}/${OPENAPI_GEN_DIR}" \
--output-pkg "github.com/kgateway-dev/kgateway/v2/pkg/generated/openapi" \
$API_INPUT_DIRS_SPACE \
sigs.k8s.io/gateway-api/apis/v1 \
k8s.io/apimachinery/pkg/apis/meta/v1 \
k8s.io/api/core/v1 \
k8s.io/apimachinery/pkg/runtime \
k8s.io/apimachinery/pkg/util/intstr \
k8s.io/apimachinery/pkg/api/resource \
k8s.io/apimachinery/pkg/version
go tool applyconfiguration-gen \
--openapi-schema <(go run ${ROOT_DIR}/cmd/modelschema) \
--output-dir "${ROOT_DIR}/${APPLY_CFG_DIR}" \
--output-pkg "github.com/kgateway-dev/kgateway/v2/api/applyconfiguration" \
${API_INPUT_DIRS_SPACE}
go tool client-gen \
--clientset-name "versioned" \
--input-base "${APIS_PKG}" \
--input "${API_INPUT_DIRS_COMMA//${APIS_PKG}/}" \
--output-dir "${ROOT_DIR}/${CLIENT_GEN_DIR}/${CLIENTSET_PKG_NAME}" \
--output-pkg "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \
--apply-configuration-package "${APIS_PKG}/api/applyconfiguration"
go generate ${ROOT_DIR}/internal/envoyinit/hack/...
# fix imports of gen code
go tool goimports -w ${ROOT_DIR}/${CLIENT_GEN_DIR}
go tool goimports -w ${ROOT_DIR}/api