Skip to content

Commit

Permalink
Automated Config Connector import.
Browse files Browse the repository at this point in the history
  - 6d3f51d2a8253079787a628613f639ab7ecbec5b Move retry script into hack by Config Connector Team <[email protected]>
  - 33c1191e42d961b79c4d2043b80f7d48d44092c4 Add docker-build / docker-push to operator Makefile by Config Connector Team <[email protected]>
  - fad6aa89ca67813c61179fb45303a1c23b0d0252 More github makefiles to root, internal makefiles to inte... by Config Connector Team <[email protected]>
  - f57fd36fc4e8ff0c20fb3e63a83ed3dbfb192701 Move more excluded scripts under google-internal by Config Connector Team <[email protected]>

GitOrigin-RevId: 6d3f51d2a8253079787a628613f639ab7ecbec5b
  • Loading branch information
Config Connector Team authored and copybara-github committed Sep 14, 2023
1 parent 262f90a commit 691a8c8
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 7 deletions.
81 changes: 81 additions & 0 deletions hack/retry
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# Copyright 2022 Google LLC
#
# 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

COMMAND_TO_RUN=""
MAX_RETRIES=10
SLEEP_SECONDS=5
SUCCESS_REGEX=""

while [[ $# -gt 0 ]]; do
case "${1}" in
# The number of seconds to wait after a failed command before retrying, default 5, example:
# --sleep-seconds 15
--sleep-seconds) SLEEP_SECONDS="${2:-}"; shift ;;
# The maximum number of times to try the command, default 10, example
# --max-retries 3
--max-retries) MAX_RETRIES="${2:-}"; shift ;;
# The command to retry, example
# --command 'gcloud projects add-iam-policy-binding my-project-id --member "user:[email protected]" --role "roles/owner"'
--command) COMMAND_TO_RUN="${2:-}"; shift ;;
# if the stdout / stderr of the command matches the success-regex, then the command will be considered a success,
# regardless of the exit code. This is to help handle ill-behaving CLIs that don't provide granular exit
# codes which indicate success.
--success-regex) SUCCESS_REGEX="${2:-}"; shift;;
*) echo "Unrecognized command line parameter: $1"; exit 1 ;;
esac
shift
done

if [[ "${COMMAND_TO_RUN}" == "" ]]; then
echo "The --command parameter is required"
exit 1
fi

RETRY_NUM=1
RESULT=0

for (( RETRY_NUM=1; RETRY_NUM<=${MAX_RETRIES}; RETRY_NUM++ ))
do
TEST_FILE=$(mktemp)
trap "rm -f $TEST_FILE" EXIT
echo "Attempt ${RETRY_NUM}/${MAX_RETRIES} of '${COMMAND_TO_RUN}'..."
if eval "${COMMAND_TO_RUN} &> $TEST_FILE"; then
echo "Succeeded."
exit $?
else
RESULT=$?
OUTPUT=$(cat "${TEST_FILE}")
if [[ "${SUCCESS_REGEX}" != "" ]] && echo "${OUTPUT}" | grep -q "${SUCCESS_REGEX}"; then
echo "Succeeded, since output \"$OUTPUT\" matched regex \"${SUCCESS_REGEX}\""
exit 0
else
echo "Failed with exit code ${RESULT} and output ${OUTPUT}"
if [[ ${RETRY_NUM} -lt ${MAX_RETRIES} ]]; then
sleep "${SLEEP_SECONDS}"
# Some backoff
sleep "${RETRY_NUM}"
# Some randomization
sleep $((RANDOM % 10))
fi
fi
fi
done

echo "FAIL: The command '${COMMAND_TO_RUN}' failed ${MAX_RETRIES} times"
exit ${RESULT}
21 changes: 21 additions & 0 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECT_ID := $(shell gcloud config get-value project)
SHORT_SHA := $(shell git rev-parse --short=7 HEAD)
OPERATOR_IMG ?= gcr.io/${PROJECT_ID}/cnrm/operator:${SHORT_SHA}

# enable multi-versions feature for CRDs
CRD_OPTIONS ?= "crd"

Expand Down Expand Up @@ -67,3 +71,20 @@ controller-gen:
ifneq (Version: v$(CONTROLLER_GEN_VERSION), $(shell $(CONTROLLER_GEN) --version))
GOFLAGS='' go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_GEN_VERSION)
endif


# Build the docker image
.PHONY: docker-build
docker-build:
docker build .. -f Dockerfile -t ${OPERATOR_IMG}
@echo "updating kustomize image patch file for manager"
cp config/manager/manager_image_patch_template.yaml config/manager/manager_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${OPERATOR_IMG}"'@' config/manager/manager_image_patch.yaml
cp -f config/autopilot-manager/manager_image_patch_template.yaml config/autopilot-manager/manager_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${OPERATOR_IMG}"'@' config/autopilot-manager/manager_image_patch.yaml


# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${OPERATOR_IMG}
6 changes: 4 additions & 2 deletions operator/scripts/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
set -o errexit
set -o nounset
set -o pipefail
OPERATOR_SRC_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${OPERATOR_SRC_ROOT}"

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd ${REPO_ROOT}/operator

make manager
make docker-build
6 changes: 4 additions & 2 deletions operator/scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
set -o errexit
set -o nounset
set -o pipefail
OPERATOR_SRC_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${OPERATOR_SRC_ROOT}"

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd ${REPO_ROOT}/operator

source ./scripts/fetch_ext_bins.sh && \
fetch_tools && \
setup_envs
Expand Down
4 changes: 1 addition & 3 deletions scripts/shared-vars-public.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@


# Paths
SCRIPT_DIR=$(dirname "${BASH_SOURCE}")
REPO_ROOT=$(cd ${SCRIPT_DIR}/..; pwd)
RETRY_CMD=${SCRIPT_DIR}/retry.sh
REPO_ROOT="$(git rev-parse --show-toplevel)"

# general purpose folders
BIN_DIR=bin
Expand Down

0 comments on commit 691a8c8

Please sign in to comment.