Remove useless temporary slices
This commit is contained in:
@@ -52,42 +52,25 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make(map[string]HelmFileGenerator)
|
generators := make(map[string]HelmFileGenerator)
|
||||||
|
|
||||||
// Manage services, avoid linked pods and store all services port in servicesMap
|
|
||||||
avoids := make(map[string]bool)
|
|
||||||
|
|
||||||
// Manage services to not export
|
|
||||||
skips := make(map[string]bool)
|
|
||||||
|
|
||||||
// remove ignored services
|
|
||||||
for _, s := range p.Data.Services {
|
|
||||||
if s.Labels[helm.LABEL_IGNORE] == "true" {
|
|
||||||
skips[s.Name] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove skipped services from the parsed data
|
// remove skipped services from the parsed data
|
||||||
for s := range skips {
|
for i, service := range p.Data.Services {
|
||||||
for i, service := range p.Data.Services {
|
if v, ok := service.Labels[helm.LABEL_IGNORE]; !ok || v != "true" {
|
||||||
if service.Name == s {
|
continue
|
||||||
p.Data.Services = append(p.Data.Services[:i], p.Data.Services[i+1:]...)
|
}
|
||||||
i--
|
p.Data.Services = append(p.Data.Services[:i], p.Data.Services[i+1:]...)
|
||||||
break
|
i--
|
||||||
}
|
|
||||||
|
// find this service in others as "depends_on" and remove it
|
||||||
|
for _, service2 := range p.Data.Services {
|
||||||
|
delete(service2.DependsOn, service.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, service := range p.Data.Services {
|
for i, service := range p.Data.Services {
|
||||||
n := service.Name
|
n := service.Name
|
||||||
|
|
||||||
// if the service depends on a skipped service, remove the link
|
|
||||||
for dep := range service.DependsOn {
|
|
||||||
if skips[dep] {
|
|
||||||
delete(service.DependsOn, dep)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the service port is declared in labels, add it to the service.
|
// if the service port is declared in labels, add it to the service.
|
||||||
if ports, ok := service.Labels[helm.LABEL_PORT]; ok {
|
if ports, ok := service.Labels[helm.LABEL_PORT]; ok {
|
||||||
if service.Ports == nil {
|
if service.Ports == nil {
|
||||||
@@ -115,15 +98,13 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid linked pods
|
|
||||||
if _, ok := service.Labels[helm.LABEL_SAMEPOD]; ok {
|
|
||||||
avoids[n] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// manage emptyDir volumes
|
// manage emptyDir volumes
|
||||||
if empty, ok := service.Labels[helm.LABEL_EMPTYDIRS]; ok {
|
if empty, ok := service.Labels[helm.LABEL_EMPTYDIRS]; ok {
|
||||||
//split empty list by coma
|
//split empty list by coma
|
||||||
emptyDirs := strings.Split(empty, ",")
|
emptyDirs := strings.Split(empty, ",")
|
||||||
|
for i, emptyDir := range emptyDirs {
|
||||||
|
emptyDirs[i] = strings.TrimSpace(emptyDir)
|
||||||
|
}
|
||||||
//append them in EmptyDirs
|
//append them in EmptyDirs
|
||||||
EmptyDirs = append(EmptyDirs, emptyDirs...)
|
EmptyDirs = append(EmptyDirs, emptyDirs...)
|
||||||
}
|
}
|
||||||
@@ -131,15 +112,17 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for all services in linked map, and not in avoids map, generate the service
|
// for all services in linked map, and not in samePods map, generate the service
|
||||||
for _, s := range p.Data.Services {
|
for _, s := range p.Data.Services {
|
||||||
name := s.Name
|
name := s.Name
|
||||||
|
|
||||||
if _, found := avoids[name]; found {
|
// do not make a deployment for services declared to be in the same pod than another
|
||||||
|
if _, ok := s.Labels[helm.LABEL_SAMEPOD]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find services that is in the same pod
|
||||||
linked := make(map[string]types.ServiceConfig, 0)
|
linked := make(map[string]types.ServiceConfig, 0)
|
||||||
// find service
|
|
||||||
for _, service := range p.Data.Services {
|
for _, service := range p.Data.Services {
|
||||||
n := service.Name
|
n := service.Name
|
||||||
if linkname, ok := service.Labels[helm.LABEL_SAMEPOD]; ok && linkname == name {
|
if linkname, ok := service.Labels[helm.LABEL_SAMEPOD]; ok && linkname == name {
|
||||||
@@ -147,15 +130,15 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
files[name] = CreateReplicaObject(name, s, linked)
|
generators[name] = CreateReplicaObject(name, s, linked)
|
||||||
}
|
}
|
||||||
|
|
||||||
// to generate notes, we need to keep an Ingresses list
|
// to generate notes, we need to keep an Ingresses list
|
||||||
ingresses := make(map[string]*helm.Ingress)
|
ingresses := make(map[string]*helm.Ingress)
|
||||||
|
|
||||||
for n, generator := range files {
|
for n, generator := range generators { // generators is a map : name -> generator
|
||||||
for helmFile := range generator {
|
for helmFile := range generator { // generator is a chan
|
||||||
if helmFile == nil {
|
if helmFile == nil { // generator finished
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
kind := helmFile.(helm.Kinded).Get()
|
kind := helmFile.(helm.Kinded).Get()
|
||||||
|
Reference in New Issue
Block a user