1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #!/usr/bin/env bash
set -o errexit set -o nounset set -o pipefail
if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then cat <<EOF Usage: $(basename "$0") <generators> <output-package> <apis-package> <groups-versions> ...
<generators> the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all". <output-package> the output package name (e.g. github.com/example/project/pkg/generated). <apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). <groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative to <api-package>. ... arbitrary flags passed to all generator binaries.
Examples: $(basename "$0") all github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" $(basename "$0") deepcopy,client github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" EOF exit 0 fi
GENS="$1" OUTPUT_PKG="$2" APIS_PKG="$3" GROUPS_WITH_VERSIONS="$4" shift 4
( cd "$(dirname "${0}")" GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} )
GOBIN="$(go env GOBIN)" gobin="${GOBIN:-$(go env GOPATH)/bin}"
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
FQ_APIS=() for GVs in ${GROUPS_WITH_VERSIONS}; do IFS=: read -r G Vs <<<"${GVs}"
for V in ${Vs//,/ }; do FQ_APIS+=("${APIS_PKG}/${G}/${V}") done done
if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs" "${gobin}/deepcopy-gen" \ --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ -O zz_generated.deepcopy \ "$@" fi
if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "${gobin}/client-gen" \ --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \ --input-base "" \ --input "$(codegen::join , "${FQ_APIS[@]}")" \ --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" \ --plural-exceptions "ProductInstanceVpcInfo:ProductInstanceVpcInfoes" \ "$@" fi
if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" "${gobin}/lister-gen" \ --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ --output-package "${OUTPUT_PKG}/listers" \ --plural-exceptions "ProductInstanceVpcInfo:ProductInstanceVpcInfoes" \ "$@" fi
if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" "${gobin}/informer-gen" \ --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \ --listers-package "${OUTPUT_PKG}/listers" \ --output-package "${OUTPUT_PKG}/informers" \ --plural-exceptions "ProductInstanceVpcInfo:ProductInstanceVpcInfoes" \ "$@" fi
|