mirror of
https://github.com/grafana/grafana.git
synced 2025-07-25 16:33:51 +08:00
K8s: Update codegen to support new packages (#83347)
--------- Co-authored-by: Charandas Batra <charandas.batra@grafana.com>
This commit is contained in:
@ -115,7 +115,6 @@ function grafana::codegen::gen_openapi() {
|
||||
|
||||
local input_pkgs=()
|
||||
while read -r dir; do
|
||||
echo ${dir}
|
||||
pkg="$(cd "${dir}" && GO111MODULE=on go list -find .)"
|
||||
input_pkgs+=("${pkg}")
|
||||
done < <(
|
||||
@ -127,6 +126,8 @@ function grafana::codegen::gen_openapi() {
|
||||
| LC_ALL=C sort -u
|
||||
)
|
||||
|
||||
|
||||
local new_report=""
|
||||
if [ "${#input_pkgs[@]}" != 0 ]; then
|
||||
echo "Generating openapi code for ${#input_pkgs[@]} targets"
|
||||
|
||||
@ -139,7 +140,6 @@ function grafana::codegen::gen_openapi() {
|
||||
inputs+=("--input-dirs" "$arg")
|
||||
done
|
||||
|
||||
local new_report
|
||||
new_report="${root}/${report}.tmp"
|
||||
if [ -n "${update_report}" ]; then
|
||||
new_report="${root}/${report}"
|
||||
@ -157,6 +157,9 @@ function grafana::codegen::gen_openapi() {
|
||||
fi
|
||||
|
||||
touch "${root}/${report}" # in case it doesn't exist yet
|
||||
if [[ -z "${new_report}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
if ! diff -u "${root}/${report}" "${new_report}"; then
|
||||
echo -e "ERROR:"
|
||||
echo -e "\tAPI rule check failed for ${root}/${report}: new reported violations"
|
||||
|
@ -10,7 +10,7 @@ set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo $GOPATH/pkg/mod/k8s.io/code-generator@v0.29.1)}
|
||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo $(go env GOPATH)/pkg/mod/k8s.io/code-generator@v0.29.1)}
|
||||
|
||||
OUTDIR="${HOME}/go/src"
|
||||
OPENAPI_VIOLATION_EXCEPTIONS_FILENAME="zz_generated.openapi_violation_exceptions.list"
|
||||
@ -18,52 +18,70 @@ OPENAPI_VIOLATION_EXCEPTIONS_FILENAME="zz_generated.openapi_violation_exceptions
|
||||
source "${CODEGEN_PKG}/kube_codegen.sh"
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/openapi-codegen.sh"
|
||||
|
||||
selected_pkg="${1-}"
|
||||
|
||||
for api_pkg in $(ls ./pkg/apis); do
|
||||
if [[ "${1-}" != "" && ${api_pkg} != $1 ]]; then
|
||||
continue
|
||||
fi
|
||||
include_common_input_dirs=$([[ ${api_pkg} == "common" ]] && echo "true" || echo "false")
|
||||
for pkg_version in $(ls ./pkg/apis/${api_pkg}); do
|
||||
echo "API: ${api_pkg}/${pkg_version}"
|
||||
echo "-------------------------------------------"
|
||||
grafana::codegen:run() {
|
||||
local generate_root=$1
|
||||
local skipped="true"
|
||||
for api_pkg in $(grafana:codegen:lsdirs ./${generate_root}/apis); do
|
||||
echo "Generating code for ${generate_root}/apis/${api_pkg}..."
|
||||
echo "============================================="
|
||||
if [[ "${selected_pkg}" != "" && ${api_pkg} != $selected_pkg ]]; then
|
||||
continue
|
||||
fi
|
||||
skipped="false"
|
||||
include_common_input_dirs=$([[ ${api_pkg} == "common" ]] && echo "true" || echo "false")
|
||||
|
||||
kube::codegen::gen_helpers \
|
||||
--input-pkg-root github.com/grafana/grafana/pkg/apis/${api_pkg}/${pkg_version} \
|
||||
--input-pkg-root github.com/grafana/grafana/${generate_root}/apis/${api_pkg} \
|
||||
--output-base "${OUTDIR}" \
|
||||
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
|
||||
|
||||
for pkg_version in $(grafana:codegen:lsdirs ./${generate_root}/apis/${api_pkg}); do
|
||||
grafana::codegen::gen_openapi \
|
||||
--input-pkg-single github.com/grafana/grafana/${generate_root}/apis/${api_pkg}/${pkg_version} \
|
||||
--output-base "${OUTDIR}" \
|
||||
--report-filename "${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" \
|
||||
--update-report \
|
||||
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
|
||||
--include-common-input-dirs ${include_common_input_dirs}
|
||||
|
||||
echo "Generating openapi package for ${api_pkg}, version=${pkg_version} ..."
|
||||
violations_file="${OUTDIR}/github.com/grafana/grafana/${generate_root}/apis/${api_pkg}/${pkg_version}/${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}"
|
||||
# delete violation exceptions file, if empty
|
||||
if ! grep -q . "${violations_file}"; then
|
||||
echo "Deleting ${violations_file} since it is empty"
|
||||
rm ${violations_file}
|
||||
fi
|
||||
|
||||
grafana::codegen::gen_openapi \
|
||||
--input-pkg-single github.com/grafana/grafana/pkg/apis/${api_pkg}/${pkg_version} \
|
||||
--output-base "${OUTDIR}" \
|
||||
--report-filename "${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}" \
|
||||
--update-report \
|
||||
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
|
||||
--include-common-input-dirs ${include_common_input_dirs}
|
||||
|
||||
violations_file="${OUTDIR}/github.com/grafana/grafana/pkg/apis/${api_pkg}/${pkg_version}/${OPENAPI_VIOLATION_EXCEPTIONS_FILENAME}"
|
||||
# delete violation exceptions file, if empty
|
||||
if ! grep -q . "${violations_file}"; then
|
||||
echo "Deleting ${violations_file} since it is empty"
|
||||
rm ${violations_file}
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
echo "Generating client code..."
|
||||
echo "---------------------------"
|
||||
if [[ "${skipped}" == "true" ]]; then
|
||||
echo "no apis matching ${selected_pkg}. skipping..."
|
||||
echo
|
||||
return 0
|
||||
fi
|
||||
|
||||
kube::codegen::gen_client \
|
||||
--with-watch \
|
||||
--with-applyconfig \
|
||||
--input-pkg-root github.com/grafana/grafana/pkg/apis \
|
||||
--output-pkg-root github.com/grafana/grafana/pkg/generated \
|
||||
--output-base "${OUTDIR}" \
|
||||
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
|
||||
echo "Generating client code..."
|
||||
echo "-------------------------"
|
||||
|
||||
kube::codegen::gen_client \
|
||||
--with-watch \
|
||||
--with-applyconfig \
|
||||
--input-pkg-root github.com/grafana/grafana/${generate_root}/apis \
|
||||
--output-pkg-root github.com/grafana/grafana/${generate_root}/generated \
|
||||
--output-base "${OUTDIR}" \
|
||||
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
grafana:codegen:lsdirs() {
|
||||
ls -d $1/*/ | xargs basename -a
|
||||
}
|
||||
|
||||
grafana::codegen:run pkg
|
||||
grafana::codegen:run pkg/apimachinery
|
||||
|
||||
echo "done."
|
||||
|
Reference in New Issue
Block a user