Use traefik and fix major problems with same-pods and cronjobs #185

Open
metal3d wants to merge 7 commits from feature/move-to-traefik into master
2 changed files with 26 additions and 13 deletions
Showing only changes of commit 99d8173c15 - Show all commits

View File

@@ -229,10 +229,11 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
// 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.
if samePod, ok := service.Labels[labels.LabelSamePod]; ok && samePod != "" {
podToMerge[samePod] = &service
podToMerge[service.Name] = &service
}
// 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 {
s := NewService(service, appName)
services[service.Name] = s

View File

@@ -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
// the above loop because we need all deployments to not duplicate PVC for "same-pod" services)
// bind static volumes
@@ -199,12 +215,9 @@ func Generate(project *types.Project) (*HelmChart, error) {
// generate all services
for _, s := range services {
// add the service ports to the target service if it's a "same-pod" service
if samePod, ok := podToMerge[s.service.Name]; ok {
// get the target service
target := services[samePod.Name]
// merge the services
s.Spec.Ports = append(s.Spec.Ports, target.Spec.Ports...)
// skip same-pod services - they are merged into target deployments
if _, isSamePod := podToMerge[s.service.Name]; isSamePod {
continue
}
y, _ := s.Yaml()
chart.Templates[s.Filename()] = &ChartTemplate{
@@ -213,12 +226,11 @@ func Generate(project *types.Project) (*HelmChart, error) {
}
}
// drop all "same-pod" services
for _, s := range podToMerge {
// get the target service
target := services[s.Name]
if target != nil {
delete(chart.Templates, target.Filename())
// drop all "same-pod" service templates (they are merged into target deployments)
for name := range podToMerge {
// find the service for this same-pod service
if svc, ok := services[name]; ok {
delete(chart.Templates, svc.Filename())
}
}