...
1#!/usr/bin/env bash
2
3# Copyright 2020 The Kubernetes Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -o errexit
18set -o nounset
19set -o pipefail
20
21readonly SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE}")"/.. && pwd)"
22
23# Keep outer module cache so we don't need to redownload them each time.
24# The build cache already is persisted.
25readonly GOMODCACHE="$(go env GOMODCACHE)"
26readonly GO111MODULE="on"
27readonly GOFLAGS="-mod=readonly"
28readonly GOPATH="$(mktemp -d)"
29readonly MIN_REQUIRED_GO_VER="$(go list -m -f '{{.GoVersion}}')"
30
31function go_version_matches {
32 go version | perl -ne "exit 1 unless m{go version go([0-9]+.[0-9]+)}; exit 1 if (\$1 < ${MIN_REQUIRED_GO_VER})"
33 return $?
34}
35
36if ! go_version_matches; then
37 echo "Go v${MIN_REQUIRED_GO_VER} or later is required to run code generation"
38 exit 1
39fi
40
41export GOMODCACHE GO111MODULE GOFLAGS GOPATH
42
43# Even when modules are enabled, the code-generator tools always write to
44# a traditional GOPATH directory, so fake on up to point to the current
45# workspace.
46mkdir -p "$GOPATH/src/sigs.k8s.io"
47ln -s "${SCRIPT_ROOT}" "$GOPATH/src/sigs.k8s.io/gateway-api"
48
49readonly OUTPUT_PKG=sigs.k8s.io/gateway-api/pkg/client
50readonly APIS_PKG=sigs.k8s.io/gateway-api
51readonly CLIENTSET_NAME=versioned
52readonly CLIENTSET_PKG_NAME=clientset
53
54if [[ "${VERIFY_CODEGEN:-}" == "true" ]]; then
55 echo "Running in verification mode"
56 readonly VERIFY_FLAG="--verify-only"
57fi
58
59readonly COMMON_FLAGS="${VERIFY_FLAG:-} --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generatego.txt"
60
61echo "Generating CRDs"
62go run ./pkg/generator
63
64echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}"
65go run k8s.io/code-generator/cmd/client-gen \
66 --clientset-name "${CLIENTSET_NAME}" \
67 --input-base "" \
68 --input "${APIS_PKG}/apis/v1alpha2,${APIS_PKG}/apis/v1beta1,${APIS_PKG}/apis/v1" \
69 --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \
70 ${COMMON_FLAGS}
71
72echo "Generating listers at ${OUTPUT_PKG}/listers"
73go run k8s.io/code-generator/cmd/lister-gen \
74 --input-dirs "${APIS_PKG}/apis/v1alpha2,${APIS_PKG}/apis/v1beta1,${APIS_PKG}/apis/v1" \
75 --output-package "${OUTPUT_PKG}/listers" \
76 ${COMMON_FLAGS}
77
78echo "Generating informers at ${OUTPUT_PKG}/informers"
79go run k8s.io/code-generator/cmd/informer-gen \
80 --input-dirs "${APIS_PKG}/apis/v1alpha2,${APIS_PKG}/apis/v1beta1,${APIS_PKG}/apis/v1" \
81 --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}/${CLIENTSET_NAME}" \
82 --listers-package "${OUTPUT_PKG}/listers" \
83 --output-package "${OUTPUT_PKG}/informers" \
84 ${COMMON_FLAGS}
85
86for VERSION in v1alpha2 v1beta1 v1
87do
88 echo "Generating ${VERSION} register at ${APIS_PKG}/apis/${VERSION}"
89 go run k8s.io/code-generator/cmd/register-gen \
90 --input-dirs "${APIS_PKG}/apis/${VERSION}" \
91 --output-package "${APIS_PKG}/apis/${VERSION}" \
92 ${COMMON_FLAGS}
93
94 echo "Generating ${VERSION} deepcopy at ${APIS_PKG}/apis/${VERSION}"
95 go run sigs.k8s.io/controller-tools/cmd/controller-gen \
96 object:headerFile=${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generatego.txt \
97 paths="${APIS_PKG}/apis/${VERSION}"
98
99done
View as plain text