Skip to content

Conversation

asahasrabuddhe
Copy link

@asahasrabuddhe asahasrabuddhe commented Sep 10, 2025

What does this PR do?

This PR strips the architecture suffix (e.g. .arm64) from Kafka image tags.

Why is it important?

Newer Kafka Docker images have started including architecture suffixes in
their tags (e.g. 7.5.9-1-ubi8.arm64, 7.5.9.arm64). These tags are
problematic because the .arm64 suffix is not valid according to the
Semantic Versioning specification.

  • 7.5.9-1-ubi8.arm64 is semver-compatible because everything before
    .arm64 (7.5.9-1-ubi8) is already a valid semver string with a
    pre-release identifier (-1-ubi8). The .arm64 suffix, while not valid
    semver itself, is layered on top of an otherwise valid version.
  • 7.5.9.arm64, on the other hand, is not semver-compatible because
    the .arm64 directly follows the patch version, making the whole string
    invalid under semver rules.

This change ensures compatibility with golang.org/x/mod/semver by
normalising the tag — removing the trailing architecture suffix — before
parsing. That way, we consistently fall back to a valid semver core
(e.g. 7.5.9 or 7.5.9-1-ubi8), while still supporting images with suffixes.

Related issues

Closes #2890

How to test this PR

We can try to use a newer Kafka image with a tag that contains the architecture suffix (e.g. confluentinc/confluent-local:7.5.0.arm64 or confluentinc/confluent-local:7.5.9.arm64). We should no longer see the KRaft mode is only available since version 7.4.0 error message.

Newer Kafka Docker images include architecture suffixes in their tags
(e.g. 7.5.0.arm64), which are not valid semver. This change normalises
the tag by removing the architecture suffix before passing it to the
semver parser, ensuring compatibility with golang.org/x/mod/semver.
@asahasrabuddhe asahasrabuddhe requested a review from a team as a code owner September 10, 2025 14:28
@netlify
Copy link

netlify bot commented Sep 10, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit cbcd0d0
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e5145d81b0360008848440
😎 Deploy Preview https://deploy-preview-3276--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@asahasrabuddhe asahasrabuddhe changed the title fix: strip architecture suffix from Kafka image tags for semver parsing Fix: strip architecture suffix from Kafka image tags for semver parsing Sep 10, 2025
@mdelapenya mdelapenya added the bug An issue with the library label Sep 10, 2025
@asahasrabuddhe asahasrabuddhe changed the title Fix: strip architecture suffix from Kafka image tags for semver parsing Strip architecture suffix from Kafka image tags for semver parsing Sep 10, 2025
@asahasrabuddhe asahasrabuddhe changed the title Strip architecture suffix from Kafka image tags for semver parsing fix: Strip architecture suffix from Kafka image tags for semver parsing Sep 10, 2025
@asahasrabuddhe asahasrabuddhe changed the title fix: Strip architecture suffix from Kafka image tags for semver parsing fix(Kafka): Strip architecture suffix from Kafka image tags for semver parsing Sep 10, 2025
@asahasrabuddhe asahasrabuddhe changed the title fix(Kafka): Strip architecture suffix from Kafka image tags for semver parsing fix(kafka): strip architecture suffix from Kafka image tags for semver parsing Sep 10, 2025
mdelapenya
mdelapenya previously approved these changes Sep 11, 2025
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

My only question would be if we should notify the Kafka folks about releasing multi-arch images to avoid breaking semver 🤔

@eddumelendez @kiview wdyt?

@asahasrabuddhe
Copy link
Author

LGTM, thanks!

My only question would be if we should notify the Kafka folks about releasing multi-arch images to avoid breaking semver 🤔

@eddumelendez @kiview wdyt?

If not multi-arch images, they should try to fix their tagging to be semver compatible.


// remove the architecture suffix
if strings.HasSuffix(version, ".amd64") || strings.HasSuffix(version, ".arm64") {
version = version[:strings.LastIndex(version, ".")]
Copy link
Author

Choose a reason for hiding this comment

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

@mdelapenya How about something like this? But at this point, we might as well let them use the image by fixing the version.

Suggested change
version = version[:strings.LastIndex(version, ".")]
return fmt.Errorf("invalid image tag %q: architecture suffixes like .arm64 or .amd64 are not valid semver; please use a multi-architecture image instead", tag)

Copy link
Member

Choose a reason for hiding this comment

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

Given we are using semver libraries to get a valid version, then we should honor it. I think this is a good compromise, failing if the version is not following semver.

Copy link
Member

Choose a reason for hiding this comment

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

@asahasrabuddhe let's apply that fix, so we can merge this PR

Thanks!

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Summary by CodeRabbit

  • New Features

    • Improved compatibility with Confluent Kafka images by accepting architecture-suffixed tags (.amd64, .arm64) during KRaft version validation.
  • Bug Fixes

    • Prevented false validation failures when using architecture-specific image tags for supported versions.
  • Tests

    • Added test coverage for amd64 and arm64 image tags to ensure correct version handling.

Walkthrough

Adds architecture suffix stripping (".amd64"/".arm64") in validateKRaftVersion before semver comparison with "v7.4.0". Updates tests to include Confluent image tags with architecture suffixes for both amd64 and arm64, expecting no errors.

Changes

Cohort / File(s) Summary
Kafka KRaft version parsing
modules/kafka/kafka.go
Enhance validateKRaftVersion to remove architecture suffix by truncating at the last dot after ensuring "v" prefix, then perform existing semver comparison against v7.4.0. No other logic changed.
Unit tests for version parsing
modules/kafka/kafka_helpers_test.go
Add two test cases covering official Confluent image tags with amd64 and arm64 suffixes; assert no error. No other test changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant V as validateKRaftVersion

  C->>V: validateKRaftVersion(tag)
  activate V
  V->>V: Ensure "v" prefix
  V->>V: If tag ends with .amd64/.arm64<br/>truncate at last "."
  V->>V: Compare semver against v7.4.0
  V-->>C: Return nil or error (unchanged criteria)
  deactivate V

  rect rgba(200,230,255,0.3)
  note right of V: New step: strip architecture suffix<br/>before semver comparison
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I sniffed the tags: dot, arch, and v—
Trim the tails, compare with glee.
amd64 hops, arm64 too,
Versions align like morning dew.
In the burrow of tests so bright,
Kafka hums—our parsing’s right. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The code changes focus on stripping architecture suffixes from Kafka image tags and do not address the objectives of issue #2890, which involves constructing build artifact names and integrating with the Sonar step, so the linked issue’s requirements are unmet. Either update or remove the linked issue reference to align with the actual changes implemented or adjust the code to satisfy the objectives defined in issue #2890 if they are intended for this PR.
Out of Scope Changes Check ⚠️ Warning All modifications pertain exclusively to Kafka image tag parsing and do not relate to building artifact names or Sonar integration specified in the linked issue, rendering these changes out of scope for the referenced objectives. Align the pull request’s scope with its linked issue by either removing unrelated Kafka changes or linking to the correct issue that requested semver parsing enhancements for Kafka image tags.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly states the primary change of stripping architecture suffix from Kafka image tags for semver parsing in a concise manner and accurately reflects the modifications introduced in the changeset.
Description Check ✅ Passed The description accurately describes the purpose of stripping architecture suffixes from Kafka image tags to ensure semver compatibility and outlines why and how the change is made, directly relating to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@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

🧹 Nitpick comments (1)
modules/kafka/kafka.go (1)

222-225: Consider using strings.TrimSuffix for clarity.

The current implementation using strings.LastIndex works correctly, but strings.TrimSuffix would more explicitly convey the intent of removing a known suffix.

Apply this diff for a more idiomatic approach:

-	// remove the architecture suffix
-	if strings.HasSuffix(version, ".amd64") || strings.HasSuffix(version, ".arm64") {
-		version = version[:strings.LastIndex(version, ".")]
-	}
+	// remove the architecture suffix
+	version = strings.TrimSuffix(version, ".amd64")
+	version = strings.TrimSuffix(version, ".arm64")

This approach:

  • Eliminates the conditional check (TrimSuffix is a no-op if suffix not present)
  • Makes the intent more explicit
  • Handles both suffixes sequentially (though only one would be present in practice)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1e747c and cbcd0d0.

📒 Files selected for processing (2)
  • modules/kafka/kafka.go (1 hunks)
  • modules/kafka/kafka_helpers_test.go (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Main pipeline
modules/kafka/kafka_helpers_test.go

[error] 103-103: golangci-lint: File is not properly formatted (gci)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
modules/kafka/kafka_helpers_test.go (1)

97-101: LGTM!

The test case correctly validates that Kafka images with .amd64 architecture suffix are now supported after the version normalization in validateKRaftVersion.

Comment on lines +102 to +105
{
name: "Official: valid, with the arm64 architecture suffix",
image: "confluentinc/confluent-local:7.5.9.arm64",
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Add missing wantErr field and fix formatting.

The test case is incomplete - it's missing the wantErr: false field. Additionally, there's a formatting issue flagged by the linter.

Apply this diff to fix both issues:

 	{
 		name:    "Official: valid, with the arm64 architecture suffix",
 		image:   "confluentinc/confluent-local:7.5.9.arm64",
+		wantErr: false,
 	},
📝 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
{
name: "Official: valid, with the arm64 architecture suffix",
image: "confluentinc/confluent-local:7.5.9.arm64",
},
{
name: "Official: valid, with the arm64 architecture suffix",
image: "confluentinc/confluent-local:7.5.9.arm64",
wantErr: false,
},
🧰 Tools
🪛 GitHub Actions: Main pipeline

[error] 103-103: golangci-lint: File is not properly formatted (gci)

🤖 Prompt for AI Agents
In modules/kafka/kafka_helpers_test.go around lines 102 to 105, the table-driven
test entry for "Official: valid, with the arm64 architecture suffix" is missing
the wantErr field and has a linter-formatting issue; update that test case to
include wantErr: false and adjust punctuation/indentation to match surrounding
cases (ensure fields are comma-separated, aligned, and the closing brace/comma
are correctly placed).

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

Labels

bug An issue with the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants