Registering multiple runners with the same service breaks with "runners.autoscale"

Summary

When using the "fleeting-plugin-aws" plugin with "runners.autoscale", we discovered that trying to register multiple runners via a template produces a partial configuration for the second registered runner (and sometimes the first too), specifically, it was missing the "runners.docker" section and other sections differed too.

Steps to reproduce

  1. Create a template (see example template below)
  2. Register the runner using the template with
gitlab-runner register -n --template-config=/tmp/example-template.toml -c /tmp/config.toml -t "glrt-TOKEN1" --name "RUNNER1"
  1. Register the second runner (in our case we have a different autoscaling group ID in the template but everything else is identical)
gitlab-runner register -n --template-config=/tmp/example-template.toml -c /tmp/config.toml -t "glrt-TOKEN2" --name "RUNNER2"
config.toml contents before registration
concurrent = 60
check_interval = 15
shutdown_timeout = 0

[session_server]
  session_timeout = 10800
template .toml contents
[[runners]]
  output_limit = 65536
  url = "https://gitlab.com/"
  executor = "docker-autoscaler"
  limit = 6
  [runners.docker]
    image = "alpinelinux/gitlab-runner-helper"
    privileged = true
    disable_cache = true
  [runners.autoscaler]
    plugin = "fleeting-plugin-aws"
    capacity_per_instance = 1
    max_use_count = 5
    max_instances = 6
  [runners.autoscaler.plugin_config]
    name = "REDACTED"
  [runners.autoscaler.connector_config]
    username = "ec2-user"
    use_external_addr = false
  [[runners.autoscaler.policy]]
    idle_count = 0
    idle_time = "1m0s"

Actual behavior

After what appeared to be a successful registration, note that the [runners.docker] section is omitted, which in this case prevents the runner from working.

Actual config.toml output after registration
concurrent = 60
check_interval = 15
shutdown_timeout = 0

[session_server]
  session_timeout = 10800

[[runners]]
  name = "RUNNER1"
  limit = 6
  output_limit = 65536
  url = "https://gitlab.com/"
  id = 29860438
  token = "glrt-REDACTED"
  token_obtained_at = 2023-11-29T09:00:48Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker-autoscaler"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.autoscaler]
    capacity_per_instance = 1
    max_use_count = 5
    max_instances = 6
    plugin = "fleeting-plugin-aws"
    [runners.autoscaler.plugin_config]
      name = "REDACTED"
    [runners.autoscaler.connector_config]
      username = "ec2-user"
      password = ""
      key_path = ""
      use_static_credentials = false
      keepalive = "0s"
      timeout = "0s"
      use_external_addr = false

    [[runners.autoscaler.policy]]
      idle_count = 0
      idle_time = "1m0s"
      scale_factor = 0.0
      scale_factor_limit = 0

Note that after registration the [runners.docker] section is missing.

Expected behavior

The [runners.docker] section should be present and any additional default config values should have been added as per other sections.

Environment description

OS: Amazon Linux 2
Gitlab-runner version: 16.6.1

Used GitLab Runner version

Version:      16.6.1
Git revision: f5da3c5a
Git branch:   16-6-stable
GO version:   go1.20.10
Built:        2023-11-24T21:11:36+0000
OS/Arch:      linux/arm64

Possible fixes

Edited by Chris Pringle