Add a "ignore" label to skip a service

This commit is contained in:
2022-05-05 10:22:02 +02:00
parent 910933e5f3
commit 053292f37c
4 changed files with 80 additions and 47 deletions

View File

@@ -45,9 +45,35 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, composeFi
// Manage services, avoid linked pods and store all services port in servicesMap
avoids := make(map[string]bool)
skips := make(map[string]bool)
for _, s := range p.Data.Services {
if s.Labels[helm.LABEL_IGNORE] == "true" {
skips[s.Name] = true
}
}
// remove skipped services
for s := range skips {
for i, service := range p.Data.Services {
if service.Name == s {
p.Data.Services = append(p.Data.Services[:i], p.Data.Services[i+1:]...)
break
}
}
}
for i, service := range p.Data.Services {
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 ports, ok := service.Labels[helm.LABEL_PORT]; ok {
if service.Ports == nil {
service.Ports = make([]types.ServicePortConfig, 0)