Skip to content

fix: normalize underscores to dashes in Service metadata.name#2098

Open
vigneshakaviki wants to merge 1 commit into
kubernetes:mainfrom
vigneshakaviki:fix/underscore-service-name
Open

fix: normalize underscores to dashes in Service metadata.name#2098
vigneshakaviki wants to merge 1 commit into
kubernetes:mainfrom
vigneshakaviki:fix/underscore-service-name

Conversation

@vigneshakaviki
Copy link
Copy Markdown

Summary

Fixes #1897

When a Docker Compose service name contains underscores (e.g., my_web_app), kompose correctly normalizes the map key and most resource names to use dashes (my-web-app), but the serviceConfig.Name field retains underscores because it's set via parseResourceName() which uses normalizeContainerNames() (lowercase only, no underscore replacement).

This causes the Kubernetes Service metadata.name to contain underscores (my_web_app) while other resources like Deployments correctly use dashes (my-web-app).

Root Cause

In dockerComposeToKomposeMapping(), serviceConfig.Name is initially set from parseResourceName() which calls normalizeContainerNames(). The map key is set from normalizeServiceNames() (which replaces underscores with dashes), but serviceConfig.Name is never updated to match.

Fix

Set serviceConfig.Name to the result of normalizeServiceNames() so all generated Kubernetes resources use consistent, DNS-valid names.

Before (stock kompose)

$ kompose convert -f docker-compose.yaml --stdout
# Service gets: name: my_web_app    ← invalid, has underscores
# Deployment gets: name: my-web-app ← correct

After (patched)

$ kompose convert -f docker-compose.yaml --stdout
# Service gets: name: my-web-app    ← correct
# Deployment gets: name: my-web-app ← correct

Test Plan

  • Added TestServiceConfigNameNormalized unit test that:
    • Creates a compose project with service name my_service
    • Verifies serviceConfig.Name is my-service after mapping
    • Confirmed test fails without the fix, passes with it
  • All existing tests pass (go test ./...)
  • End-to-end verification with kompose convert --stdout

The serviceConfig.Name field was set via parseResourceName() which uses
normalizeContainerNames() (lowercase only), but the map key used
normalizeServiceNames() (replaces underscores with dashes). This caused
the Kubernetes Service metadata.name to contain underscores while other
resources like Deployments correctly used dashes.

Set serviceConfig.Name to the normalized name from normalizeServiceNames()
so all generated Kubernetes resources use consistent, valid DNS names.

Fixes kubernetes#1897

Signed-off-by: Vignesh <kumarvignesh295@gmail.com>
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 13, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Invalid commit message issues detected

Invalid commit messages

Keywords which can automatically close issues and hashtag(#) mentions are not allowed.

  • 58c0465 fix: normalize service name with dashes in serviceConfig.Name

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @vigneshakaviki!

It looks like this is your first PR to kubernetes/kompose 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kompose has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vigneshakaviki
Once this PR has been reviewed and has the lgtm label, please assign cdrage for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from TessaIO and cdrage April 13, 2026 21:35
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 13, 2026
@cdrage
Copy link
Copy Markdown
Member

cdrage commented May 13, 2026

Hi @vigneshakaviki the main blocker would be the commit message, any way you can modify it to pass? :) thanks

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] underscores in compose service name are not replaced with dashes in kubernetes Service metadata.name

3 participants