Double quote appVersion in helm package index.yaml

What does this MR do and why?

When generating index.yaml for Helm packages, version strings that match scientific notation patterns (e.g., 4852e000) are interpreted by Helm as numbers in scientific notation rather than strings. This causes:

  • Helm to parse 4852e000 as 4.852e+003
  • Failed when users try to add the package registry to helm repo

This MR fixes Helm parsing errors caused by appVersion values that resemble scientific notation (e.g., 4852e000).

The presenter now generates YAML directly and ensures all appVersion values are quoted, preventing Helm from misinterpreting them as numbers.

Changes

  • Refactored Packages::Helm::IndexPresenter to have full control over YAML generation
  • Added post-processing to ensure appVersion values are always quoted in the YAML output

Previous MR

We previously attempted to fix this in !166663 (merged) by pre-quoting the value:

metadata['appVersion'] = format('"%s"', metadata['appVersion']) if metadata.key?('appVersion')

However, this approach caused Ruby's to_yaml to quote the value again, resulting in double-quoted output:

appVersion: '"master"'    
appVersion: '"4852e000"' 

References

N/A

Screenshots or screen recordings

appVersion Before After
4852e000 appVersion: 4852e004 appVersion: "4852e000"
master appVersion: master appVersion: "master"
1.0.0 appVersion: 1.0.0 appVersion: "1.0.0"

How to set up and validate locally

  1. Switch to master branch

  2. Create a Helm package with a problematic appVersion:

helm create test-chart
cd test-chart
# Edit Chart.yaml to set appVersion: 4852e000
helm package .
  1. Upload the package to your local GitLab instance:
curl --request POST \
  --user root:$TOKEN \
  --form 'chart=@test-chart-0.1.0.tgz' \
  "${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/packages/helm/api/stable/charts"
  1. Check the index.yaml and try to download the package, it will return an error
> curl --user root:$TOKEN \
    "${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/packages/helm/stable/index.yaml"

---
apiVersion: v1
entries:
  test-chart:
  - name: test-chart
    type: application
    version: 0.1.0
    apiVersion: v2
    appVersion: 4852e000
    description: A Helm chart for Kubernetes
    created: '2025-06-30T15:33:34.246950000Z'
    digest:
    urls:
    - charts/test-chart-0.1.0.tgz
generated: '2025-06-30T15:33:42.705558000Z'
serverInfo:
  contextPath: "/api/v4/projects/2/packages/helm"

> helm repo add gitlab ${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/packages/helm/stable --username root --password $TOKEN

Error: looks like "http://gdk.test:3000/api/v4/projects/2/packages/helm/stable" is not a valid chart repository or cannot be reached: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal number into Go struct field ChartVersion.entries.Metadata.appVersion of type string
  1. Switch to this brach and download index.yaml and add repo
> curl --user root:$TOKEN \   
    "${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/packages/helm/stable/index.yaml"

---
apiVersion: v1
entries:
  test-chart:
  - name: test-chart
    type: application
    version: 0.1.0
    apiVersion: v2
    appVersion: "4852e000"
    description: A Helm chart for Kubernetes
    created: '2025-06-30T15:33:34.246950000Z'
    digest:
    urls:
    - charts/test-chart-0.1.0.tgz
generated: '2025-06-30T15:34:57.339084000Z'
serverInfo:
  contextPath: "/api/v4/projects/2/packages/helm"

> helm repo add gitlab ${GITLAB_URL}/api/v4/projects/${PROJECT_ID}/packages/helm/stable --username root --password $TOKEN

"gitlab" has been added to your repositories
  1. Pull the package, it should be successful
helm repo update
helm pull gitlab/test-chart --version 0.1.0

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #490699 (closed)

Edited by Sylvia Shen

Merge request reports

Loading