Skip to content

Fix too long kubernetes labels when using digest in image tag #326

Open
barskern wants to merge 1 commit into
meilisearch:mainfrom
barskern:fix-tag-in-labels
Open

Fix too long kubernetes labels when using digest in image tag #326
barskern wants to merge 1 commit into
meilisearch:mainfrom
barskern:fix-tag-in-labels

Conversation

@barskern
Copy link
Copy Markdown
Contributor

@barskern barskern commented May 20, 2026

Pull Request

Related issue

NaN

What does this PR do?

Labels have to be less than 63 characters, so when using a digest in the tag, which is recommended 0, the label
becomes too long and the chart fails. This change strips away any digest or pinning after the tag.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Overview

This PR prevents Kubernetes label failures caused by overly long image tags (e.g., when using image digests) by adding a configurable label value and sanitizing the version used in labels.

Changes

New Configuration Option

  • Added image.versionLabel to charts/meilisearch/values.yaml (defaults to empty string). Documented as intended for use when the image tag is pinned to a digest.

Label Generation Logic Update

  • Updated charts/meilisearch/templates/_helpers.tpl → meilisearch.labels:
    • app.kubernetes.io/version is now emitted only when either .Chart.AppVersion or .Values.image.tag is set.
    • The label value is computed from .Values.image.tag with a fallback to .Chart.AppVersion, then:
      • Strips any @sha256:... digest suffix,
      • Truncates to 63 characters,
      • Trims a trailing -,
      • Quotes the result.

Design Rationale

Sanitizing and truncating the version keeps label values within Kubernetes' 63-character limit. The added image.versionLabel provides an opt-in configurable field for users, though the template currently derives the emitted version from image.tagChart.AppVersion and applies normalization to ensure label validity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

Warning

Review limit reached

@barskern, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 42 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1cc8976a-4fdc-4b70-9bf2-a3fe597208b0

📥 Commits

Reviewing files that changed from the base of the PR and between b72a8f3 and 21d3c52.

📒 Files selected for processing (1)
  • charts/meilisearch/templates/_helpers.tpl
📝 Walkthrough

Walkthrough

Adds image.versionLabel to chart values and updates the meilisearch.labels helper to emit app.kubernetes.io/version only when a version source exists; the helper computes the label from image.tag (fallback to Chart.AppVersion), strips @sha256:..., truncates to 63 chars, trims trailing -, and quotes the value.

Changes

Version label configuration

Layer / File(s) Summary
Version label config and template integration
charts/meilisearch/values.yaml, charts/meilisearch/templates/_helpers.tpl
Adds image.versionLabel: "" to values and updates meilisearch.labels to conditionally emit app.kubernetes.io/version. The helper computes the label from image.tag with fallback to Chart.AppVersion, strips any @sha256:... suffix, truncates to 63 chars, trims a trailing -, and quotes the result.

🎯 3 (Moderate) | ⏱️ ~20 minutes

A rabbit whispers in the chart, 🐇
A version field and tidy art,
Tags are trimmed and quoted clean,
Labels born from tidy glean,
Kubernetes sings, neat and smart.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main problem being fixed: Kubernetes labels becoming too long when using digest in image tags.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@barskern barskern force-pushed the fix-tag-in-labels branch from 0dc27fa to 7098b93 Compare June 1, 2026 13:07
@barskern
Copy link
Copy Markdown
Contributor Author

barskern commented Jun 1, 2026

@coderabbitai help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@barskern
Copy link
Copy Markdown
Contributor Author

barskern commented Jun 1, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@charts/meilisearch/templates/_helpers.tpl`:
- Around line 37-40: The helper currently computes $rawVersion only from
.Values.image.tag or .Chart.AppVersion so .Values.image.versionLabel is ignored;
change the $rawVersion assignment to prefer .Values.image.versionLabel first,
falling back to .Values.image.tag then .Chart.AppVersion (e.g. set $rawVersion
:= .Values.image.versionLabel | default (.Values.image.tag | default
.Chart.AppVersion)), leaving the subsequent $version
regexReplaceAll/trunc/trimSuffix and the app.kubernetes.io/version label
generation unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55ed916a-b82b-4201-871f-b9f53c880d85

📥 Commits

Reviewing files that changed from the base of the PR and between 0dc27fa and 7098b93.

📒 Files selected for processing (2)
  • charts/meilisearch/templates/_helpers.tpl
  • charts/meilisearch/values.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • charts/meilisearch/values.yaml

Comment on lines 37 to +40
{{- if or .Chart.AppVersion .Values.image.tag }}
app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
{{- $rawVersion := .Values.image.tag | default .Chart.AppVersion }}
{{- $version := regexReplaceAll "@sha256:[a-f0-9]+" $rawVersion "" | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/version: {{ $version | quote }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

image.versionLabel override is not applied in label computation

The new override path is missing: on Line 38 the helper still derives version only from image.tag/Chart.AppVersion, so image.versionLabel cannot actually control app.kubernetes.io/version as intended.

Suggested fix
-{{- if or .Chart.AppVersion .Values.image.tag }}
-{{- $rawVersion := .Values.image.tag | default .Chart.AppVersion }}
+{{- if or .Values.image.versionLabel .Values.image.tag .Chart.AppVersion }}
+{{- $rawVersion := .Values.image.versionLabel | default (.Values.image.tag | default .Chart.AppVersion) }}
 {{- $version := regexReplaceAll "`@sha256`:[a-f0-9]+" $rawVersion "" | trunc 63 | trimSuffix "-" }}
 app.kubernetes.io/version: {{ $version | quote }}
 {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- if or .Chart.AppVersion .Values.image.tag }}
app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
{{- $rawVersion := .Values.image.tag | default .Chart.AppVersion }}
{{- $version := regexReplaceAll "@sha256:[a-f0-9]+" $rawVersion "" | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/version: {{ $version | quote }}
{{- if or .Values.image.versionLabel .Values.image.tag .Chart.AppVersion }}
{{- $rawVersion := .Values.image.versionLabel | default (.Values.image.tag | default .Chart.AppVersion) }}
{{- $version := regexReplaceAll "`@sha256`:[a-f0-9]+" $rawVersion "" | trunc 63 | trimSuffix "-" }}
app.kubernetes.io/version: {{ $version | quote }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@charts/meilisearch/templates/_helpers.tpl` around lines 37 - 40, The helper
currently computes $rawVersion only from .Values.image.tag or .Chart.AppVersion
so .Values.image.versionLabel is ignored; change the $rawVersion assignment to
prefer .Values.image.versionLabel first, falling back to .Values.image.tag then
.Chart.AppVersion (e.g. set $rawVersion := .Values.image.versionLabel | default
(.Values.image.tag | default .Chart.AppVersion)), leaving the subsequent
$version regexReplaceAll/trunc/trimSuffix and the app.kubernetes.io/version
label generation unchanged.

Labels have to be less than 63 characters, so when using a digest in the tag, which is recommended [0], the label
becomes too long and the chart fails. This change strips away any digest or pinning after the tag.

[0]: https://docs.docker.com/dhi/core-concepts/digests/
@barskern barskern force-pushed the fix-tag-in-labels branch from 7098b93 to 21d3c52 Compare June 1, 2026 13:19
@barskern
Copy link
Copy Markdown
Contributor Author

barskern commented Jun 1, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

✅ Actions performed

Full review triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant