fix(generation): Fix container name

Container names were built using the service name. We didn't checked the
name and leave underscores inside.

This commit does:
- fix all service and rename containers (`container_name`)
- use `ContainerName` everywhere we need to get the container by name

See #106
This commit is contained in:
2025-06-26 23:23:03 +02:00
parent 9fcce059e5
commit e2b897eb9d
4 changed files with 54 additions and 7 deletions

View File

@@ -48,6 +48,8 @@ func Generate(project *types.Project) (*HelmChart, error) {
// drop all services with the "ignore" label
dropIngoredServices(project)
fixContainerNames(project)
// rename all services name to remove dashes
if err := fixResourceNames(project); err != nil {
return nil, err
@@ -265,7 +267,7 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC
return
}
container, index := utils.GetContainerByName(service.Name, d.Spec.Template.Spec.Containers)
container, index := utils.GetContainerByName(service.ContainerName, d.Spec.Template.Spec.Containers)
if container == nil { // may append for the same-pod services
return
}
@@ -416,3 +418,15 @@ func samePodVolume(service types.ServiceConfig, v types.ServiceVolumeConfig, dep
}
return false
}
func fixContainerNames(project *types.Project) {
// fix container names to be unique
for i, service := range project.Services {
if service.ContainerName == "" {
service.ContainerName = utils.FixedResourceName(service.Name)
} else {
service.ContainerName = utils.FixedResourceName(service.ContainerName)
}
project.Services[i] = service
}
}