Skip to content

Commit 39d6763

Browse files
committed
Merge pull request juju#624 from wallyworld/container-startup-trunk
Merge pull request juju#623 from wallyworld/container-startup Container startup tweaks Maybe fixes: https://bugs.launchpad.net/juju-core/+bug/1362360 We need extra debugging to see what's going on. Deferring the stopping of the worker might help.
2 parents e338c9e + 531a0aa commit 39d6763

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

worker/provisioner/container_initialisation.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,33 +106,41 @@ func (cs *ContainerSetup) Handle(containerIds []string) (resultError error) {
106106
return resultError
107107
}
108108

109-
func (cs *ContainerSetup) initialiseAndStartProvisioner(containerType instance.ContainerType) error {
109+
func (cs *ContainerSetup) initialiseAndStartProvisioner(containerType instance.ContainerType) (resultError error) {
110110
// Flag that this container type has been handled.
111111
atomic.StoreInt32(cs.setupDone[containerType], 1)
112112

113-
if atomic.AddInt32(&cs.numberProvisioners, 1) == int32(len(cs.supportedContainers)) {
114-
// We only care about the initial container creation.
115-
// This worker has done its job so stop it.
116-
// We do not expect there will be an error, and there's not much we can do anyway.
117-
if err := cs.runner.StopWorker(cs.workerName); err != nil {
118-
logger.Warningf("stopping machine agent container watcher: %v", err)
113+
defer func() {
114+
if resultError != nil {
115+
logger.Warningf("not stopping machine agent container watcher due to error: %v", resultError)
116+
return
119117
}
120-
}
118+
if atomic.AddInt32(&cs.numberProvisioners, 1) == int32(len(cs.supportedContainers)) {
119+
// We only care about the initial container creation.
120+
// This worker has done its job so stop it.
121+
// We do not expect there will be an error, and there's not much we can do anyway.
122+
if err := cs.runner.StopWorker(cs.workerName); err != nil {
123+
logger.Warningf("stopping machine agent container watcher: %v", err)
124+
}
125+
}
126+
}()
121127

128+
logger.Debugf("setup and start provisioner for %s containers", containerType)
122129
if initialiser, broker, err := cs.getContainerArtifacts(containerType); err != nil {
123-
return fmt.Errorf("initialising container infrastructure on host machine: %v", err)
130+
return errors.Annotate(err, "initialising container infrastructure on host machine")
124131
} else {
125132
if err := cs.runInitialiser(containerType, initialiser); err != nil {
126-
return fmt.Errorf("setting up container dependencies on host machine: %v", err)
133+
return errors.Annotate(err, "setting up container dependencies on host machine")
127134
}
128135
return StartProvisioner(cs.runner, containerType, cs.provisioner, cs.config, broker)
129136
}
130137
}
131138

132139
// runInitialiser runs the container initialiser with the initialisation hook held.
133140
func (cs *ContainerSetup) runInitialiser(containerType instance.ContainerType, initialiser container.Initialiser) error {
141+
logger.Debugf("running initialiser for %s containers", containerType)
134142
if err := cs.initLock.Lock(fmt.Sprintf("initialise-%s", containerType)); err != nil {
135-
return fmt.Errorf("failed to acquire initialization lock: %v", err)
143+
return errors.Annotate(err, "failed to acquire initialization lock")
136144
}
137145
defer cs.initLock.Unlock()
138146
return initialiser.Initialise()
@@ -145,6 +153,7 @@ func (cs *ContainerSetup) TearDown() error {
145153
}
146154

147155
func (cs *ContainerSetup) getContainerArtifacts(containerType instance.ContainerType) (container.Initialiser, environs.InstanceBroker, error) {
156+
logger.Debugf("finding tools for %s containers", containerType)
148157
tag := cs.config.Tag()
149158
machineTag, ok := tag.(names.MachineTag)
150159
if !ok {

0 commit comments

Comments
 (0)