volcano.sh/volcano@v1.9.0/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  (
    51    # To support running this script from anywhere, first cd into this directory,
    52    # and then install with forced module mode on and fully qualified name.
    53    cd "$(dirname "${0}")"
    54    GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,conversion-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,openapi-gen}
    55  )
    56  
    57  function codegen::join() { local IFS="$1"; shift; echo "$*"; }
    58  
    59  # enumerate group versions
    60  ALL_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
    61  INT_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps
    62  EXT_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    if [ -n "${INT_APIS_PKG}" ]; then
    67      ALL_FQ_APIS+=("${INT_APIS_PKG}/${G}")
    68      INT_FQ_APIS+=("${INT_APIS_PKG}/${G}")
    69    fi
    70  
    71    # enumerate versions
    72    for V in ${Vs//,/ }; do
    73      ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
    74      EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
    75    done
    76  done
    77  
    78  if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
    79    echo "Generating deepcopy funcs"
    80    "${GOPATH}/bin/deepcopy-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.deepcopy "$@"
    81  fi
    82  
    83  if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then
    84    echo "Generating defaulters"
    85    "${GOPATH}/bin/defaulter-gen"  --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" -O zz_generated.defaults "$@"
    86  fi
    87  
    88  if [ "${GENS}" = "all" ] || grep -qw "conversion" <<<"${GENS}"; then
    89    echo "Generating conversions"
    90    "${GOPATH}/bin/conversion-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.conversion "$@"
    91  fi
    92  
    93  if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
    94    echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
    95    if [ -n "${INT_APIS_PKG}" ]; then
    96      IFS=" " read -r -a APIS <<< "$(printf '%s/ ' "${INT_FQ_APIS[@]}")"
    97      "${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_INTERNAL:-internalversion}" --input-base "" --input "$(codegen::join , "${APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
    98    fi
    99    "${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${EXT_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
   100  fi
   101  
   102  if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
   103    echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
   104    "${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
   105  fi
   106  
   107  if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
   108    echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
   109    "${GOPATH}/bin/informer-gen" \
   110             --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
   111             --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
   112             --internal-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_INTERNAL:-internalversion}" \
   113             --listers-package "${OUTPUT_PKG}/listers" \
   114             --output-package "${OUTPUT_PKG}/informers" \
   115             "$@"
   116  fi
   117  
   118  if [ "${GENS}" = "all" ] || grep -qw "openapi" <<<"${GENS}"; then
   119    echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
   120    declare -a OPENAPI_EXTRA_PACKAGES
   121    "${GOPATH}/bin/openapi-gen" \
   122             --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}" "${OPENAPI_EXTRA_PACKAGES[@]+"${OPENAPI_EXTRA_PACKAGES[@]}"}")" \
   123             --input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version" \
   124             --output-package "${OUTPUT_PKG}/openapi" \
   125             -O zz_generated.openapi \
   126             "$@"
   127  fi