From e1bdc784a0517ba8faa52185a510397868108398 Mon Sep 17 00:00:00 2001 From: Shyam Jeedigunta Date: Wed, 4 Jul 2018 16:18:50 +0200 Subject: [PATCH 1/2] Unify bazel and makefile modes of build for kubemark --- test/kubemark/common/util.sh | 10 ++--- test/kubemark/start-kubemark.sh | 78 ++++++++++----------------------- 2 files changed, 27 insertions(+), 61 deletions(-) diff --git a/test/kubemark/common/util.sh b/test/kubemark/common/util.sh index 2c7e7c119b8..171397bcbe2 100644 --- a/test/kubemark/common/util.sh +++ b/test/kubemark/common/util.sh @@ -26,19 +26,19 @@ function run-cmd-with-retries { if [[ "${ret_val:-0}" -ne "0" ]]; then if [[ $(echo "${result}" | grep -c "already exists") -gt 0 ]]; then if [[ "${attempt}" == 1 ]]; then - echo -e "${color_red}Failed to $1 $2 $3 as the resource hasn't been deleted from a previous run.${color_norm}" >& 2 + echo -e "${color_red}Failed to $1 $2 ${3:-} as the resource hasn't been deleted from a previous run.${color_norm}" >& 2 exit 1 fi - echo -e "${color_yellow}Succeeded to $1 $2 $3 in the previous attempt, but status response wasn't received.${color_norm}" + echo -e "${color_yellow}Succeeded to $1 $2 ${3:-} in the previous attempt, but status response wasn't received.${color_norm}" return 0 fi - echo -e "${color_yellow}Attempt $attempt failed to $1 $2 $3. Retrying.${color_norm}" >& 2 + echo -e "${color_yellow}Attempt $attempt failed to $1 $2 ${3:-}. Retrying.${color_norm}" >& 2 sleep $(($attempt * 5)) else - echo -e "${color_green}Succeeded to $1 $2 $3.${color_norm}" + echo -e "${color_green}Succeeded to $1 $2 ${3:-}.${color_norm}" return 0 fi done - echo -e "${color_red}Failed to $1 $2 $3.${color_norm}" >& 2 + echo -e "${color_red}Failed to $1 $2 ${3:-}.${color_norm}" >& 2 exit 1 } diff --git a/test/kubemark/start-kubemark.sh b/test/kubemark/start-kubemark.sh index 2062eb4d694..1710bbf7f4b 100755 --- a/test/kubemark/start-kubemark.sh +++ b/test/kubemark/start-kubemark.sh @@ -188,64 +188,34 @@ function start-master-components { echo "The master has started and is now live." } -# Finds the right kubemark binary for 'linux/amd64' platform and uses it to -# create a docker image for hollow-node and upload it to the appropriate -# docker container registry for the cloud provider. +# Create a docker image for hollow-node and upload it to the appropriate docker registry. function create-and-upload-hollow-node-image { - MAKE_DIR="${KUBE_ROOT}/cluster/images/kubemark" - KUBEMARK_BIN="$(kube::util::find-binary-for-platform kubemark linux/amd64)" - if [[ -z "${KUBEMARK_BIN}" ]]; then - echo 'Cannot find cmd/kubemark binary' - exit 1 - fi - echo "Configuring registry authentication" mkdir -p "${HOME}/.docker" gcloud beta auth configure-docker -q - echo "Copying kubemark binary to ${MAKE_DIR}" - cp "${KUBEMARK_BIN}" "${MAKE_DIR}" - CURR_DIR=`pwd` - cd "${MAKE_DIR}" - RETRIES=3 KUBEMARK_IMAGE_REGISTRY="${KUBEMARK_IMAGE_REGISTRY:-${CONTAINER_REGISTRY}/${PROJECT}}" - for attempt in $(seq 1 ${RETRIES}); do - if ! REGISTRY="${KUBEMARK_IMAGE_REGISTRY}" IMAGE_TAG="${KUBEMARK_IMAGE_TAG}" make "${KUBEMARK_IMAGE_MAKE_TARGET}"; then - if [[ $((attempt)) -eq "${RETRIES}" ]]; then - echo "${color_red}Make failed. Exiting.${color_norm}" - exit 1 - fi - echo -e "${color_yellow}Make attempt $(($attempt)) failed. Retrying.${color_norm}" >& 2 - sleep $(($attempt * 5)) - else - break + if [[ "${KUBEMARK_BAZEL_BUILD:-}" =~ ^[yY]$ ]]; then + # Build+push the image through bazel. + build_cmd=("bazel" "run" "//cluster/images/kubemark:push" "--define" "REGISTRY=${KUBEMARK_IMAGE_REGISTRY}" "--define" "IMAGE_TAG=${KUBEMARK_IMAGE_TAG}") + run-cmd-with-retries "${build_cmd[@]}" + else + # Build+push the image through makefile. + build_cmd=("make" "${KUBEMARK_IMAGE_MAKE_TARGET}") + MAKE_DIR="${KUBE_ROOT}/cluster/images/kubemark" + KUBEMARK_BIN="$(kube::util::find-binary-for-platform kubemark linux/amd64)" + if [[ -z "${KUBEMARK_BIN}" ]]; then + echo 'Cannot find cmd/kubemark binary' + exit 1 fi - done - rm kubemark - cd $CURR_DIR - echo "Created and uploaded the kubemark hollow-node image to docker registry." -} - -# Use bazel rule to create a docker image for hollow-node and upload -# it to the appropriate docker container registry for the cloud provider. -function create-and-upload-hollow-node-image-bazel { - echo "Configuring registry authentication" - mkdir -p "${HOME}/.docker" - gcloud beta auth configure-docker -q - - RETRIES=3 - for attempt in $(seq 1 ${RETRIES}); do - if ! bazel run //cluster/images/kubemark:push --define REGISTRY="${KUBEMARK_IMAGE_REGISTRY}" --define IMAGE_TAG="${KUBEMARK_IMAGE_TAG}"; then - if [[ $((attempt)) -eq "${RETRIES}" ]]; then - echo "${color_red}Image push failed. Exiting.${color_norm}" - exit 1 - fi - echo -e "${color_yellow}Make attempt $(($attempt)) failed. Retrying.${color_norm}" >& 2 - sleep $(($attempt * 5)) - else - break - fi - done + echo "Copying kubemark binary to ${MAKE_DIR}" + cp "${KUBEMARK_BIN}" "${MAKE_DIR}" + CURR_DIR=`pwd` + cd "${MAKE_DIR}" + REGISTRY=${KUBEMARK_IMAGE_REGISTRY} IMAGE_TAG=${KUBEMARK_IMAGE_TAG} run-cmd-with-retries "${build_cmd[@]}" + rm kubemark + cd $CURR_DIR + fi echo "Created and uploaded the kubemark hollow-node image to docker registry." } @@ -500,11 +470,7 @@ start-master-components # Setup for hollow-nodes. echo "" echo -e "${color_yellow}STARTING SETUP FOR HOLLOW-NODES${color_norm}" -if [[ "${KUBEMARK_BAZEL_BUILD:-}" =~ ^[yY]$ ]]; then - create-and-upload-hollow-node-image-bazel -else - create-and-upload-hollow-node-image -fi +create-and-upload-hollow-node-image create-kube-hollow-node-resources wait-for-hollow-nodes-to-run-or-timeout From 69090f0ad27151931d764a486362f613db15a60f Mon Sep 17 00:00:00 2001 From: Shyam Jeedigunta Date: Wed, 4 Jul 2018 16:27:22 +0200 Subject: [PATCH 2/2] Make docker authentication in kubemark provider-independent --- test/kubemark/gce/util.sh | 6 ++++++ test/kubemark/skeleton/util.sh | 6 ++++++ test/kubemark/start-kubemark.sh | 5 +---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/kubemark/gce/util.sh b/test/kubemark/gce/util.sh index 398913779c8..e6a7c9c95ab 100644 --- a/test/kubemark/gce/util.sh +++ b/test/kubemark/gce/util.sh @@ -25,6 +25,12 @@ function run-gcloud-compute-with-retries { run-cmd-with-retries gcloud compute "$@" } +function authenticate-docker { + echo "Configuring registry authentication" + mkdir -p "${HOME}/.docker" + gcloud beta auth configure-docker -q +} + function create-master-instance-with-resources { GCLOUD_COMMON_ARGS="--project ${PROJECT} --zone ${ZONE}" diff --git a/test/kubemark/skeleton/util.sh b/test/kubemark/skeleton/util.sh index d646b3d9f25..fdd0c1c2936 100644 --- a/test/kubemark/skeleton/util.sh +++ b/test/kubemark/skeleton/util.sh @@ -18,6 +18,12 @@ # Kubermark must implement to use test/kubemark/start-kubemark.sh and # test/kubemark/stop-kubemark.sh scripts. +# This function should authenticate docker to be able to read/write to +# the right container registry (needed for pushing kubemark image). +function authenticate-docker { + echo "Configuring registry authentication" 1>&2 +} + # This function should create a machine instance for the master along # with any/all of the following resources: # - Attach a PD to the master (optionally 1 more for storing events) diff --git a/test/kubemark/start-kubemark.sh b/test/kubemark/start-kubemark.sh index 1710bbf7f4b..0c794ae37be 100755 --- a/test/kubemark/start-kubemark.sh +++ b/test/kubemark/start-kubemark.sh @@ -190,10 +190,7 @@ function start-master-components { # Create a docker image for hollow-node and upload it to the appropriate docker registry. function create-and-upload-hollow-node-image { - echo "Configuring registry authentication" - mkdir -p "${HOME}/.docker" - gcloud beta auth configure-docker -q - + authenticate-docker KUBEMARK_IMAGE_REGISTRY="${KUBEMARK_IMAGE_REGISTRY:-${CONTAINER_REGISTRY}/${PROJECT}}" if [[ "${KUBEMARK_BAZEL_BUILD:-}" =~ ^[yY]$ ]]; then # Build+push the image through bazel.