Skip to content

Convert Values.replicas from float64 to int64

Romuald Atchadé requested to merge convert-replicas-to-int64 into main

What does this MR do?

We recently merged this MR: !459 (merged), which now allows setting replicas using the following command:

helm template gitlab-runner . --set replicas=2

However, this change unintentionally introduced a bug that I missed during my initial review. While testing, I encountered an issue related to type conversion errors.

In this merge request, we addressed this issue by ensuring that the Values.replicas value is always converted to int64. This prevents any potential type conversion errors, whether the value is set in the values.yaml file or via the --set flag

Why was this MR needed?

Prevent introducing a bug in next release

What's the best way to test this MR?

Test on main branch

  1. Run the following command
helm template gitlab-runner . -f --set replicas=2

The template will generate without any errors

  1. Run the following command
cat << EOF > custom_values.yaml
image:
  registry: registry.gitlab.com
  image: gitlab-org/gitlab-runner
useTini: false
imagePullPolicy: IfNotPresent
replicas: 1
gitlabUrl: https://gitlab.com/

useJobNamespace: true
terminationGracePeriodSeconds: 0
concurrent: 1
checkInterval: 1
logLevel: "debug"
sessionServer:
  enabled: true
  # publicIP: ""
  annotations: {}
  timeout: 1800
  internalPort: 8093
  externalPort: 9000

## For RBAC support:
rbac:
  create: true
  rules:
    - apiGroups: [""]
      resources: ["configmaps", "events", "pods", "pods/attach", "pods/log", "secrets", "services",  "serviceAccounts"]
      verbs: ["get", "list", "watch", "create", "patch", "update", "delete"]
    - apiGroups: [""]
      resources: ["pods/exec"]
      verbs: ["create", "patch", "delete"]
  clusterWideAccess: false
  podSecurityPolicy:
    enabled: false
    resourceNames:
    - gitlab-runner
EOF

helm template gitlab-runner . -f custom_values.yaml >tmp.yaml

The command will fail with the error below:

Error: template: gitlab-runner/templates/service-session-server.yaml:1:11: executing "gitlab-runner/templates/service-session-server.yaml" at <include "gitlab-runner.isSessionServerAllowed" .>: error calling include: template: gitlab-runner/templates/_helpers.tpl:127:9: executing "gitlab-runner.isSessionServerAllowed" at <eq (default 1 .Values.replicas) 1>: error calling eq: incompatible types for comparison

Use --debug flag to render out invalid YAML

Test on the MR branch

Run commands 1 and 2 on the MR branch.

Both should generate the template without error

What are the relevant issue numbers?

NA

Merge request reports