Refactor commands, construct a single GitLab client in a single place

What does this MR do?

  • Construct a single GitLab client in a single place. This would allow us to configure it consistently and not repeat that many times.
  • Construct commands using normal functions, not init(). This is problematic for many reasons.

Why was this MR needed?

To allow me to untangle and refactor things further. I need to have a single place where the GitLab client is constructed. I don't want to mess with init() functions because such code is fragile and hard to reason about. Normal sequential code is simpler - easier to follow and harder to get wrong.

What's the best way to test this MR?

I ran the --help command on the binaries. Here is the output:

Before:
NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]

VERSION:
   development version (HEAD)

AUTHOR:
   GitLab Inc. <support@gitlab.com>

COMMANDS:
   list                  List all configured runners
   run                   run multi runner service
   register              register a new runner
   reset-token           reset a runner's token
   install               install service
   uninstall             uninstall service
   start                 start service
   stop                  stop service
   restart               restart service
   status                get status of a service
   run-single            start single runner
   unregister            unregister specific runner
   verify                verify all registered runners
   wrapper               start multi runner service wrapped with gRPC manager server
   fleeting              manage fleeting plugins
   artifacts-downloader  download and extract build artifacts (internal)
   artifacts-uploader    create and upload build artifacts (internal)
   cache-archiver        create and upload cache artifacts (internal)
   cache-extractor       download and extract cache artifacts (internal)
   cache-init            changed permissions for cache paths (internal)
   health-check          check health for a specific address
   proxy-exec            execute internal commands (internal)
   read-logs             reads job logs from a file, used by kubernetes executor (internal)
   help, h               Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --cpuprofile value           write cpu profile to file [$CPU_PROFILE]
   --debug                      debug mode [$RUNNER_DEBUG]
   --log-format value           Choose log format (options: runner, text, json) [$LOG_FORMAT]
   --log-level value, -l value  Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
   --help, -h                   show help
   --version, -v                print the version
After:
NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]

VERSION:
   development version (HEAD)

AUTHOR:
   GitLab Inc. <support@gitlab.com>

COMMANDS:
   list                  List all configured runners
   register              register a new runner
   reset-token           reset a runner's token
   run                   run multi runner service
   run-single            start single runner
   wrapper               start multi runner service wrapped with gRPC manager server
   unregister            unregister specific runner
   verify                verify all registered runners
   fleeting              manage fleeting plugins
   artifacts-downloader  download and extract build artifacts (internal)
   artifacts-uploader    create and upload build artifacts (internal)
   cache-archiver        create and upload cache artifacts (internal)
   cache-extractor       download and extract cache artifacts (internal)
   cache-init            changed permissions for cache paths (internal)
   health-check          check health for a specific address
   proxy-exec            execute internal commands (internal)
   read-logs             reads job logs from a file, used by kubernetes executor (internal)
   install               install service
   uninstall             uninstall service
   start                 start service
   stop                  stop service
   restart               restart service
   status                get status of a service
   help, h               Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --cpuprofile value           write cpu profile to file [$CPU_PROFILE]
   --debug                      debug mode [$RUNNER_DEBUG]
   --log-format value           Choose log format (options: runner, text, json) [$LOG_FORMAT]
   --log-level value, -l value  Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
   --help, -h                   show help
   --version, -v                print the version
Diff:
--- ./before.txt	2025-11-18 20:08:53
+++ ./after.txt	2025-11-18 20:09:10
@@ -12,19 +12,13 @@
 
 COMMANDS:
    list                  List all configured runners
-   run                   run multi runner service
    register              register a new runner
    reset-token           reset a runner's token
-   install               install service
-   uninstall             uninstall service
-   start                 start service
-   stop                  stop service
-   restart               restart service
-   status                get status of a service
+   run                   run multi runner service
    run-single            start single runner
+   wrapper               start multi runner service wrapped with gRPC manager server
    unregister            unregister specific runner
    verify                verify all registered runners
-   wrapper               start multi runner service wrapped with gRPC manager server
    fleeting              manage fleeting plugins
    artifacts-downloader  download and extract build artifacts (internal)
    artifacts-uploader    create and upload build artifacts (internal)
@@ -34,6 +28,12 @@
    health-check          check health for a specific address
    proxy-exec            execute internal commands (internal)
    read-logs             reads job logs from a file, used by kubernetes executor (internal)
+   install               install service
+   uninstall             uninstall service
+   start                 start service
+   stop                  stop service
+   restart               restart service
+   status                get status of a service
    help, h               Shows a list of commands or help for one command
 
 GLOBAL OPTIONS:

Helper binary:

Before:
NAME:
   gitlab-runner-helper - a GitLab Runner Helper

USAGE:
   gitlab-runner-helper [global options] command [command options] [arguments...]

VERSION:
   development version (HEAD)

AUTHOR:
   GitLab Inc. <support@gitlab.com>

COMMANDS:
   artifacts-downloader  download and extract build artifacts (internal)
   artifacts-uploader    create and upload build artifacts (internal)
   cache-archiver        create and upload cache artifacts (internal)
   cache-extractor       download and extract cache artifacts (internal)
   cache-init            changed permissions for cache paths (internal)
   health-check          check health for a specific address
   proxy-exec            execute internal commands (internal)
   read-logs             reads job logs from a file, used by kubernetes executor (internal)
   help, h               Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug                      debug mode [$RUNNER_DEBUG]
   --log-format value           Choose log format (options: runner, text, json) [$LOG_FORMAT]
   --log-level value, -l value  Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
   --help, -h                   show help
   --version, -v                print the version
After:
NAME:
   gitlab-runner-helper - a GitLab Runner Helper

USAGE:
   gitlab-runner-helper [global options] command [command options] [arguments...]

VERSION:
   development version (HEAD)

AUTHOR:
   GitLab Inc. <support@gitlab.com>

COMMANDS:
   artifacts-downloader  download and extract build artifacts (internal)
   artifacts-uploader    create and upload build artifacts (internal)
   cache-archiver        create and upload cache artifacts (internal)
   cache-extractor       download and extract cache artifacts (internal)
   cache-init            changed permissions for cache paths (internal)
   health-check          check health for a specific address
   proxy-exec            execute internal commands (internal)
   read-logs             reads job logs from a file, used by kubernetes executor (internal)
   help, h               Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug                      debug mode [$RUNNER_DEBUG]
   --log-format value           Choose log format (options: runner, text, json) [$LOG_FORMAT]
   --log-level value, -l value  Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
   --help, -h                   show help
   --version, -v                print the version

What are the relevant issue numbers?

Relates to Implement Runner job proxying (gitlab-org/cluster-integration/gitlab-agent#771 - closed).

Edited by Mikhail Mazurskiy

Merge request reports

Loading