forked from ray-project/kuberay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codegen scripts and make required api changes (ray-project#96)
* Update go modules to include code-generator * Add scripts to generate clients * Clean up code-generator dependency Signed-off-by: Jiaxin Shan <[email protected]> * Update codegen scripts and make required api changes 1. Add update-codegen.sh and verify-codegen.sh 2. Add required changes to register.go and doc.go and //+genclient tag in raycluster_types.go Signed-off-by: Jiaxin Shan <[email protected]> Co-authored-by: Jiaxin Shan <[email protected]>
- Loading branch information
Showing
8 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// +groupName=ray.io | ||
package v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// SchemeGroupVersion is group version used to register these objects. | ||
var SchemeGroupVersion = GroupVersion | ||
|
||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
package tools | ||
|
||
// This package imports things required by this repository, to force `go mod` to see them as dependencies | ||
import ( | ||
_ "k8s.io/code-generator" | ||
_ "k8s.io/code-generator/cmd/client-gen" | ||
_ "k8s.io/code-generator/cmd/deepcopy-gen" | ||
_ "k8s.io/code-generator/cmd/defaulter-gen" | ||
_ "k8s.io/code-generator/cmd/informer-gen" | ||
_ "k8s.io/code-generator/cmd/lister-gen" | ||
_ "k8s.io/code-generator/cmd/openapi-gen" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
# This shell is used to auto generate some useful tools for k8s, such as clientset, lister, informer and so on. | ||
# We don't use this tool to generate deepcopy because kubebuilder (controller-tools) has coverred that part. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||
ROOT_PKG=github.com/ray-project/kuberay/ray-operator | ||
|
||
# Grab code-generator version from go.sum | ||
CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.sum | awk '{print $2}' | sed 's/\/go.mod//g' | head -1) | ||
CODEGEN_PKG=$(echo `go env GOPATH`"/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}") | ||
|
||
if [[ ! -d ${CODEGEN_PKG} ]]; then | ||
echo "${CODEGEN_PKG} is missing. Running 'go mod download'." | ||
go mod download | ||
fi | ||
|
||
echo ">> Using ${CODEGEN_PKG}" | ||
|
||
# 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) | ||
cleanup() { | ||
echo ">> Removing ${TEMP_DIR}" | ||
# rm -rf ${TEMP_DIR} | ||
} | ||
trap "cleanup" EXIT SIGINT | ||
|
||
echo ">> Temporary output directory ${TEMP_DIR}" | ||
|
||
# Ensure we can execute. | ||
chmod +x ${CODEGEN_PKG}/generate-groups.sh | ||
|
||
# generate the code with: | ||
# --output-base because this script should also be able to run inside the vendor dir of | ||
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir | ||
# instead of the $GOPATH directly. For normal projects this can be dropped. | ||
# | ||
cd ${SCRIPT_ROOT} | ||
${CODEGEN_PKG}/generate-groups.sh "client,informer,lister" \ | ||
github.com/ray-project/kuberay/ray-operator/pkg/client github.com/ray-project/kuberay/ray-operator/api \ | ||
raycluster:v1alpha1 \ | ||
--output-base "${TEMP_DIR}" \ | ||
--go-header-file hack/boilerplate.go.txt | ||
|
||
|
||
# Copy everything back. | ||
cp -a "${TEMP_DIR}/${ROOT_PKG}/." "${SCRIPT_ROOT}/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||
|
||
DIFFROOT="${SCRIPT_ROOT}/pkg" | ||
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg" | ||
_tmp="${SCRIPT_ROOT}/_tmp" | ||
|
||
cleanup() { | ||
rm -rf "${_tmp}" | ||
} | ||
trap "cleanup" EXIT SIGINT | ||
|
||
cleanup | ||
|
||
mkdir -p "${TMP_DIFFROOT}" | ||
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" | ||
|
||
"${SCRIPT_ROOT}/hack/update-codegen.sh" | ||
echo "diffing ${DIFFROOT} against freshly generated codegen" | ||
ret=0 | ||
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? | ||
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" | ||
if [[ $ret -eq 0 ]] | ||
then | ||
echo "${DIFFROOT} up to date." | ||
else | ||
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" | ||
exit 1 | ||
fi |