volcano.sh/volcano@v1.9.0/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  (
    50    # To support running this script from anywhere, first cd into this directory,
    51    # and then install with forced module mode on and fully qualified name.
    52    cd "$(dirname "${0}")"
    53    GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
    54  )
    55  # Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
    56  GOBIN="$(go env GOBIN)"
    57  gobin="${GOBIN:-$(go env GOPATH)/bin}"
    58  
    59  function codegen::join() { local IFS="$1"; shift; echo "$*"; }
    60  
    61  # enumerate group versions
    62  FQ_APIS=() # e.g. k8s.io/api/apps/v1
    63  for GVs in ${GROUPS_WITH_VERSIONS}; do
    64    IFS=: read -r G Vs <<<"${GVs}"
    65  
    66    # enumerate versions
    67    for V in ${Vs//,/ }; do
    68      FQ_APIS+=("${APIS_PKG}/${G}/${V}")
    69    done
    70  done
    71  
    72  if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
    73    echo "Generating deepcopy funcs"
    74    "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy "$@"
    75  fi
    76  
    77  if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
    78    echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
    79    "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
    80  fi
    81  
    82  if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
    83    echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
    84    "${gobin}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
    85  fi
    86  
    87  if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
    88    echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
    89    "${gobin}/informer-gen" \
    90             --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
    91             --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
    92             --listers-package "${OUTPUT_PKG}/listers" \
    93             --output-package "${OUTPUT_PKG}/informers" \
    94             "$@"
    95  fi