diff --git a/Makefile.core.mk b/Makefile.core.mk index b3219ddb13..f8cd0936e1 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -14,7 +14,7 @@ GOPATH ?= $(shell cd ${ISTIOIO_GO}/../../..; pwd) export GOPATH # Set the directory for Istio source. -ISTIO_GO ?= ${GOPATH}/src/istio.io/istio +ISTIO_GO ?= $(GOPATH)/src/istio.io/istio export ISTIO_GO # If GOPATH is made up of several paths, use the first one for our targets in this Makefile diff --git a/bin/init.sh b/bin/init.sh index 288a4a3de1..4d0e996f2c 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -18,29 +18,62 @@ set -o errexit set -o nounset set -o pipefail +export ISTIO_REMOTE=${ISTIO_REMOTE:-origin} export ISTIO_BRANCH=${ISTIO_BRANCH:-master} echo "ISTIOIO_GO=${ISTIOIO_GO}" echo "ISTIO_GO=${ISTIO_GO}" +echo "ISTIO_REMOTE=${ISTIO_REMOTE}" echo "ISTIO_BRANCH=${ISTIO_BRANCH}" # Download the Istio source if not available. -if [[ ! -d "${ISTIO_GO}" ]] +if [[ -d "${ISTIO_GO}" ]] then - git clone https://github.com/istio/istio.git "${ISTIO_GO}" + echo "${ISTIO_GO} already exists. Using existing repository ..." +else + echo "${ISTIO_GO} not found. Cloning Istio repository ..." + git clone https://github.com/istio/istio.git "${ISTIO_GO}" +fi + +pushd "${ISTIO_GO}" > /dev/null + +REMOTE_BRANCH="${ISTIO_REMOTE}/${ISTIO_BRANCH}" + +# Switch to latest for requested branch if possible +if [ -z "$(git status --porcelain)" ]; then + # Get updates to the remote repository + git fetch "$ISTIO_REMOTE" + + # Switch to the desired local branch (create if necessary) + git checkout -B "${ISTIO_BRANCH}" + + LOCAL_REV=$(git rev-parse @) + REMOTE_REV=$(git rev-parse "${REMOTE_BRANCH}") + BASE_REV=$(git merge-base @ "${REMOTE_BRANCH}") + + if [[ "${LOCAL_REV}" == "${REMOTE_REV}" ]]; then + echo "Istio already up-to-date with ${REMOTE_BRANCH}" + elif [[ "${LOCAL_REV}" == "${BASE_REV}" ]]; then + echo "WARNING: Istio is out-of-date with ${REMOTE_BRANCH}. Merging remote changes." + git pull "${ISTIO_REMOTE}" "${ISTIO_BRANCH}" + elif [[ "${REMOTE_REV}" == "${BASE_REV}" ]]; then + echo "WARNING: Istio is ahead of ${REMOTE_BRANCH}. Using local branch." + else + echo "WARNING: Istio has diverged with ${REMOTE_BRANCH}. Using local branch." + fi + +else + echo "WARNING: Istio has uncommitted changes. To use latest from ${REMOTE_BRANCH} clear your local changes." fi # Build and install istioctl -pushd "${ISTIO_GO}" -git checkout "${ISTIO_BRANCH}" go install ./istioctl/cmd/istioctl -popd + +popd > /dev/null # Copy install/samples files over from Istio. These are needed by the tests. -rm -rf "${ISTIOIO_GO}/install" +rm -rf "${ISTIOIO_GO}/install" "${ISTIOIO_GO}/samples" cp -a "${ISTIO_GO}/install" "${ISTIOIO_GO}/install" - -rm -rf "${ISTIOIO_GO}/samples" cp -a "${ISTIO_GO}/samples" "${ISTIOIO_GO}/samples" # For generating junit.xml files diff --git a/tests/tests.mk b/tests/tests.mk index 7d4002b5e0..f548108b9f 100644 --- a/tests/tests.mk +++ b/tests/tests.mk @@ -31,11 +31,8 @@ endif # $(INTEGRATION_TEST_KUBECONFIG) specifies the kube config file to be used. If not specified, then # ~/.kube/config is used. # TODO: This probably needs to be more intelligent and take environment variables into account. -ifneq ($(KUBECONFIG),) - _INTEGRATION_TEST_FLAGS += --istio.test.kube.config=$(KUBECONFIG) -else - _INTEGRATION_TEST_FLAGS += --istio.test.kube.config=~/.kube/config -endif +KUBECONFIG ?= ~/.kube/config +_INTEGRATION_TEST_FLAGS += --istio.test.kube.config=$(KUBECONFIG) test.kube.presubmit: init PATH=${PATH}:${ISTIO_OUT} $(GO) test -p 1 ${T} ./tests/... -timeout 30m \