Skip to content

Commit 69798a0

Browse files
committed
Add additional checks during DNS network attach
1 parent 0fb8be0 commit 69798a0

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

netmaster/master/netmaster.go

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func startServiceContainer(tenantName string) error {
264264
containerID, err := docker.CreateContainer(containerConfig, getDNSName(tenantName), nil)
265265
if err != nil {
266266
log.Errorf("Error creating DNS container for tenant: %s. Error: %s", tenantName, err)
267+
return err
267268
}
268269

269270
hostConfig := &dockerclient.HostConfig{

netmaster/master/network.go

+34-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package master
1717

1818
import (
1919
"errors"
20-
"fmt"
2120
"net"
2221
"strings"
2322

@@ -171,27 +170,48 @@ func attachServiceContainer(tenantName, networkName string, stateDriver core.Sta
171170
return err
172171
}
173172

173+
cinfo, err := docker.InspectContainer(contName)
174+
if err != nil {
175+
if strings.Contains(err.Error(), "no such id") {
176+
// DNS container not started for this tenant. Start skydns container
177+
err = startServiceContainer(tenantName)
178+
if err != nil {
179+
log.Warnf("Error starting service container. "+
180+
"Continuing without DNS provider. Error: %v", err)
181+
return nil
182+
}
183+
}
184+
}
185+
186+
// If it's not in running state, restart the container.
187+
// This case can occur if the host is reloaded
188+
if !cinfo.State.Running {
189+
log.Debugf("Container %s not running. Restarting the conttainer", contName)
190+
err = docker.RestartContainer(contName, 0)
191+
if err != nil {
192+
log.Warnf("Error restarting service container %s. "+
193+
"Continuing without DNS provider. Error: %v",
194+
contName, err)
195+
return nil
196+
}
197+
198+
// Refetch container info after restart
199+
cinfo, err = docker.InspectContainer(contName)
200+
}
201+
202+
log.Debugf("Container info: %+v\n Hostconfig: %+v", cinfo, cinfo.HostConfig)
203+
174204
// Trim default tenant
175205
dnetName := docknet.GetDocknetName(tenantName, networkName, "")
176206

177207
err = docker.ConnectNetwork(dnetName, contName)
178208
if err != nil {
179-
log.Errorf("Could not attach container(%s) to network %s. Error: %s",
209+
log.Warnf("Could not attach container(%s) to network %s. "+
210+
"Continuing with DNS provider. Error: %s",
180211
contName, dnetName, err)
181-
return fmt.Errorf("Could not attach container(%s) to network %s."+
182-
"Please make sure %s container is up.",
183-
contName, dnetName, contName)
184-
}
185-
186-
// inspect the container
187-
cinfo, err := docker.InspectContainer(contName)
188-
if err != nil {
189-
log.Errorf("Error inspecting the container %s. Err: %v", contName, err)
190-
return err
212+
return nil
191213
}
192214

193-
log.Debugf("Container info: %+v\n Hostconfig: %+v", cinfo, cinfo.HostConfig)
194-
195215
ninfo, err := docker.InspectNetwork(dnetName)
196216
if err != nil {
197217
log.Errorf("Error getting network info for %s. Err: %v", dnetName, err)

0 commit comments

Comments
 (0)