Different Kubernetes ENV variables depending on type of trigger
Summary
Seems that GitLab sets different ENV variables for Kubernetes depending on the trigger. For example for merge_requests
the following ENV variables can be found:
- KUBE_URL
- KUBE_CA_PEM
- KUBE_TOKEN
- KUBE_CONFIG
These variables are missing if the trigger is set to specific branch
Steps to reproduce
Create two jobs with similar parameters, set different triggers and print ENV variables, after that compare them with diff
deploy:
image: ubuntu:latest
tags:
- "kubernetes"
stage: deploy
only:
- master
script:
- env
- kubectl version
deploy-preview_env:
image: ubuntu:latest
tags:
- "kubernetes"
stage: deploy
only:
- merge_requests
script:
- env
- kubectl version
environment:
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_preview_env
url: https://$CI_ENVIRONMENT_SLUG.example.com
What is the current bug behavior?
With trigger merge_requests
it sets the ENV variable KUBE_URL
which seems to be wrong. The IP address assign to this variable do not have anything in common with some of the IPs in the Kubernetes Cluster. Because of that any interactions with the API are impossible.
What is the expected correct behavior?
I suppose that the correct behaviour should be to not set KUBE_URL
as if this variable is not set everything is working perfect.
Relevant logs and/or screenshots
$ helm upgrade --install app-$CI_ENVIRONMENT_SLUG --namespace app-$CI_ENVIRONMENT_SLUG chartmuseum/app
Error: Get https://35.193.88.144/api/v1/namespaces/kube-system/pods?labelSelector=app%3Dhelm%2Cname%3Dtiller: dial tcp 35.193.88.144:443: i/o timeout
Output of checks
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Results of GitLab environment info
ENV Variables from build
CI_COMMIT_SHORT_SHA=70d96f9b
CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
CI_COMMIT_TITLE=adding debug for network issue
CI_JOB_TOKEN=[MASKED]
KUBE_CA_PEM_FILE=/builds/app/app.tmp/KUBE_CA_PEM_FILE
CI_BUILD_REF_NAME=ci-cd-mr
CI_REGISTRY_PASSWORD=[MASKED]
CI_RUNNER_TAGS=kubernetes
CI_PIPELINE_URL=https://private.gitlab/app/pipelines/13569
CI_MERGE_REQUEST_ID=10689
CI_JOB_NAME=deploy-app-preview_env
GITLAB_TOKEN=
CI_MERGE_REQUEST_SOURCE_PROJECT_PATH=project/app
CI_COMMIT_REF_PROTECTED=false
CI_SERVER_VERSION=12.2.5
CI_PAGES_DOMAIN=example.com
GITLAB_CI=true
CI_SERVER_REVISION=09f8edbc29a
HOSTNAME=runner-0bvghz
CI_PROJECT_VISIBILITY=private
OLDPWD=/
CI_DISPOSABLE_ENVIRONMENT=true
KUBECONFIG=/builds/project/app.tmp/KUBECONFIG
SSH_PRIVATE_KEY=
CI_SERVER_HOST=private.gitlab
CI_COMMIT_SHA=70d96f9b54d6444aae903dff0a676c7a5e3d0929
CI_MERGE_REQUEST_TITLE=adding helm install and destroy
MAIL_IMAGE_TAG=private.gitlab/project/app/sub-app:branch
CI_COMMIT_MESSAGE=adding debug for network issue
FF_USE_LEGACY_VOLUMES_MOUNTING_ORDER=false
CI_BUILD_STAGE=deploy
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=ci-cd-mr
KUBE_TOKEN=[MASKED]
CI_PROJECT_URL=https://private.gitlab/project/app
CI_COMMIT_REF_SLUG=ci-cd-mr
CI_SERVER_NAME=GitLab
CI_RUNNER_VERSION=12.2.0
CI_BUILD_NAME=deploy-app-preview_env
KUBERNETES_PORT_443_TCP_PROTO=tcp
CI=true
KUBERNETES_PORT_443_TCP_ADDR=10.233.0.1
API_IMAGE_TAG=private.gitlab/project/app/api:ci-cd-mr
FE_IMAGE=private.gitlab/project/app/frontend
CI_REGISTRY_USER=gitlab-ci-toke
MAIL_DEPS_TAG=private.gitlab/project/app/mail:deps
CI_PROJECT_ID=339
CI_PIPELINE_ID=13569
CI_MERGE_REQUEST_REF_PATH=refs/merge-requests/581/head
CI_MERGE_REQUEST_TARGET_BRANCH_NAME=ci-cd
CI_JOB_URL=https://private.gitlab/project/app/-/jobs/36032
KUBERNETES_PORT=tcp://10.233.0.1:443
CI_COMMIT_DESCRIPTION=
FE_RELEASE=private.gitlab/project/app/frontend:
PWD=/builds/project/app
GITLAB_FEATURES=
FF_CMD_DISABLE_DELAYED_ERROR_LEVEL_EXPANSION=false
HOME=/root
CI_CONCURRENT_ID=0
MAIL_IMAGE=private.gitlab/project/app/mail
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA=
CI_REGISTRY=private.gitlab
CI_BUILD_TOKEN=[MASKED]
HELM_REPO_PASSWORD=
CI_MERGE_REQUEST_TARGET_BRANCH_SHA=
CI_BUILD_ID=36032
GITLAB_USER_NAME=Valeri Rangelov
CI_COMMIT_BEFORE_SHA=0000000000000000000000000000000000000000
CI_PROJECT_PATH_SLUG=project-app
KUBERNETES_SERVICE_PORT_HTTPS=443
CI_CONCURRENT_PROJECT_ID=0
CI_API_V4_URL=https://private.gitlab/api/v4
CI_ENVIRONMENT_URL=https://review-branch-axhv.private.app
KUBERNETES_PORT_443_TCP_PORT=443
GITLAB_USER_EMAIL=my@email
CI_COMMIT_REF_NAME=ci-cd-mr
CI_SERVER_VERSION_PATCH=5
API_IMAGE=private.gitlab/project/app/api
CI_REGISTRY_IMAGE=private.gitlab/project/app
CI_MERGE_REQUEST_IID=581
CI_PIPELINE_IID=2067
CI_MERGE_REQUEST_SOURCE_PROJECT_URL=https://private.gitlab/project/app
KUBE_URL=https://35.193.88.144 #WRONG IP ( CHECK SUMMARY )
CI_SERVER_TLS_CA_FILE=/builds/project/app.tmp/CI_SERVER_TLS_CA_FILE
CI_RUNNER_ID=54
CI_ENVIRONMENT_SLUG=review-ci-cd-mr-axhvfh
CI_BUILDS_DIR=/builds
CI_SERVER=yes
KUBERNETES_PORT_443_TCP=tcp://10.233.0.1:443
CI_JOB_ID=36032
CI_REPOSITORY_URL=https://gitlab-ci-token:[MASKED]@private.gitlab/project/app.git
FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER=false
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE=runner
GITLAB_USER_LOGIN=valeri.rangelov
CI_RUNNER_REVISION=a987417a
DOCKER_TLS_CERTDIR=
CI_MERGE_REQUEST_SOURCE_PROJECT_ID=339
CI_MERGE_REQUEST_ASSIGNEES=valeri.rangelov
FE_DEPS_TAG=private.gitlab/project/app/frontend:deps
CI_CONFIG_PATH=.gitlab-ci.yml
CI_PROJECT_NAME=app
CI_SERVER_VERSION_MINOR=2
CI_SERVER_VERSION_MAJOR=12
CI_NODE_TOTAL=1
FE_DEPS_RELEASE=private.gitlab/project/app/frontend:deps-
CI_ENVIRONMENT_NAME=review/ci-cd-mr
SHLVL=1
HELM_REPO_USER=dev-chartmuseum
CI_MERGE_REQUEST_PROJECT_PATH=project/app
CI_RUNNER_DESCRIPTION=runner
KUBE_CA_PEM=
KUBERNETES_SERVICE_PORT=443
CI_PAGES_URL=http://private.gitlab/project/app
CI_PROJECT_PATH=app/project
KUBE_NAMESPACE=default
GITLAB_USER_ID=84
CI_BUILD_BEFORE_SHA=0000000000000000000000000000000000000000
CI_BUILD_REF=70d96f9b54d6444aae903dff0a676c7a5e3d0929
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CI_PIPELINE_SOURCE=merge_request_event
CI_PROJECT_NAMESPACE=app
CI_MERGE_REQUEST_PROJECT_URL=https://private.gitlab/project/app
FE_IMAGE_TAG=private.gitlab/project/app/frontend:ci-cd-mr
CI_MERGE_REQUEST_PROJECT_ID=339
KUBERNETES_SERVICE_HOST=10.233.0.1
API_DEPS_TAG=private.gitlab/project/app/api:deps
CI_PROJECT_DIR=/builds/app/project
CI_JOB_STAGE=deploy
CI_BUILD_REF_SLUG=ci-cd-mr
_=/usr/bin/env