@@ -17,7 +17,6 @@ package master
17
17
18
18
import (
19
19
"errors"
20
- "fmt"
21
20
"net"
22
21
"strings"
23
22
@@ -171,27 +170,48 @@ func attachServiceContainer(tenantName, networkName string, stateDriver core.Sta
171
170
return err
172
171
}
173
172
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
+
174
204
// Trim default tenant
175
205
dnetName := docknet .GetDocknetName (tenantName , networkName , "" )
176
206
177
207
err = docker .ConnectNetwork (dnetName , contName )
178
208
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" ,
180
211
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
191
213
}
192
214
193
- log .Debugf ("Container info: %+v\n Hostconfig: %+v" , cinfo , cinfo .HostConfig )
194
-
195
215
ninfo , err := docker .InspectNetwork (dnetName )
196
216
if err != nil {
197
217
log .Errorf ("Error getting network info for %s. Err: %v" , dnetName , err )
0 commit comments