diff --git a/hack/lib/init.sh b/hack/lib/init.sh index 4aafe51f58..aa01fc10c2 100644 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -44,6 +44,31 @@ source "${KUBE_ROOT}/hack/lib/etcd.sh" KUBE_OUTPUT_HOSTBIN="${KUBE_OUTPUT_BINPATH}/$(kube::util::host_platform)" +# list of all available group versions. This should be used when generated code +# or when starting an API server that you want to have everything. +# most preferred version for a group should appear first +KUBE_AVAILABLE_GROUP_VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS:-\ +v1 \ +apps/v1alpha1 \ +authentication.k8s.io/v1beta1 \ +authorization.k8s.io/v1beta1 \ +autoscaling/v1 \ +batch/v1 \ +batch/v2alpha1 \ +certificates.k8s.io/v1alpha1 \ +extensions/v1beta1 \ +imagepolicy.k8s.io/v1alpha1 \ +policy/v1alpha1 \ +rbac.authorization.k8s.io/v1alpha1 \ +storage.k8s.io/v1beta1\ +}" + +# not all group versions are exposed by the server. This list contains those +# which are not available so we don't generate clients or swagger for them +KUBE_NONSERVER_GROUP_VERSIONS=" + imagepolicy.k8s.io/v1alpha1 +" + # This emulates "readlink -f" which is not available on MacOS X. # Test: # T=/tmp/$$.$RANDOM diff --git a/hack/lib/util.sh b/hack/lib/util.sh index f6b6d162bd..549f6f0bbf 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -312,10 +312,10 @@ kube::util::group-version-to-pkg-path() { echo "api/unversioned" ;; *.k8s.io) - echo "apis/${group_version%.k8s.io}" + echo "apis/${group_version%.*k8s.io}" ;; *.k8s.io/*) - echo "apis/${group_version/.k8s.io/}" + echo "apis/${group_version/.*k8s.io/}" ;; *) echo "apis/${group_version%__internal}" @@ -347,6 +347,9 @@ kube::util::gv-to-swagger-name() { # VERSIONS: Array of group versions to include in swagger spec. kube::util::fetch-swagger-spec() { for ver in ${VERSIONS}; do + if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${ver} "* ]]; then + continue + fi # fetch the swagger spec for each group version. if [[ ${ver} == "v1" ]]; then SUBPATH="api" diff --git a/hack/make-rules/test-integration.sh b/hack/make-rules/test-integration.sh index 063c6104be..63e400280f 100755 --- a/hack/make-rules/test-integration.sh +++ b/hack/make-rules/test-integration.sh @@ -27,7 +27,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh" # KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1"} # FIXME: due to current implementation of a test client (see: pkg/api/testapi/testapi.go) # ONLY the last version is tested in each group. -KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,authentication.k8s.io/v1beta1,authorization.k8s.io/v1beta1,autoscaling/v1,batch/v1,apps/v1alpha1,policy/v1alpha1,extensions/v1beta1,rbac.authorization.k8s.io/v1alpha1,certificates.k8s.io/v1alpha1,storage.k8s.io/v1beta1"} +ALL_VERSIONS_CSV=$(IFS=',';echo "${KUBE_AVAILABLE_GROUP_VERSIONS[*]// /,}";IFS=$) +KUBE_TEST_API_VERSIONS="${KUBE_TEST_API_VERSIONS:-${ALL_VERSIONS_CSV}}" # Give integration tests longer to run # TODO: allow a larger value to be passed in diff --git a/hack/make-rules/test.sh b/hack/make-rules/test.sh index 3484991c7d..690d7e04e8 100755 --- a/hack/make-rules/test.sh +++ b/hack/make-rules/test.sh @@ -66,7 +66,8 @@ KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-} # "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3" # FIXME: due to current implementation of a test client (see: pkg/api/testapi/testapi.go) # ONLY the last version is tested in each group. -KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,apps/v1alpha1,authentication.k8s.io/v1beta1,authorization.k8s.io/v1beta1,autoscaling/v1,batch/v1,batch/v2alpha1,certificates.k8s.io/v1alpha1,extensions/v1beta1,federation/v1beta1,policy/v1alpha1,rbac.authorization.k8s.io/v1alpha1,imagepolicy.k8s.io/v1alpha1,storage.k8s.io/v1beta1"} +ALL_VERSIONS_CSV=$(IFS=',';echo "${KUBE_AVAILABLE_GROUP_VERSIONS[*]// /,}";IFS=$),federation/v1beta1 +KUBE_TEST_API_VERSIONS="${KUBE_TEST_API_VERSIONS:-${ALL_VERSIONS_CSV}}" # once we have multiple group supports # Create a junit-style XML test report in this directory if set. KUBE_JUNIT_REPORT_DIR=${KUBE_JUNIT_REPORT_DIR:-} @@ -295,6 +296,7 @@ checkFDs() { checkFDs + # Convert the CSVs to arrays. IFS=';' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}" apiVersionsCount=${#apiVersions[@]} diff --git a/hack/update-api-reference-docs.sh b/hack/update-api-reference-docs.sh index 3e30668efc..6dae42e178 100755 --- a/hack/update-api-reference-docs.sh +++ b/hack/update-api-reference-docs.sh @@ -34,12 +34,19 @@ OUTPUT=${1:-${DEFAULT_OUTPUT}} SWAGGER_SPEC_PATH="${REPO_DIR}/api/swagger-spec" -GROUP_VERSIONS=("v1" "extensions/v1beta1" "batch/v1" "authentication.k8s.io/v1beta1" "autoscaling/v1" "certificates.k8s.io/v1alpha1") +ALL_GROUP_VERSIONS=(${KUBE_AVAILABLE_GROUP_VERSIONS}) +INTERESTING_GROUP_VERSIONS=() GV_DIRS=() -for gv in "${GROUP_VERSIONS[@]}"; do - GV_DIRS+=("${REPO_DIR}/pkg/$(kube::util::group-version-to-pkg-path "${gv}")") +for gv in "${ALL_GROUP_VERSIONS[@]}"; do + # skip groups that aren't being served, clients for these don't matter + if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then + continue + fi + + INTERESTING_GROUP_VERSIONS+=(${gv}) + GV_DIRS+=("${REPO_DIR}/pkg/$(kube::util::group-version-to-pkg-path "${gv}")") done -GROUP_VERSIONS="${GROUP_VERSIONS[@]}" GV_DIRS="${GV_DIRS[@]}" kube::swagger::gen_api_ref_docs "${SWAGGER_SPEC_PATH}" "${OUTPUT}" +GROUP_VERSIONS="${INTERESTING_GROUP_VERSIONS[@]}" GV_DIRS="${GV_DIRS[@]}" kube::swagger::gen_api_ref_docs "${SWAGGER_SPEC_PATH}" "${OUTPUT}" # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index ad07f4a875..a6a6a11a5f 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -35,11 +35,37 @@ setgen=$(kube::util::find-binary "set-gen") # Please do not add any logic to this shell script. Add logic to the go code # that generates the set-gen program. # + +GROUP_VERSIONS=(${KUBE_AVAILABLE_GROUP_VERSIONS}) +GV_DIRS=() +SEEN_GROUPS="," +for gv in "${GROUP_VERSIONS[@]}"; do + # add items, but strip off any leading apis/ you find to match command expectations + api_dir=$(kube::util::group-version-to-pkg-path "${gv}") + pkg_dir=${api_dir#apis/} + + # don't add a version for a group you've already seen + group=${pkg_dir%%/*} + if [[ "${SEEN_GROUPS}" == *",${group}."* ]]; then + continue + fi + SEEN_GROUPS="${SEEN_GROUPS},${group}." + + # skip groups that aren't being served, clients for these don't matter + if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then + continue + fi + + GV_DIRS+=("${pkg_dir}") +done +# delimit by commas for the command +GV_DIRS_CSV=$(IFS=',';echo "${GV_DIRS[*]// /,}";IFS=$) + # This can be called with one flag, --verify-only, so it works for both the # update- and verify- scripts. ${clientgen} "$@" ${clientgen} -t "$@" -${clientgen} --clientset-name="release_1_5" --input="api/v1,authorization/v1beta1,autoscaling/v1,batch/v1,extensions/v1beta1,policy/v1alpha1,storage/v1beta1" "$@" +${clientgen} --clientset-name="release_1_5" --input="${GV_DIRS_CSV}" "$@" # Clientgen for federation clientset. ${clientgen} --clientset-name=federation_internalclientset --clientset-path=k8s.io/kubernetes/federation/client/clientset_generated --input="../../federation/apis/federation/","api/","extensions/" --included-types-overrides="api/Service,api/Namespace,extensions/ReplicaSet,api/Secret,extensions/Ingress,api/Event" "$@" ${clientgen} --clientset-name=federation_release_1_5 --clientset-path=k8s.io/kubernetes/federation/client/clientset_generated --input="../../federation/apis/federation/v1beta1","api/v1","extensions/v1beta1" --included-types-overrides="api/v1/Service,api/v1/Namespace,extensions/v1beta1/ReplicaSet,api/v1/Secret,extensions/v1beta1/Ingress,api/v1/Event" "$@" diff --git a/hack/update-generated-swagger-docs.sh b/hack/update-generated-swagger-docs.sh index 6bac92e66e..12091c3d93 100755 --- a/hack/update-generated-swagger-docs.sh +++ b/hack/update-generated-swagger-docs.sh @@ -28,7 +28,8 @@ source "${KUBE_ROOT}/hack/lib/swagger.sh" kube::golang::setup_env -GROUP_VERSIONS=(unversioned v1 authentication/v1beta1 authorization/v1beta1 autoscaling/v1 batch/v1 batch/v2alpha1 extensions/v1beta1 apps/v1alpha1 policy/v1alpha1 rbac/v1alpha1 storage/v1beta1 certificates/v1alpha1) +GROUP_VERSIONS=(unversioned ${KUBE_AVAILABLE_GROUP_VERSIONS}) + # To avoid compile errors, remove the currently existing files. for group_version in "${GROUP_VERSIONS[@]}"; do rm -f "pkg/$(kube::util::group-version-to-pkg-path "${group_version}")/types_swagger_doc_generated.go" diff --git a/hack/update-swagger-spec.sh b/hack/update-swagger-spec.sh index 486fbe6de0..bce02a7884 100755 --- a/hack/update-swagger-spec.sh +++ b/hack/update-swagger-spec.sh @@ -73,12 +73,10 @@ APISERVER_PID=$! kube::util::wait_for_url "${API_HOST}:${API_PORT}/healthz" "apiserver: " SWAGGER_API_PATH="${API_HOST}:${API_PORT}/swaggerapi/" -DEFAULT_GROUP_VERSIONS="v1 apps/v1alpha1 authentication.k8s.io/v1beta1 authorization.k8s.io/v1beta1 autoscaling/v1 batch/v1 batch/v2alpha1 extensions/v1beta1 certificates.k8s.io/v1alpha1 policy/v1alpha1 rbac.authorization.k8s.io/v1alpha1 storage.k8s.io/v1beta1" -VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS} kube::log::status "Updating " ${SWAGGER_ROOT_DIR} -SWAGGER_API_PATH="${SWAGGER_API_PATH}" SWAGGER_ROOT_DIR="${SWAGGER_ROOT_DIR}" VERSIONS="${VERSIONS}" kube::util::fetch-swagger-spec +SWAGGER_API_PATH="${SWAGGER_API_PATH}" SWAGGER_ROOT_DIR="${SWAGGER_ROOT_DIR}" VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS}" KUBE_NONSERVER_GROUP_VERSIONS="${KUBE_NONSERVER_GROUP_VERSIONS}" kube::util::fetch-swagger-spec kube::log::status "SUCCESS" diff --git a/pkg/api/testapi/testapi.go b/pkg/api/testapi/testapi.go index f54ff586b5..a1d1d87a63 100644 --- a/pkg/api/testapi/testapi.go +++ b/pkg/api/testapi/testapi.go @@ -115,8 +115,10 @@ func init() { kubeTestAPI := os.Getenv("KUBE_TEST_API") if len(kubeTestAPI) != 0 { + // priority is "first in list preferred", so this has to run in reverse order testGroupVersions := strings.Split(kubeTestAPI, ",") - for _, gvString := range testGroupVersions { + for i := len(testGroupVersions) - 1; i >= 0; i-- { + gvString := testGroupVersions[i] groupVersion, err := unversioned.ParseGroupVersion(gvString) if err != nil { panic(fmt.Sprintf("Error parsing groupversion %v: %v", gvString, err))