Skip to content

Fix jsonschema validation warning for kubernetes retry_limits

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

  • Please check this box if this contribution uses AI-generated content as outlined in the GitLab DCO & CLA

What does this MR do?

This MR fixes a jsonschema validation warning for the kubernetes retry_limits struct.

It is based on similar solutions (e.g. !4248 (merged) and !4724 (merged)) and adds the omitempty flag to the RequestRetryLimits struct inside common/config.go. It is an optional configuration for tuning the retry behavior of the runner and should not produce a validation warning if left empty by the user.

Why was this MR needed?

Running gitlab-runner list with a basic config.toml currently throws a jsonschema validation warning:

$ gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=100411 revision=81ab07f6 version=16.10.0
There might be a problem with your config based on jsonschema annotations in common/config.go (experimental feature):
ssonschema: '/runners/0/kubernetes/retry_limits' does not validate with https://gitlab.com/gitlab-org/gitlab-runner/common/config#/$ref/properties/runners/items/$ref/properties/kubernetes/$ref/properties/retry_limits/$ref/type: expected object, but got null
Listing configured runners                          ConfigFile=/home/gitlab-runner/.gitlab-runner/config.toml
kubernetes-runner-001                               Executor=kubernetes Token=xj484ijsdjoiv892 URL=https://gitlab.company.local

What's the best way to test this MR?

To reproduce the issue:

  1. Create a basic config.toml that uses the kubernetes executor (see example config below)
  2. Download the latest gitlab-runner binary
  3. Run gitlab-runner list --config path/to/config.toml
  4. Verify that the validation warning is being displayed

To test the fix:

  1. Re-use the config.toml
  2. Build the gitlab-runner binary
  3. Run gitlab-runner list --config path/to/config.toml
  4. Ensure that no validation warnings are being displayed
Example `config.toml`
concurrent = 5
check_interval = 3
log_level = "info"
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "kubernetes-runner-001"
  output_limit = 4096000
  url = "https://git.company.local"
  id = 1
  token = "xj484ijsdjoiv892-hiuZ4"
  token_obtained_at = 2024-05-17T08:48:08Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "kubernetes"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.kubernetes]
    host = ""
    bearer_token_overwrite_allowed = false
    image = "alpine"
    namespace = "gitlab-runner"
    namespace_overwrite_allowed = ""
    namespace_per_job = false
    pull_policy = ["always", "if-not-present"]
    node_selector_overwrite_allowed = ""
    node_tolerations_overwrite_allowed = ""
    poll_timeout = 360
    pod_labels_overwrite_allowed = ""
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.init_permissions_container_security_context]
    [runners.kubernetes.build_container_security_context]
    [runners.kubernetes.helper_container_security_context]
    [runners.kubernetes.service_container_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

What are the relevant issue numbers?

There is currently no issue for this.

Edited by 🤖 GitLab Bot 🤖

Merge request reports