fix: normalize underscores to dashes in Service metadata.name#2098
fix: normalize underscores to dashes in Service metadata.name#2098vigneshakaviki wants to merge 1 commit into
Conversation
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>
|
Invalid commit message issues detected Invalid commit messagesKeywords which can automatically close issues and hashtag(#) mentions are not allowed.
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. |
|
Welcome @vigneshakaviki! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vigneshakaviki The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @vigneshakaviki the main blocker would be the commit message, any way you can modify it to pass? :) thanks |
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 theserviceConfig.Namefield retains underscores because it's set viaparseResourceName()which usesnormalizeContainerNames()(lowercase only, no underscore replacement).This causes the Kubernetes Service
metadata.nameto contain underscores (my_web_app) while other resources like Deployments correctly use dashes (my-web-app).Root Cause
In
dockerComposeToKomposeMapping(),serviceConfig.Nameis initially set fromparseResourceName()which callsnormalizeContainerNames(). The map key is set fromnormalizeServiceNames()(which replaces underscores with dashes), butserviceConfig.Nameis never updated to match.Fix
Set
serviceConfig.Nameto the result ofnormalizeServiceNames()so all generated Kubernetes resources use consistent, DNS-valid names.Before (stock kompose)
After (patched)
Test Plan
TestServiceConfigNameNormalizedunit test that:my_serviceserviceConfig.Nameismy-serviceafter mappinggo test ./...)kompose convert --stdout