Skip to content

Commit 536bece

Browse files
committed
container:xx are not constrained to containers managed by compose
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 813d4cc commit 536bece

File tree

3 files changed

+0
-43
lines changed

3 files changed

+0
-43
lines changed

loader/validate.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ func checkConsistency(project *types.Project) error {
4545
}
4646
}
4747

48-
if strings.HasPrefix(s.NetworkMode, types.ContainerPrefix) {
49-
containerName := s.NetworkMode[len(types.ContainerPrefix):]
50-
if _, err := project.GetByContainerName(containerName); err != nil {
51-
return fmt.Errorf("service with container_name %q not found for network_mode 'container:%s'", containerName, containerName)
52-
}
53-
}
54-
5548
for _, volume := range s.Volumes {
5649
switch volume.Type {
5750
case types.VolumeTypeVolume:

loader/validate_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,4 @@ func TestValidateNetworkMode(t *testing.T) {
138138
err := checkConsistency(project)
139139
assert.NilError(t, err)
140140
})
141-
142-
t.Run("network_mode container fail", func(t *testing.T) {
143-
project := &types.Project{
144-
Services: types.Services([]types.ServiceConfig{
145-
{
146-
Name: "myservice1",
147-
Image: "scratch",
148-
},
149-
{
150-
Name: "myservice2",
151-
Image: "scratch",
152-
NetworkMode: "container:nonexistentcontainer",
153-
},
154-
}),
155-
}
156-
err := checkConsistency(project)
157-
assert.Error(t, err, `service with container_name "nonexistentcontainer" not found for network_mode 'container:nonexistentcontainer'`)
158-
})
159141
}

types/project.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,6 @@ func (p Project) ConfigNames() []string {
9494
return names
9595
}
9696

97-
func (p Project) GetByContainerName(names ...string) (Services, error) {
98-
if len(names) == 0 {
99-
return p.Services, nil
100-
}
101-
services := Services{}
102-
outLoop:
103-
for _, name := range names {
104-
for _, s := range p.Services {
105-
if name == s.ContainerName {
106-
services = append(services, s)
107-
continue outLoop
108-
}
109-
}
110-
return nil, fmt.Errorf("service with container_name %q could not be found", name)
111-
}
112-
return services, nil
113-
}
114-
11597
// GetServices retrieve services by names, or return all services if no name specified
11698
func (p Project) GetServices(names ...string) (Services, error) {
11799
if len(names) == 0 {

0 commit comments

Comments
 (0)