forked from k-orc/openstack-resource-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-codegen.sh
More file actions
executable file
·72 lines (57 loc) · 2.66 KB
/
update-codegen.sh
File metadata and controls
executable file
·72 lines (57 loc) · 2.66 KB
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
#!/usr/bin/env bash
# Copyright 2024 The Kubernetes 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.
set -euo pipefail -x
SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}"))
PROJECT_ROOT=$(realpath "${SCRIPT_ROOT}/..")
GENERATED_PKG="pkg/clients"
# Ensure tools built by kube_codegen go in our own GOBIN rather than something
# shared under GOPATH. This guards against these tools being rebuilt by some
# other concurrent invocation, potentially with a different version.
export GOBIN="${PROJECT_ROOT}/bin"
cd "$PROJECT_ROOT"
# For this to work, the current working directory must be under a Go module which
# lists k8s.io/code-generator
CODEGEN_PKG=$(go list -f '{{ .Dir }}' k8s.io/code-generator)
source "${CODEGEN_PKG}/kube_codegen.sh"
# Deep-copies and what-not are generated by controller-gen, so we don't need to use kube::codegen::gen_helpers
declare -a gen_openapi_args=(
--report-filename "${PROJECT_ROOT}/api_violations.report"
--output-dir "${PROJECT_ROOT}/cmd/models-schema"
--output-pkg main
--boilerplate "${SCRIPT_ROOT}/boilerplate.go.txt"
# We need to include all referenced types in our generated openapi schema
# or applyconfiguration-gen won't be able to use it. Helpfully it will
# generate an error including the missing type.
--extra-pkgs k8s.io/api/core/v1
)
# It is an error to make a change which updates the api violations. When doing
# this intentionally, for example when fixing violations, run with
# UPDATE_API_KNOWN_VIOLATIONS=true to update the api violations report.
if [ ! -z "${UPDATE_API_KNOWN_VIOLATIONS:-}" ]; then
gen_openapi_args+=(--update-report)
fi
kube::codegen::gen_openapi "${gen_openapi_args[@]}" "${PROJECT_ROOT}/api"
openapi="${PROJECT_ROOT}/openapi.json"
go run "${PROJECT_ROOT}/cmd/models-schema" | jq > "$openapi"
kube::codegen::gen_client \
--with-applyconfig \
--with-watch \
--applyconfig-openapi-schema "$openapi" \
--output-dir "${PROJECT_ROOT}/${GENERATED_PKG}" \
--output-pkg github.com/k-orc/openstack-resource-controller/v2/${GENERATED_PKG} \
--versioned-name clientset \
--boilerplate "${SCRIPT_ROOT}/boilerplate.go.txt" \
--one-input-api "api" \
"${PROJECT_ROOT}"