Skip to content

Commit

Permalink
Provide a non-racey way to log into OpenShift cluster
Browse files Browse the repository at this point in the history
Concurrent login attempts were being throttled so now we ensure that we
don't invoke this too many times at the same moment.
  • Loading branch information
sgnn7 committed May 14, 2019
1 parent 2ddcae8 commit dec7f67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
4 changes: 3 additions & 1 deletion 1_create_test_app_namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ set -euo pipefail
announce "Creating Test App namespace."

if [[ $PLATFORM == openshift ]]; then
oc login -u $OSHIFT_CLUSTER_ADMIN_USERNAME
if [[ "$(oc whoami)" != "$OSHIFT_CLUSTER_ADMIN_USERNAME" ]]; then
oc login -u $OSHIFT_CLUSTER_ADMIN_USERNAME
fi
fi

set_namespace default
Expand Down
31 changes: 25 additions & 6 deletions ci/platform_login
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ IFS=$'\n\t'
function main() {
# Log in to platform
if [[ "$PLATFORM" = "kubernetes" ]]; then

gcloud auth activate-service-account \
--key-file $GCLOUD_SERVICE_KEY
gcloud container clusters get-credentials \
Expand All @@ -15,14 +16,32 @@ function main() {
docker login $DOCKER_REGISTRY_URL \
-u oauth2accesstoken \
-p "$(gcloud auth print-access-token)"

elif [[ "$PLATFORM" = "openshift" ]]; then
echo "Logging into OpenShift..."
oc login $OPENSHIFT_URL \
--username=$OPENSHIFT_USERNAME \
--password=$OPENSHIFT_PASSWORD \
--insecure-skip-tls-verify=true
docker login \
-u _ -p "$(oc whoami -t)" \
$DOCKER_REGISTRY_PATH
--username=$OPENSHIFT_USERNAME \
--password=$OPENSHIFT_PASSWORD \
--insecure-skip-tls-verify=true
echo "Logged into OpenShift"

echo "Logging into OpenShift Docker registry..."
retry_attempt=0
while ! docker login -u _ \
-p "$(oc whoami -t)" \
"$DOCKER_REGISTRY_PATH"; do
echo "Failed to login to $DOCKER_REGISTRY_PATH registry!"

retry_attempt=$(( $retry_attempt + 1 ))
if [[ $retry_attempt -gt 10 ]]; then
echo "ERROR: Was unable to login to OpenShift Docker registry after 10 attempts!"
exit 1
fi

sleep 2
echo "Retrying login..."
done
echo "Logged into OpenShift Docker registry"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions stop
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ set -euo pipefail

. utils.sh

set_namespace default

if [[ $PLATFORM == openshift ]]; then
oc login -u $OSHIFT_CLUSTER_ADMIN_USERNAME
if [[ "$(oc whoami)" != "$OSHIFT_CLUSTER_ADMIN_USERNAME" ]]; then
oc login -u $OSHIFT_CLUSTER_ADMIN_USERNAME
fi
fi

if has_namespace $TEST_APP_NAMESPACE_NAME; then
Expand Down

0 comments on commit dec7f67

Please sign in to comment.