Skip to content

Add feature flags in config.toml

Steve Xuereb requested to merge feature-flags-configuraiton into master

What does this MR do?

  1. refactor(ff): change default type to bool
  2. Allow user to set a feature flag inside of the config.toml with [runners.feature_flags] which aren't overridable able by an job variables.

Why was this MR needed?

  1. refactor(ff): change default type to bool

    Having a bool as a string makes it hard when you want to check if pragmatically. It's easier to transform a bool into a string than vice versa.

  2. feat(ff): set feature flag in config.toml

    In !2805 (merged) we want to change how docker+machine executor creates machines and we want to roll this out behind a feature flag. At the moment users can only specify a feature flag as a job variable, which won't work in this case because a machine is created before a job exists so there is no way we can set this.

What's the best way to test this MR?

Feature flag defined in config.toml

  1. Start a docker executor with the following config.toml

    [[runners]]
      name = "docker"
      url = "http://gdk.test:3000/"
      token = ""
      executor = "docker"
      limit = 2
      [runners.feature_flags]
        "FF_NETWORK_PER_BUILD" = true
      [runners.docker]
        image = "alpine:3.12"
        privileged = true
  2. Start a job

    .gitlab-ci.yml
    variables:
      SLEEP: 60
    
    job:
      stage: test
      script:
        - sleep ${SLEEP}
  3. Whilst the job is running make sure that a network is created for the build

    docker network ls
    $ docker network ls
    NETWORK ID     NAME                                                       DRIVER    SCOPE
    9f60f6e85862   bridge                                                     bridge    local
    a8d215125ce7   host                                                       host      local
    d071437ccf78   minikube                                                   bridge    local
    44a1a7d5bd1a   none                                                       null      local
    7897d6060eb2   runner-4b72igtx-project-20-concurrent-0-job-2195-network   bridge    local
    b478d99ffde3   spamcheck_default                                          bridge    local
    job log

    Screenshot_2021-03-15_at_11.07.41

Feature flag turned off in config.toml but turned on inside of envionrments

  1. Start a docker executor with the following config.toml

    config.toml
    [[runners]]
      name = "docker"
      url = "http://gdk.test:3000/"
      token = ""
      executor = "docker"
      environment = ["FF_NETWORK_PER_BUILD=true"]
      [runners.feature_flags]
        "FF_NETWORK_PER_BUILD" = false
      [runners.docker]
        image = "alpine:3.12"
        privileged = true
  2. Start a job

    .gitlab-ci.yml
    variables:
      SLEEP: 60
    
    job:
      stage: test
      script:
        - sleep ${SLEEP}
  3. Whilst running the job make sure that a network wasn't created since we disable it in [runners.feature_flags]

    docker network ls
    # No network created for the build!
    $ docker network ls
    NETWORK ID     NAME                DRIVER    SCOPE
    9f60f6e85862   bridge              bridge    local
    a8d215125ce7   host                host      local
    d071437ccf78   minikube            bridge    local
    44a1a7d5bd1a   none                null      local
    b478d99ffde3   spamcheck_default   bridge    local
    job log

    Screenshot_2021-03-15_at_11.17.08

Feature flag turned off in config.toml but turned on inside of job variables

  1. Start a docker executor with the following config.toml

    config.toml
    [[runners]]
      name = "docker"
      url = "http://gdk.test:3000/"
      token = ""
      executor = "docker"
      [runners.feature_flags]
        "FF_NETWORK_PER_BUILD" = false
      [runners.docker]
        image = "alpine:3.12"
        privileged = true
  2. Start a job

    .gitlab-ci.yml
    variables:
      SLEEP: 60
      FF_NETWORK_PER_BUILD: "true"
    
    job:
      stage: test
      script:
        - sleep ${SLEEP}
  3. Whilst running the job make sure that a network wasn't created since we disable it in [runners.feature_flags]

    docker network ls
    # No network created for the build!
    $ docker network ls
    NETWORK ID     NAME                DRIVER    SCOPE
    9f60f6e85862   bridge              bridge    local
    a8d215125ce7   host                host      local
    d071437ccf78   minikube            bridge    local
    44a1a7d5bd1a   none                null      local
    b478d99ffde3   spamcheck_default   bridge    local
    job log

    Screenshot_2021-03-15_at_11.24.28

What are the relevant issue numbers?

To safely roll out #27613 (closed)

Edited by Steve Xuereb

Merge request reports