Skip to content

Commit

Permalink
hack,Makefile: Update codegen to reflect new api structure
Browse files Browse the repository at this point in the history
   - Updates codegen scripts for new paths
   - Ensures generated code works with new structure

Signed-off-by: timflannagan <[email protected]>
  • Loading branch information
timflannagan committed Feb 6, 2025
1 parent 840835c commit 6a2a5c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ generated-code: fmt

.PHONY: go-generate-all
go-generate-all: ## Run all go generate directives in the repo, including codegen for protos, mockgen, and more
GO111MODULE=on go generate ./internal/gateway2/...
GO111MODULE=on go generate ./hack/...

.PHONY: go-generate-mocks
go-generate-mocks: ## Runs all generate directives for mockgen in the repo
Expand Down
38 changes: 18 additions & 20 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
# generate deep copy and clients for our api.
# In this project, clients mostly used as fakes for testing.

set -e
set -x
set -o errexit
set -o nounset
set -o pipefail

APIS_PKG=""
set -x

readonly SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE}")" && pwd)"
readonly OUTPUT_PKG=github.com/kgateway-dev/kgateway/projects/gateway2/pkg/client
readonly APIS_PKG=github.com/kgateway-dev/kgateway/projects/gateway2
readonly ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE}")"/.. && pwd)"
readonly OUTPUT_PKG=github.com/kgateway-dev/kgateway/pkg/client
readonly APIS_PKG=github.com/kgateway-dev/kgateway
readonly CLIENTSET_NAME=versioned
readonly CLIENTSET_PKG_NAME=clientset
readonly VERSIONS=(v1alpha1)
readonly VERSIONS=( v1alpha1 )

echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME} for versions: ${VERSIONS[@]}"
echo "Running from directory: ${SCRIPT_ROOT}"

API_INPUT_DIRS_SPACE=""
API_INPUT_DIRS_COMMA=""
Expand All @@ -31,17 +31,16 @@ API_INPUT_DIRS_COMMA="${API_INPUT_DIRS_COMMA%,}" # drop trailing comma

go run k8s.io/code-generator/cmd/register-gen --output-file zz_generated.register.go ${API_INPUT_DIRS_SPACE}
go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:maxDescLen=0 object rbac:roleName=kgateway paths="${APIS_PKG}/api/${VERSION}" \
output:crd:artifacts:config=${SCRIPT_ROOT}/../../install/helm/kgateway/crds/ output:rbac:artifacts:config=${SCRIPT_ROOT}/../../install/helm/kgateway/templates
output:crd:artifacts:config=${ROOT_DIR}/install/helm/kgateway/crds/ output:rbac:artifacts:config=${ROOT_DIR}/install/helm/kgateway/templates

# throw away
new_report="$(mktemp -t "$(basename "$0").api_violations.XXXXXX")"

go run k8s.io/kube-openapi/cmd/openapi-gen \
--output-file zz_generated.openapi.go \
--report-filename "${new_report}" \
--output-dir "pkg/generated/openapi" \
--output-pkg "${APIS_PKG}/pkg/generated/openapi" \
${COMMON_FLAGS} \
--output-dir "${ROOT_DIR}/pkg/generated/openapi" \
--output-pkg "github.com/kgateway-dev/kgateway/pkg/generated/openapi" \
$API_INPUT_DIRS_SPACE \
sigs.k8s.io/gateway-api/apis/v1 \
k8s.io/apimachinery/pkg/apis/meta/v1 \
Expand All @@ -52,20 +51,19 @@ go run k8s.io/kube-openapi/cmd/openapi-gen \
k8s.io/apimachinery/pkg/version

go run k8s.io/code-generator/cmd/applyconfiguration-gen \
--openapi-schema <(go run ${SCRIPT_ROOT}/cmd/modelschema) \
--output-dir "api/applyconfiguration" \
--output-pkg "${APIS_PKG}/api/applyconfiguration" \
${COMMON_FLAGS} \
--openapi-schema <(go run ${ROOT_DIR}/cmd/modelschema) \
--output-dir "${ROOT_DIR}/api/applyconfiguration" \
--output-pkg "github.com/kgateway-dev/kgateway/api/applyconfiguration" \
${API_INPUT_DIRS_SPACE}

go run k8s.io/code-generator/cmd/client-gen \
--clientset-name "versioned" \
--input-base "${APIS_PKG}" \
--input "${API_INPUT_DIRS_COMMA//${APIS_PKG}/}" \
--output-dir "pkg/client/${CLIENTSET_PKG_NAME}" \
--output-dir "${ROOT_DIR}/pkg/client/${CLIENTSET_PKG_NAME}" \
--output-pkg "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \
--apply-configuration-package "${APIS_PKG}/api/applyconfiguration" \
${COMMON_FLAGS}
--apply-configuration-package "${APIS_PKG}/api/applyconfiguration"

# fix imports of gen code
go run golang.org/x/tools/cmd/goimports -w ${SCRIPT_ROOT}/api/v1alpha1
go run golang.org/x/tools/cmd/goimports -w ${ROOT_DIR}/pkg/client
go run golang.org/x/tools/cmd/goimports -w ${ROOT_DIR}/api

0 comments on commit 6a2a5c8

Please sign in to comment.