Label docker networks in the same way as containers

What does this MR do?

Adds labels to docker networks created per build. It reuses the logic from container labelling with slight refactoring:

  • adds a Labeler interface which has the logic for constructing labels
  • adds it as a dependency to places where it's used

Example docker network inspect:

 ~  >> docker network inspect eedcfb0f7cb7
[
    {
        "Name": "runner-r4BEA2my-project-17304257-concurrent-0-job-473035577-network",
        "Id": "eedcfb0f7cb7d342f0234be557614b27948f6860080afd2fbd4534cca91495c0",
        "Created": "2020-03-16T11:42:17.7871228Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.21.0.0/16",
                    "Gateway": "172.21.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "f6111a9bbb20819cd9f524fa6c1c926f146c800317ecc9f125192c068633dd3a": {
                "Name": "runner-r4BEA2my-project-17304257-concurrent-0-predefined-5",
                "EndpointID": "d71cd6f3a1cec45a09874783f9c5b0e59a9ec358e05e80462dae8ea13ba00ecc",
                "MacAddress": "02:42:ac:15:00:02",
                "IPv4Address": "172.21.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.gitlab.gitlab-runner.job.before_sha": "0000000000000000000000000000000000000000",
            "com.gitlab.gitlab-runner.job.id": "473035577",
            "com.gitlab.gitlab-runner.job.ref": "master",
            "com.gitlab.gitlab-runner.job.sha": "96085a5f5c5bcf7818dec93b3a2b1e47f3039520",
            "com.gitlab.gitlab-runner.pipeline.id": "126651403",
            "com.gitlab.gitlab-runner.project.id": "17304257",
            "com.gitlab.gitlab-runner.runner.id": "r4BEA2my",
            "com.gitlab.gitlab-runner.runner.local_id": "0"
        }
    }
]

Why was this MR needed?

As a follow-up to !1569 (merged)

Are there points in the code the reviewer needs to double check?

Does this MR meet the acceptance criteria?

  • Documentation created/updated
  • Added tests for this feature/bug
  • In case of conflicts with master - branch was rebased

What are the relevant issue numbers?

Fixes: #10120 (closed)

Edited by Lyubomir Raykov

Merge request reports

Loading