Skip to content

Commit

Permalink
Clean up code gen scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
efiacor committed Mar 25, 2024
1 parent 8d161f6 commit a9006e0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 43 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
k8s.io/component-base v0.29.2
k8s.io/klog/v2 v2.120.1
k8s.io/kube-aggregator v0.29.2
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
k8s.io/kubectl v0.29.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/cli-utils v0.35.0
Expand Down Expand Up @@ -189,6 +188,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/kms v0.29.2 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
12 changes: 0 additions & 12 deletions scripts/_env

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/_functions

This file was deleted.

13 changes: 10 additions & 3 deletions scripts/_trap
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ function goodbye () {
local CODE=$1
cd "$TRAP_DIR"
if [ "$CODE" == 0 ]; then
m "$(realpath --relative-to="$ROOT" "$0") succeeded! $DURATION" "$GREEN"
echo "$(realpath --relative-to="$ROOT" "$0") succeeded! $DURATION"
elif [ "$CODE" == abort ]; then
m "Aborted $(realpath --relative-to="$ROOT" "$0")! $DURATION" "$RED"
echo "Aborted $(realpath --relative-to="$ROOT" "$0")! $DURATION"
else
m "Oh no! $(realpath --relative-to="$ROOT" "$0") failed! $DURATION" "$RED"
echo "Oh no! $(realpath --relative-to="$ROOT" "$0") failed! $DURATION"
fi
}


function copy_function () {
local ORIG_FUNC=$(declare -f $1)
local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
eval "$NEWNAME_FUNC"
}

function trap_EXIT () {
local ERR=$?
goodbye "$ERR"
Expand Down
14 changes: 8 additions & 6 deletions scripts/generate-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
set -e

HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
. "$HERE/_env"
. "$HERE/_trap"

ROOT=$(readlink --canonicalize "$HERE/..")

ORG=github.com/nephio-project
REPO=$ORG/porch
API_PKG=$REPO/api
Expand All @@ -14,6 +15,7 @@ CLIENT_PKG=$API_PKG/generated
BOILERPLATE=$HERE/boilerplate.go.txt
OPENAPI_REPORT=$ROOT/gen_openapi.report

KUBERNETES_VERSION=0.29.2
go get -d "k8s.io/code-generator@v$KUBERNETES_VERSION"
CODE_GENERATOR=$(go list -f '{{.Dir}}' -m "k8s.io/code-generator@v$KUBERNETES_VERSION")
# . "${CODE_GENERATOR}/kube_codegen.sh"
Expand All @@ -23,19 +25,19 @@ CODE_GENERATOR=$(go list -f '{{.Dir}}' -m "k8s.io/code-generator@v$KUBERNETES_VE

WORK=$(mktemp --directory)

m "work directory: $WORK"
echo "work directory: $WORK"

copy_function goodbye old_goodbye
function goodbye () {
m "deleting work directory: $WORK"
echo "deleting work directory: $WORK"
rm --recursive "$WORK"
old_goodbye $1
}

mkdir --parents "$WORK/$ORG"
ln --symbolic "$ROOT" "$WORK/$REPO"

m 'gen_helpers...'
echo 'gen_helpers...'

kube::codegen::gen_helpers \
--output-base "$WORK" \
Expand All @@ -45,7 +47,7 @@ kube::codegen::gen_helpers \
--extra-peer-dir "k8s.io/apimachinery/pkg/runtime" \
--extra-peer-dir "k8s.io/apimachinery/pkg/version"

m 'gen_openapi...'
echo 'gen_openapi...'

rm --recursive --force "$CLIENT_PKG/openapi"

Expand All @@ -58,7 +60,7 @@ kube::codegen::gen_openapi \
--report-filename "$OPENAPI_REPORT" \
--update-report

m 'gen_client...'
echo 'gen_client...'

#rm --recursive --force "$ROOT/api/kubernetes-client"

Expand Down

0 comments on commit a9006e0

Please sign in to comment.