volcano.sh/apis@v1.8.2/hack/generate-internal-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-internal-groups generates everything for a project with internal types, e.g. an
    22  # user-provided API server based on k8s.io/apiserver.
    23  
    24  if [ "$#" -lt 5 ] || [ "${1}" == "--help" ]; then
    25    cat <<EOF
    26  Usage: $(basename "$0") <generators> <output-package> <internal-apis-package> <extensiona-apis-package> <groups-versions> ...
    27  
    28    <generators>        the generators comma separated to run (deepcopy,defaulter,conversion,client,lister,informer,openapi) or "all".
    29    <output-package>    the output package name (e.g. github.com/example/project/pkg/generated).
    30    <int-apis-package>  the internal types dir (e.g. github.com/example/project/pkg/apis).
    31    <ext-apis-package>  the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis).
    32    <groups-versions>   the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
    33                        to <api-package>.
    34    ...                 arbitrary flags passed to all generator binaries.
    35  
    36  Examples:
    37    $(basename "$0") all                           github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1"
    38    $(basename "$0") deepcopy,defaulter,conversion github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis     "foo:v1 bar:v1alpha1,v1beta1"
    39  EOF
    40    exit 0
    41  fi
    42  
    43  GENS="$1"
    44  OUTPUT_PKG="$2"
    45  INT_APIS_PKG="$3"
    46  EXT_APIS_PKG="$4"
    47  GROUPS_WITH_VERSIONS="$5"
    48  shift 5
    49  
    50  go install k8s.io/code-generator/cmd/{defaulter-gen,conversion-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,openapi-gen}@v0.25.0
    51  
    52  # Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
    53  GOBIN="$(go env GOBIN)"
    54  gobin="${GOBIN:-$(go env GOPATH)/bin}"
    55  
    56  function codegen::join() { local IFS="$1"; shift; echo "$*"; }
    57  
    58  # enumerate group versions
    59  ALL_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
    60  INT_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps
    61  EXT_FQ_APIS=() # e.g. k8s.io/api/apps/v1
    62  for GVs in ${GROUPS_WITH_VERSIONS}; do
    63    IFS=: read -r G Vs <<<"${GVs}"
    64  
    65    if [ -n "${INT_APIS_PKG}" ]; then
    66      ALL_FQ_APIS+=("${INT_APIS_PKG}/${G}")
    67      INT_FQ_APIS+=("${INT_APIS_PKG}/${G}")
    68    fi
    69  
    70    # enumerate versions
    71    for V in ${Vs//,/ }; do
    72      ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
    73      EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
    74    done
    75  done
    76  
    77  if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
    78    echo "Generating deepcopy funcs"
    79    "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${INT_APIS_PKG},${EXT_APIS_PKG}" "$@"
    80  fi
    81  
    82  if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then
    83    echo "Generating defaulters"
    84    "${gobin}/defaulter-gen"  --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" -O zz_generated.defaults "$@"
    85  fi
    86  
    87  if [ "${GENS}" = "all" ] || grep -qw "conversion" <<<"${GENS}"; then
    88    echo "Generating conversions"
    89    "${gobin}/conversion-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.conversion "$@"
    90  fi
    91  
    92  if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
    93    echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
    94    if [ -n "${INT_APIS_PKG}" ]; then
    95      IFS=" " read -r -a APIS <<< "$(printf '%s/ ' "${INT_FQ_APIS[@]}")"
    96      "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_INTERNAL:-internalversion}" --input-base "" --input "$(codegen::join , "${APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
    97    fi
    98    "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${EXT_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
    99  fi
   100  
   101  if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
   102    echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
   103    "${gobin}/lister-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
   104  fi
   105  
   106  if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
   107    echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
   108    "${gobin}/informer-gen" \
   109             --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
   110             --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
   111             --internal-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_INTERNAL:-internalversion}" \
   112             --listers-package "${OUTPUT_PKG}/listers" \
   113             --output-package "${OUTPUT_PKG}/informers" \
   114             "$@"
   115  fi
   116  
   117  if [ "${GENS}" = "all" ] || grep -qw "openapi" <<<"${GENS}"; then
   118    echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
   119    declare -a OPENAPI_EXTRA_PACKAGES
   120    "${gobin}/openapi-gen" \
   121             --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}" "${OPENAPI_EXTRA_PACKAGES[@]}")" \
   122             --input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version" \
   123             --output-package "${OUTPUT_PKG}/openapi" \
   124             -O zz_generated.openapi \
   125             "$@"
   126  fi