Skip to content

Commit

Permalink
Set KUBECONFIG to the $HOME/.kube/config if missing
Browse files Browse the repository at this point in the history
To support root or non-root docker invocations, set the KUBECONFIG
specifically to the passed .kube dir. The reason is that 'oc' incovation
as root is by default looking for the .kube dir uner
`/root/.kube/config` where as non-root is looking at $HOME/.kube/config.

With this we always set KUBECONFIG, so root invocation of `oc` commands
will always find the passed in config.

Fixes: ansibleplaybookbundle#298

Signed-off-by: Roy Golan <[email protected]>
  • Loading branch information
rgolangh committed Jul 23, 2018
1 parent 585694b commit 7606e0d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/apb-docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if ! [[ -z "${DOCKER_CERT_PATH}" ]] && [[ ${DOCKER_CERT_PATH} = *"minishift"* ]]
fi

KUBECONFIG_ENV="${KUBECONFIG:+-v ${KUBECONFIG}:${KUBECONFIG} -e KUBECONFIG=${KUBECONFIG}}"
[[ -z $KUBECONFIG ]] && KUBECONFIG_ENV="${KUBECONFIG:--v $HOME/.kube:/.kube -e KUBECONFIG=/.kube/config}"

if [[ $IS_MINISHIFT = true ]]; then
# If targetting minishift, there are some unique issues with using the apb
Expand All @@ -36,7 +37,7 @@ if [[ $IS_MINISHIFT = true ]]; then
unset DOCKER_CERT_PATH

docker run --rm --privileged \
-v $PWD:/mnt -v $HOME/.kube:/.kube \
-v $PWD:/mnt \
-v $MINISHIFT_DOCKER_CERT_SRC:$MINISHIFT_DOCKER_CERT_DEST \
-e DOCKER_TLS_VERIFY="1" \
-e DOCKER_HOST="${MINISHIFT_DOCKER_HOST}" \
Expand All @@ -46,7 +47,7 @@ if [[ $IS_MINISHIFT = true ]]; then
-u $UID $APB_IMAGE "$@"
else
docker run --rm --privileged \
-v $PWD:/mnt -v $HOME/.kube:/.kube \
-v $PWD:/mnt \
-v /var/run/docker.sock:/var/run/docker.sock \
${KUBECONFIG_ENV} \
-u $UID $APB_IMAGE "$@"
Expand Down

0 comments on commit 7606e0d

Please sign in to comment.