Skip to content

Commit

Permalink
Update make generate (#132)
Browse files Browse the repository at this point in the history
* update make generate and add clientset for orchestration/v1alpha1

* add make verify

* nit makefile changes

* add verify in ci

* add license

* nit

* nit

* remove make verify for now

* restore make generate, remove doc.go and add make verify-codegen in CI

* add generate in other make commands

---------

Co-authored-by: varungupta <varungupta@BYTEDANCE.COM>
  • Loading branch information
varungup90 and varungupta authored Sep 6, 2024
1 parent dc29371 commit 01b78cf
Show file tree
Hide file tree
Showing 40 changed files with 2,619 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ "main" ]

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand All @@ -18,5 +18,7 @@ jobs:
go-version: '1.22'
- name: Lint
run: make lint-all
- name: Verify
run: bash ${GITHUB_WORKSPACE}/hack/verify-codegen.sh
- name: Unit Test
run: make test
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: update-codegen
update-codegen:
sh ./hack/update-codegen.sh

.PHONY: verify-codegen
verify-codegen:
sh ./hack/verify-codegen.sh

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down
1 change: 1 addition & 0 deletions api/autoscaling/v1alpha1/podautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type PodAutoscalerStatus struct {
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PodAutoscalerList contains a list of PodAutoscaler
type PodAutoscalerList struct {
Expand Down
1 change: 1 addition & 0 deletions api/model/v1alpha1/modeladapter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type ModelAdapter struct {
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ModelAdapterList contains a list of ModelAdapter
type ModelAdapterList struct {
Expand Down
7 changes: 7 additions & 0 deletions api/orchestration/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "orchestration.aibrix.ai", Version: "v1alpha1"}

// SchemeGroupVersion is group version used to register these objects.
SchemeGroupVersion = GroupVersion

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
9 changes: 6 additions & 3 deletions api/orchestration/v1alpha1/rayclusterfleet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ const (
FleetReplicaFailure FleetConditionType = "ReplicaFailure"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// RayClusterFleet is the Schema for the rayclusterfleets API
type RayClusterFleet struct {
Expand All @@ -158,7 +160,8 @@ type RayClusterFleet struct {
Status RayClusterFleetStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// RayClusterFleetList contains a list of RayClusterFleet
type RayClusterFleetList struct {
Expand Down
9 changes: 6 additions & 3 deletions api/orchestration/v1alpha1/rayclusterreplicaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ type RayClusterReplicaSetStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,6,rep,name=conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// RayClusterReplicaSet is the Schema for the rayclusterreplicasets API
type RayClusterReplicaSet struct {
Expand All @@ -95,7 +97,8 @@ type RayClusterReplicaSet struct {
Status RayClusterReplicaSetStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// RayClusterReplicaSetList contains a list of RayClusterReplicaSet
type RayClusterReplicaSetList struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/development/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kind load docker-image aibrix/vllm:v0.1.0
2. Deploy mocked model image
```shell
kubectl apply -f docs/development/app/deployment.yaml
kubectl port-forward svc/llama2-70b 8000:8000 &
kubectl -n aibrix-system port-forward svc/llama2-70b 8000:8000 &
```

## Test python app separately
Expand Down
5 changes: 3 additions & 2 deletions hack/update-codegen.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ echo ">> Temporary output directory ${TEMP_DIR}"

# Ensure we can execute.
chmod +x ${CODEGEN_PKG}/generate-groups.sh
chmod +x ${CODEGEN_PKG}/generate-internal-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 all \
${CODEGEN_PKG}/generate-groups.sh applyconfiguration,client,informer,lister \
github.com/aibrix/aibrix/pkg/client github.com/aibrix/aibrix/api \
"model:v1alpha1 autoscaling:v1alpha1" \
"model:v1alpha1 autoscaling:v1alpha1 orchestration:v1alpha1" \
--output-base "${TEMP_DIR}" \
--go-header-file hack/boilerplate.go.txt

Expand Down
61 changes: 25 additions & 36 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,35 @@ set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
ROOT_PKG=github.com/aibrix/aibrix
DIFFROOT="${SCRIPT_ROOT}/pkg/client"
TMP_DIFFROOT="$(mktemp -d -t "$(basename "$0").XXXXXX")"

# 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}
rm -rf "${TMP_DIFFROOT}"
}
trap "cleanup" EXIT SIGINT

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

mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

# 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 all \
github.com/aibrix/aibrix/pkg/client github.com/aibrix/aibrix/api \
"model:v1alpha1 autoscaling:v1alpha1" \
--output-base "${TEMP_DIR}" \
--go-header-file hack/boilerplate.go.txt

# Copy everything back.
cp -a "${TEMP_DIR}/${ROOT_PKG}/." "${SCRIPT_ROOT}/"
chmod +x ${SCRIPT_ROOT}/hack/update-codegen.sh

"${SCRIPT_ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
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

# smoke test
echo "Smoke testing by compiling..."
pushd "${SCRIPT_ROOT}"
go build "${DIFFROOT}/..."
popd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 01b78cf

Please sign in to comment.