Skip to content

Service not accessible via the default naming convention if we used a variable to specify the service

Summary

Using a variable in a service will break the naming convention to access the service.

Steps to reproduce

image: docker:latest
build:
  services:
    - name: $TUTUM_IMAGE
      alias: tutum-hello-world
  stage: build
  script:
    - cat /etc/hosts
    - sleep 600
    - wget http://tutum-hello-world

build-noalias:
  services:
    - $TUTUM_IMAGE
  stage: build
  script:
    - cat /etc/hosts
    - sleep 600
    - wget http://tutum-hello-world

build-novar:
  services:
    - tutum/hello-world
  stage: build
  script:
    - cat /etc/hosts
    - sleep 600
    - wget http://tutum-hello-world

In this example, I specified 3 jobs. I also set TUTUM_IMAGE as a project variable with a value of tutum/hello-world. As per our documentation, the job should be able to access the service using the name tutum-hello-world.

Output of the build job: https://gitlab.com/jdasmarinas/services-variable-test/-/jobs/3483539544 Output of the build-noalias job: https://gitlab.com/jdasmarinas/services-variable-test/-/jobs/3483539545 Output of the build-novar job: https://gitlab.com/jdasmarinas/services-variable-test/-/jobs/3483539546

As you can see build-novar (doesn't specify any variable or alias has the right /etc/hosts file:

$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
fe00::0	ip6-mcastprefix
fe00::1	ip6-allnodes
fe00::2	ip6-allrouters
10.192.1.20	runner-8w6ra8m6-project-41718154-concurrent-2cqgtk
# Entries added by HostAliases.
127.0.0.1	tutum-hello-world

build-noalias doesn't have the right host file and the job won't be able to access service via the default naming convention:

$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
fe00::0	ip6-mcastprefix
fe00::1	ip6-allnodes
fe00::2	ip6-allrouters
10.192.4.44	runner-8w6ra8m6-project-41718154-concurrent-1rvrpg

As a workaround, in the build job, I have to specify an alias so that the service is accessible inside the job:

$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
fe00::0	ip6-mcastprefix
fe00::1	ip6-allnodes
fe00::2	ip6-allrouters
10.192.3.20	runner-8w6ra8m6-project-41718154-concurrent-04sg72
# Entries added by HostAliases.
127.0.0.1	tutum-hello-world

This also doesn't happen in the docker+machine executor.

Actual behavior

The build container doesn't have the right /etc/hosts file to access the service.

Expected behavior

The build container has the right /etc/hosts file to access the service.

Relevant logs and/or screenshots

See log file above.

Environment description

Default value (aside from the token) of the GitLab Runner Helm chart

Used GitLab Runner version

Possible fixes

Edited by Julian Paul Dasmarinas