Skip to content

Commit

Permalink
fix: make verify-coodegen error
Browse files Browse the repository at this point in the history
Signed-off-by: jiuxia211 <[email protected]>
  • Loading branch information
jiuxia211 committed Jul 23, 2024
1 parent 333cc7e commit e680a09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
6 changes: 3 additions & 3 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ trap "cleanup" EXIT SIGINT
echo ">> Temporary output directory ${TEMP_DIR}"

# Ensure we can execute.
chmod +x ${CODEGEN_PKG}/kube_codegen.sh

PACKAGE_PATH_BASE="github.com/fluent/fluent-operator/v2"

mkdir -p "${TEMP_DIR}/${PACKAGE_PATH_BASE}/apis/fluentbit" \
"${TEMP_DIR}/${PACKAGE_PATH_BASE}/apis/fluentd" \
"${TEMP_DIR}/${PACKAGE_PATH_BASE}/apis/generated"

chmod +x ${CODEGEN_PKG}/kube_codegen.sh

source ${CODEGEN_PKG}/kube_codegen.sh kube::codegen::gen_client \
--output-dir "${TEMP_DIR}" \
--with-watch \
--output-pkg "${PACKAGE_PATH_BASE}/apis/generated" \
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
./apis/generated
./apis

ls -lha $TEMP_DIR

Expand Down
35 changes: 12 additions & 23 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
#!/usr/bin/env bash

# inspired by: https://github.com/weaveworks/flagger/tree/master/hack
# inspired by: https://github.com/weaveworks/flagger/tree/main/hack

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(git rev-parse --show-toplevel)

# Grab code-generator version from go.sum.
CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.sum | awk '{print $2}' | head -1 |cut -b 1-7)
CODEGEN_PKG=$(echo `go env GOPATH`"/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}")

# code-generator does work with go.mod but makes assumptions about
# the project living in `$GOPATH/src`. To work around this and support
# any location; create a temporary directory, use this as an output
# base, and copy everything back once generated.
TEMP_DIR=$(mktemp -d)
DIFFROOT="${SCRIPT_ROOT}/apis"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/apis"

_tmp="${SCRIPT_ROOT}/_tmp"

cleanup() {
echo ">> Removing ${TEMP_DIR}"
rm -rf ${TEMP_DIR}
echo ">> Removing ${_tmp}"
rm -rf ${_tmp}
}
trap "cleanup" EXIT SIGINT

echo ">> Temporary output directory ${TEMP_DIR}"

# Ensure we can execute.
chmod +x ${CODEGEN_PKG}/generate-groups.sh

${CODEGEN_PKG}/generate-groups.sh "client" \
github.com/fluent/fluent-operator/v2/apis/generated github.com/fluent/fluent-operator/v2/apis \
"fluentbit:v1alpha2 fluentd:v1alpha1" \
--output-base "${TEMP_DIR}" \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt
cleanup

TMP_DIFFROOT=${TEMP_DIR}/github.com/fluent/fluent-operator/v2/apis/generated/clientset
DIFFROOT=${SCRIPT_ROOT}/apis/generated/clientset
mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

"${SCRIPT_ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated clientset"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
Expand Down

0 comments on commit e680a09

Please sign in to comment.