Fixes same-pod problems
This commit is contained in:
@@ -229,10 +229,11 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
|
|||||||
// get the same-pod label if exists, add it to the list.
|
// get the same-pod label if exists, add it to the list.
|
||||||
// We later will copy some parts to the target deployment and remove this one.
|
// We later will copy some parts to the target deployment and remove this one.
|
||||||
if samePod, ok := service.Labels[labels.LabelSamePod]; ok && samePod != "" {
|
if samePod, ok := service.Labels[labels.LabelSamePod]; ok && samePod != "" {
|
||||||
podToMerge[samePod] = &service
|
podToMerge[service.Name] = &service
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the needed service for the container port
|
// create the needed service for the container port
|
||||||
|
// NOTE: ports from same-pod services are now added in generator.go after all services are processed
|
||||||
if len(service.Ports) > 0 {
|
if len(service.Ports) > 0 {
|
||||||
s := NewService(service, appName)
|
s := NewService(service, appName)
|
||||||
services[service.Name] = s
|
services[service.Name] = s
|
||||||
|
|||||||
@@ -79,6 +79,22 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// second pass, create services for services with ports (now podToMerge is fully populated)
|
||||||
|
for _, service := range project.Services {
|
||||||
|
if len(service.Ports) > 0 {
|
||||||
|
s := NewService(service, appName)
|
||||||
|
// add ports from same-pod services that target this service
|
||||||
|
for _, mergedSvc := range podToMerge {
|
||||||
|
if mergedSvc.Labels[labels.LabelSamePod] == service.Name {
|
||||||
|
for _, p := range mergedSvc.Ports {
|
||||||
|
s.AddPort(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
services[service.Name] = s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// now we have all deployments, we can create PVC if needed (it's separated from
|
// now we have all deployments, we can create PVC if needed (it's separated from
|
||||||
// the above loop because we need all deployments to not duplicate PVC for "same-pod" services)
|
// the above loop because we need all deployments to not duplicate PVC for "same-pod" services)
|
||||||
// bind static volumes
|
// bind static volumes
|
||||||
@@ -199,12 +215,9 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
|||||||
|
|
||||||
// generate all services
|
// generate all services
|
||||||
for _, s := range services {
|
for _, s := range services {
|
||||||
// add the service ports to the target service if it's a "same-pod" service
|
// skip same-pod services - they are merged into target deployments
|
||||||
if samePod, ok := podToMerge[s.service.Name]; ok {
|
if _, isSamePod := podToMerge[s.service.Name]; isSamePod {
|
||||||
// get the target service
|
continue
|
||||||
target := services[samePod.Name]
|
|
||||||
// merge the services
|
|
||||||
s.Spec.Ports = append(s.Spec.Ports, target.Spec.Ports...)
|
|
||||||
}
|
}
|
||||||
y, _ := s.Yaml()
|
y, _ := s.Yaml()
|
||||||
chart.Templates[s.Filename()] = &ChartTemplate{
|
chart.Templates[s.Filename()] = &ChartTemplate{
|
||||||
@@ -213,12 +226,11 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop all "same-pod" services
|
// drop all "same-pod" service templates (they are merged into target deployments)
|
||||||
for _, s := range podToMerge {
|
for name := range podToMerge {
|
||||||
// get the target service
|
// find the service for this same-pod service
|
||||||
target := services[s.Name]
|
if svc, ok := services[name]; ok {
|
||||||
if target != nil {
|
delete(chart.Templates, svc.Filename())
|
||||||
delete(chart.Templates, target.Filename())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user