mirror of
https://github.com/rancher/os.git
synced 2025-07-07 03:48:38 +00:00
Merge pull request #527 from imikushin/fix-bad-service-deps
Do not link to services that do not exist in the project
This commit is contained in:
commit
4df78bbca1
@ -14,32 +14,34 @@ type Service struct {
|
|||||||
*docker.Service
|
*docker.Service
|
||||||
deps map[string][]string
|
deps map[string][]string
|
||||||
context *docker.Context
|
context *docker.Context
|
||||||
|
project *project.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(factory *ServiceFactory, name string, serviceConfig *project.ServiceConfig, context *docker.Context) *Service {
|
func NewService(factory *ServiceFactory, name string, serviceConfig *project.ServiceConfig, context *docker.Context, project *project.Project) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
Service: docker.NewService(name, serviceConfig, context),
|
Service: docker.NewService(name, serviceConfig, context),
|
||||||
deps: factory.Deps,
|
deps: factory.Deps,
|
||||||
context: context,
|
context: context,
|
||||||
|
project: project,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) DependentServices() []project.ServiceRelationship {
|
func (s *Service) DependentServices() []project.ServiceRelationship {
|
||||||
rels := s.Service.DependentServices()
|
rels := s.Service.DependentServices()
|
||||||
for _, dep := range s.deps[s.Name()] {
|
for _, dep := range s.deps[s.Name()] {
|
||||||
rels = appendLink(rels, dep, true)
|
rels = appendLink(rels, dep, true, s.project)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.requiresSyslog() {
|
if s.requiresSyslog() {
|
||||||
rels = appendLink(rels, "syslog", false)
|
rels = appendLink(rels, "syslog", false, s.project)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.requiresUserDocker() {
|
if s.requiresUserDocker() {
|
||||||
// Linking to cloud-init is a hack really. The problem is we need to link to something
|
// Linking to cloud-init is a hack really. The problem is we need to link to something
|
||||||
// that will trigger a reload
|
// that will trigger a reload
|
||||||
rels = appendLink(rels, "cloud-init", false)
|
rels = appendLink(rels, "cloud-init", false, s.project)
|
||||||
} else if s.missingImage() {
|
} else if s.missingImage() {
|
||||||
rels = appendLink(rels, "network", false)
|
rels = appendLink(rels, "network", false, s.project)
|
||||||
}
|
}
|
||||||
return rels
|
return rels
|
||||||
}
|
}
|
||||||
@ -62,7 +64,10 @@ func (s *Service) requiresUserDocker() bool {
|
|||||||
return s.Config().Labels.MapParts()[config.SCOPE] != config.SYSTEM
|
return s.Config().Labels.MapParts()[config.SCOPE] != config.SYSTEM
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendLink(deps []project.ServiceRelationship, name string, optional bool) []project.ServiceRelationship {
|
func appendLink(deps []project.ServiceRelationship, name string, optional bool, p *project.Project) []project.ServiceRelationship {
|
||||||
|
if _, ok := p.Configs[name]; !ok {
|
||||||
|
return deps
|
||||||
|
}
|
||||||
rel := project.NewServiceRelationship(name, project.REL_TYPE_LINK)
|
rel := project.NewServiceRelationship(name, project.REL_TYPE_LINK)
|
||||||
rel.Optional = optional
|
rel.Optional = optional
|
||||||
return append(deps, rel)
|
return append(deps, rel)
|
||||||
|
@ -23,5 +23,5 @@ func (s *ServiceFactory) Create(project *project.Project, name string, serviceCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewService(s, name, serviceConfig, s.Context), nil
|
return NewService(s, name, serviceConfig, s.Context, project), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user