volcano.sh/apis@v1.8.2/hack/generate-groups.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2017 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  
    17  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  # generate-groups generates everything for a project with external types only, e.g. a project based
    22  # on CustomResourceDefinitions.
    23  
    24  if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then
    25    cat <<EOF
    26  Usage: $(basename "$0") <generators> <output-package> <apis-package> <groups-versions> ...
    27  
    28    <generators>        the generators comma separated to run (deepcopy,defaulter,client,lister,informer) or "all".
    29    <output-package>    the output package name (e.g. github.com/example/project/pkg/generated).
    30    <apis-package>      the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis).
    31    <groups-versions>   the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
    32                        to <api-package>.
    33    ...                 arbitrary flags passed to all generator binaries.
    34  
    35  
    36  Examples:
    37    $(basename "$0") all             github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
    38    $(basename "$0") deepcopy,client github.com/example/project/pkg/client github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
    39  EOF
    40    exit 0
    41  fi
    42  
    43  GENS="$1"
    44  OUTPUT_PKG="$2"
    45  APIS_PKG="$3"
    46  GROUPS_WITH_VERSIONS="$4"
    47  shift 4
    48  
    49  go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,conversion-gen}@v0.25.0
    50  
    51  # Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
    52  GOBIN="$(go env GOBIN)"
    53  gobin="${GOBIN:-$(go env GOPATH)/bin}"
    54  
    55  function codegen::join() { local IFS="$1"; shift; echo "$*"; }
    56  
    57  # enumerate group versions
    58  FQ_APIS=() # e.g. k8s.io/api/apps/v1
    59  for GVs in ${GROUPS_WITH_VERSIONS}; do
    60    IFS=: read -r G Vs <<<"${GVs}"
    61  
    62    # enumerate versions
    63    for V in ${Vs//,/ }; do
    64      FQ_APIS+=("${APIS_PKG}/${G}/${V}")
    65    done
    66  done
    67  
    68  if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
    69    echo "Generating deepcopy funcs"
    70    "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@"
    71  fi
    72  
    73  if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
    74    echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
    75    "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
    76  fi
    77  
    78  if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
    79    echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
    80    "${gobin}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
    81  fi
    82  
    83  if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
    84    echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
    85    "${gobin}/informer-gen" \
    86             --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
    87             --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
    88             --listers-package "${OUTPUT_PKG}/listers" \
    89             --output-package "${OUTPUT_PKG}/informers" \
    90             "$@"
    91  fi
    92  
    93  if grep -qw "conversion" <<<"${GENS}"; then
    94    echo "Generating conversion funcs"
    95    "${gobin}/conversion-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.conversion "$@"
    96  fi