Skip to content

Commit

Permalink
Merge pull request #329 from ashnehete/kube_codegen
Browse files Browse the repository at this point in the history
Migrate to use kube_codegen.sh to generate client
  • Loading branch information
k8s-ci-robot authored Nov 15, 2023
2 parents c82eb64 + 407024b commit 2466090
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ code-generator:
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)
cp -f $(CODEGEN_ROOT)/generate-groups.sh $(PROJECT_DIR)/bin/
cp -f $(CODEGEN_ROOT)/generate-internal-groups.sh $(PROJECT_DIR)/bin/
cp -f $(CODEGEN_ROOT)/kube_codegen.sh $(PROJECT_DIR)/bin/


.PHONY: openapi-gen
Expand Down
23 changes: 23 additions & 0 deletions api/jobset/v1alpha2/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
This file is needed for kubernetes/code-generator/kube_codegen.sh script used in hack/update-codegen.sh.
*/

package v1alpha2

//+genclient
46 changes: 23 additions & 23 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ set -o errexit
set -o nounset
set -o pipefail

cd "$(dirname "${0}")"
cd "$(dirname "${0}")/.."
GO_CMD=${1:-go}
CODEGEN_PKG=${2:-../bin}
CODEGEN_PKG=${2:-bin}
REPO_ROOT="$(git rev-parse --show-toplevel)"

echo "GOPATH=$GOPATH"

chmod +x "${CODEGEN_PKG}/generate-internal-groups.sh"

bash "${CODEGEN_PKG}/generate-groups.sh" \
"applyconfiguration,client,informer,lister" \
sigs.k8s.io/jobset/client-go \
sigs.k8s.io/jobset/api \
jobset:v1alpha2 \
--go-header-file ./boilerplate.go.txt

# if client-go files were generated outside of repo root, attempt to move them to the repo root.
CLIENT_GO=$(find $GOPATH -regextype sed -regex ".*jobset.*client-go")
if [ -z "$CLIENT_GO" ]; then
echo "WARNING: generated client-go files were not found."
elif [ "$CLIENT_GO" != "$REPO_ROOT/client-go" ]; then
echo "moving generated files from $CLIENT_GO to $REPO_ROOT/client-go"
rm -rf $REPO_ROOT/client-go
mv -f $CLIENT_GO $REPO_ROOT

fi


source "${CODEGEN_PKG}/kube_codegen.sh"

# TODO: remove the workaround when the issue is solved in the code-generator
# (https://github.com/kubernetes/code-generator/issues/165).
# Here, we create the soft link named "sigs.k8s.io" to the parent directory of
# Jobset to ensure the layout required by the kube_codegen.sh script.
ln -s .. sigs.k8s.io
trap "rm sigs.k8s.io" EXIT

kube::codegen::gen_helpers \
--input-pkg-root sigs.k8s.io/jobset/api \
--output-base "${REPO_ROOT}" \
--boilerplate "${REPO_ROOT}/hack/boilerplate.go.txt"

kube::codegen::gen_client \
--with-watch \
--with-applyconfig \
--input-pkg-root sigs.k8s.io/jobset/api \
--output-base "$REPO_ROOT" \
--output-pkg-root sigs.k8s.io/jobset/client-go \
--boilerplate "${REPO_ROOT}/hack/boilerplate.go.txt"

0 comments on commit 2466090

Please sign in to comment.