#!/bin/bash # Copyright 2014 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit set -o nounset set -o pipefail global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/../.." source "$(KUBE_ROOT)/hack/lib/init.sh" # Lists of API Versions of each groups that should be tested, groups are # separated by comma, lists are separated by semicolon. e.g., # "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3" # TODO: It's going to be: # 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. global ALL_VERSIONS_CSV := $[global IFS := '','';echo $(KUBE_AVAILABLE_GROUP_VERSIONS[*]// /,);global IFS := '$'] global 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 #KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 240s} global KUBE_TIMEOUT := '"-timeout 600s'" global KUBE_INTEGRATION_TEST_MAX_CONCURRENCY := $(KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1") global LOG_LEVEL := $(LOG_LEVEL:-2) global KUBE_TEST_ARGS := $(KUBE_TEST_ARGS:-) # Default glog module settings. global KUBE_TEST_VMODULE := $(KUBE_TEST_VMODULE:-"garbagecollector*=6,graph_builder*=6") proc kube::test::find_integration_test_dirs { shell { cd $(KUBE_ROOT) find test/integration/ -name '*_test.go' -print0 \ | xargs -0n1 dirname | sed "s|^|$(KUBE_GO_PACKAGE)/|" \ | env LC_ALL=C sort -u find vendor/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \ | xargs -0n1 dirname | sed "s|^|$(KUBE_GO_PACKAGE)/|" \ | env LC_ALL=C sort -u find federation/test/integration/ -name '*_test.go' -print0 \ | xargs -0n1 dirname | sed "s|^|$(KUBE_GO_PACKAGE)/|" \ | env LC_ALL=C sort -u } } global CLEANUP_REQUIRED := '' proc cleanup { if [[ -z "${CLEANUP_REQUIRED}" ]] { return } kube::log::status "Cleaning up etcd" kube::etcd::cleanup global CLEANUP_REQUIRED := '' kube::log::status "Integration test cleanup complete" } proc runTests { kube::log::status "Starting etcd instance" global CLEANUP_REQUIRED := '1' kube::etcd::start kube::log::status "Running integration test cases" global KUBE_RACE := '"-race'" make -C $(KUBE_ROOT) test \ WHAT="$(WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -))" \ GOFLAGS="$(GOFLAGS:-)" \ KUBE_TEST_ARGS="$(KUBE_TEST_ARGS:-) $(SHORT:--short=true) --vmodule=$(KUBE_TEST_VMODULE) --alsologtostderr=true" \ KUBE_RACE="" \ KUBE_TIMEOUT="$(KUBE_TIMEOUT)" \ KUBE_TEST_API_VERSIONS="$1" cleanup } proc checkEtcdOnPath { kube::log::status "Checking etcd is on PATH" which etcd && return kube::log::status "Cannot find etcd, cannot run integration tests." kube::log::status "Please see https://github.com/kubernetes/community/blob/master/contributors/devel/testing.md#install-etcd-dependency for instructions." kube::log::usage "You can use 'hack/install-etcd.sh' to install a copy in third_party/." return 1 } checkEtcdOnPath # Run cleanup to stop etcd on interrupt or other kill signal. trap cleanup EXIT # If a test case is specified, just run once with v1 API version and exit if [[ -n "${KUBE_TEST_ARGS}" ]] { runTests v1 exit 0 } # Convert the CSV to an array of API versions to test env IFS=';' read -a apiVersions <<< $(KUBE_TEST_API_VERSIONS) for apiVersion in [$(apiVersions[@])] { runTests $(apiVersion) } (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [64 72] ) (/../..) } spids: [63] ) ] spids: [63] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/init.sh))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ALL_VERSIONS_CSV) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:IFS) op: Equal rhs: {(SQ <",">)} spids: [107] ) ] spids: [107] ) terminator: ) (Sentence child: (C {(echo)} { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Arith_Star) suffix_op: (PatSub pat: {(" ")} replace: {(",")} do_all: True do_prefix: False do_suffix: False ) spids: [115 125] ) ) } ) terminator: ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:IFS) op: Equal rhs: {(Lit_Other "$")} spids: [128] ) ] spids: [128] ) ] ) left_token: spids: [106 130] ) } spids: [105] ) ] spids: [105] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_TEST_API_VERSIONS) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(${ VSub_Name ALL_VERSIONS_CSV)} ) spids: [134 140] ) ) } spids: [132] ) ] spids: [132] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_TIMEOUT) op: Equal rhs: {(DQ ("-timeout 600s"))} spids: [153] ) ] spids: [153] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_INTEGRATION_TEST_MAX_CONCURRENCY) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(DQ (-1))}) spids: [159 165] ) } spids: [158] ) ] spids: [158] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LOG_LEVEL) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(2)}) spids: [168 172] ) } spids: [167] ) ] spids: [167] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_TEST_ARGS) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{}) spids: [175 178] ) } spids: [174] ) ] spids: [174] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_TEST_VMODULE) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(DQ ("garbagecollector*=6,graph_builder*=6"))} ) spids: [184 190] ) } spids: [183] ) ] spids: [183] ) (FuncDef name: "kube::test::find_integration_test_dirs" body: (BraceGroup children: [ (Subshell child: (CommandList children: [ (C {(cd)} {(${ VSub_Name KUBE_ROOT)}) (Pipeline children: [ (C {(find)} {(test/integration/)} {(-name)} {(SQ <"*_test.go">)} {(-print0)}) (C {(xargs)} {(-0n1)} {(dirname)}) (C {(sed)} {(DQ ("s|^|") (${ VSub_Name KUBE_GO_PACKAGE) ("/|"))}) (SimpleCommand words: [{(sort)} {(-u)}] more_env: [(env_pair name:LC_ALL val:{(C)} spids:[254])] ) ] negated: False ) (Pipeline children: [ (C {(find)} {(vendor/k8s.io/apiextensions-apiserver/test/integration/)} {(-name)} {(SQ <"*_test.go">)} {(-print0)} ) (C {(xargs)} {(-0n1)} {(dirname)}) (C {(sed)} {(DQ ("s|^|") (${ VSub_Name KUBE_GO_PACKAGE) ("/|"))}) (SimpleCommand words: [{(sort)} {(-u)}] more_env: [(env_pair name:LC_ALL val:{(C)} spids:[300])] ) ] negated: False ) (Pipeline children: [ (C {(find)} {(federation/test/integration/)} {(-name)} {(SQ <"*_test.go">)} {(-print0)} ) (C {(xargs)} {(-0n1)} {(dirname)}) (C {(sed)} {(DQ ("s|^|") (${ VSub_Name KUBE_GO_PACKAGE) ("/|"))}) (SimpleCommand words: [{(sort)} {(-u)}] more_env: [(env_pair name:LC_ALL val:{(C)} spids:[346])] ) ] negated: False ) ] ) spids: [206 354] ) ] spids: [203] ) spids: [193 202] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:CLEANUP_REQUIRED) op:Equal rhs:{(SQ )} spids:[359])] spids: [359] ) (FuncDef name: cleanup body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: {(DQ (${ VSub_Name CLEANUP_REQUIRED))} ) ) terminator: ) ] action: [(ControlFlow token:)] spids: [-1 383] ) ] spids: [-1 389] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Cleaning up etcd"))} ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (etcd) (Lit_Other ":") (Lit_Other ":") (cleanup)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLEANUP_REQUIRED) op: Equal rhs: {(SQ )} spids: [414] ) ] spids: [414] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Integration test cleanup complete"))} ) ] spids: [365] ) spids: [361 364] ) (FuncDef name: runTests body: (BraceGroup children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Starting etcd instance"))} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLEANUP_REQUIRED) op: Equal rhs: {(1)} spids: [452] ) ] spids: [452] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (etcd) (Lit_Other ":") (Lit_Other ":") (start)}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Running integration test cases"))} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_RACE) op: Equal rhs: {(DQ (-race))} spids: [479] ) ] spids: [479] ) (C {(make)} {(-C)} {(DQ (${ VSub_Name KUBE_ROOT))} {(test)} {(Lit_VarLike "WHAT=") (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (test) (Lit_Other ":") (Lit_Other ":") (find_integration_test_dirs) } ) (C {(paste)} {(-sd) (SQ <" ">)} {(-)}) ] negated: False ) ] ) left_token: spids: [504 523] ) } ) spids: [501 524] ) ) } {(Lit_VarLike "GOFLAGS=") (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [531 534] ) ) } {(Lit_VarLike "KUBE_TEST_ARGS=") (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [541 544] ) (" ") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{("-short=true")}) spids: [546 550] ) (" --vmodule=") (${ VSub_Name KUBE_TEST_VMODULE) (" --alsologtostderr=true") ) } {(Lit_VarLike "KUBE_RACE=") (DQ )} {(Lit_VarLike "KUBE_TIMEOUT=") (DQ (${ VSub_Name KUBE_TIMEOUT))} {(Lit_VarLike "KUBE_TEST_API_VERSIONS=") (DQ ($ VSub_Number "$1"))} ) (C {(cleanup)}) ] spids: [436] ) spids: [432 435] ) (FuncDef name: checkEtcdOnPath body: (BraceGroup children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Checking etcd is on PATH"))} ) (AndOr children: [(C {(which)} {(etcd)}) (ControlFlow token:)] op_id: Op_DAmp ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} {(DQ ("Cannot find etcd, cannot run integration tests."))} ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (status)} { (DQ ( "Please see https://github.com/kubernetes/community/blob/master/contributors/devel/testing.md#install-etcd-dependency for instructions." ) ) } ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (usage)} {(DQ ("You can use 'hack/install-etcd.sh' to install a copy in third_party/."))} ) (ControlFlow token: arg_word:{(1)}) ] spids: [591] ) spids: [587 590] ) (C {(checkEtcdOnPath)}) (C {(trap)} {(cleanup)} {(EXIT)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_n child:{(DQ (${ VSub_Name KUBE_TEST_ARGS))}) ) terminator: ) ] action: [(C {(runTests)} {(v1)}) (C {(exit)} {(0)})] spids: [-1 693] ) ] spids: [-1 705] ) (SimpleCommand words: [{(read)} {(-a)} {(apiVersions)}] redirects: [ (Redir op_id: Redir_TLess fd: -1 arg_word: {(DQ (${ VSub_Name KUBE_TEST_API_VERSIONS))} spids: [722] ) ] more_env: [(env_pair name:IFS val:{(SQ <";">)} spids:[711])] ) (ForEach iter_name: apiVersion iter_words: [ { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [737 742] ) ) } ] do_arg_iter: False body: (DoGroup children:[(C {(runTests)} {(DQ (${ VSub_Name apiVersion))})] spids:[746757]) spids: [735 744] ) ] )