mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +00:00
Error if there are duplicate service names
Continue to allow onboot to have duplicates as we do not run simultaneously so that is ok (and we number them anyway), but services are run together so we will get a runtime error if duplicated as this is the containerd/runc id. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
ec7e73b304
commit
3ee4fdc43a
@ -199,7 +199,10 @@ func build(args []string) {
|
||||
if err != nil {
|
||||
log.Fatalf("Invalid config: %v", err)
|
||||
}
|
||||
m = moby.AppendConfig(m, c)
|
||||
m, err = moby.AppendConfig(m, c)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot append config files: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if *buildDisableTrust {
|
||||
|
@ -105,6 +105,18 @@ func convert(i interface{}) interface{} {
|
||||
return i
|
||||
}
|
||||
|
||||
func uniqueServices(m Moby) error {
|
||||
// service names must be unique, as they run as simultaneous containers
|
||||
names := map[string]bool{}
|
||||
for _, s := range m.Services {
|
||||
if names[s.Name] {
|
||||
return fmt.Errorf("duplicate service name: %s", s.Name)
|
||||
}
|
||||
names[s.Name] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewConfig parses a config file
|
||||
func NewConfig(config []byte) (Moby, error) {
|
||||
m := Moby{}
|
||||
@ -140,11 +152,15 @@ func NewConfig(config []byte) (Moby, error) {
|
||||
return m, err
|
||||
}
|
||||
|
||||
if err := uniqueServices(m); err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AppendConfig appends two configs.
|
||||
func AppendConfig(m0, m1 Moby) Moby {
|
||||
func AppendConfig(m0, m1 Moby) (Moby, error) {
|
||||
moby := m0
|
||||
if m1.Kernel.Image != "" {
|
||||
moby.Kernel.Image = m1.Kernel.Image
|
||||
@ -159,7 +175,11 @@ func AppendConfig(m0, m1 Moby) Moby {
|
||||
moby.Trust.Image = append(moby.Trust.Image, m1.Trust.Image...)
|
||||
moby.Trust.Org = append(moby.Trust.Org, m1.Trust.Org...)
|
||||
|
||||
return moby
|
||||
if err := uniqueServices(moby); err != nil {
|
||||
return moby, err
|
||||
}
|
||||
|
||||
return moby, nil
|
||||
}
|
||||
|
||||
// NewImage validates an parses yaml or json for a Image
|
||||
|
Loading…
Reference in New Issue
Block a user