Kubernetes integration does not work in gitlab runner image entrypoint
Summary
Kubernetes integration does not work in gitlab runner image entrypoint.
Steps to reproduce
A base image for gitlab runner job that is build from the Dockerfile:
FROM alpine:3.9
RUN apk add --no-cache --virtual .runtime-utils curl bash git make
ENV KUBECTL_VERSION v1.14.2
RUN set -ex \
&& curl -sSL https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl
COPY docker-entrypoint.sh /opt/ci/
ENTRYPOINT ["/opt/ci/docker-entrypoint.sh"]
docker-entrypoint.sh, contains the following script:
#!/usr/bin/env bash
set -euo pipefail
echo "--> kubectl version"
kubectl version
exec "$@"
exit $?
kubectl version shows both local kubectl tool version as well as the server version. To get server version, it connects to the server with credentials that should be prepared by GitLab Kubernetes integration.
.gitlab-ci.yml looks like this:
stages:
- debug
debug:
stage: debug
image: ${CI_IMAGE} # image build from Dockerfile above
script:
- echo "Ok"
environment:
name: dev
This job fails with the message:
# ...
section_start:1559767529:build_script
--> kubectl version
Error loading config file " LS0tLS1CRUdJTiBDRVJUS...
contexts": open LS0tLS1CRUdJTiBDRVJUS...
contexts: file name too long
Error loading config file " [MASKED]
": open [MASKED]
: file name too long
section_end:1559767531:build_script
# ...
It outputs the full Kubernetes CA certificate (I replaced it with LS0tLS1CRUdJTiBDRVJUS... it for brevity).
Note that if we remove kubectl version command from the Docker entrypoint, and put it into the script section to .gitlab-ci.yaml like this:
stages:
- debug
debug:
stage: debug
image: ${CI_IMAGE} # image build from Dockerfile above
script:
- kubectl version
environment:
name: dev
Then everything works just fine (which means Kubernetes integration works fine in this case).
What is the current bug behavior?
Script in Docker entrypoint of the gitlab runner base image is not geting proper kubeconfig to connect to the Kubernetes.
What is the expected correct behavior?
GitLab Kubernetes integration should provide correct kubeconfig to the Docker entrypoint script.
Other info
I'm using hosted gitlab.com.