Skip to content

Commit a73be7c

Browse files
authored
skipping unreachable containers when deploying zdbs (#72)
Signed-off-by: Ashraf Fouda <[email protected]>
1 parent 3a62ad6 commit a73be7c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pkg/primitives/zdb/zdb.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (p *Manager) zdbProvisionImpl(ctx context.Context, wl *gridtypes.WorkloadWi
168168
if err != nil {
169169
return zos.ZDBResult{}, errors.Wrap(err, "failed to find IP address on zdb0 interface")
170170
}
171-
171+
log.Info().Msg("found a container matching this namespace of the requested zdb")
172172
return zos.ZDBResult{
173173
Namespace: nsID,
174174
IPs: ipsToString(containerIPs),
@@ -189,8 +189,24 @@ func (p *Manager) zdbProvisionImpl(ctx context.Context, wl *gridtypes.WorkloadWi
189189

190190
var cont tZDBContainer
191191
if len(candidates) > 0 {
192-
cont = candidates[0]
193-
} else {
192+
// try to find the first reachable zdb instance
193+
for _, c := range candidates {
194+
cl := zdbConnection(pkg.ContainerID(c.Name))
195+
if err := cl.Connect(); err == nil {
196+
_ = cl.Close()
197+
log.Debug().Str("container name", c.Name).Msg(
198+
"found running container suitable for provisioning the namespace of the requested zdb",
199+
)
200+
cont = c
201+
break
202+
}
203+
log.Debug().Str("container name", c.Name).Msg("zdb container is not reachable")
204+
_ = cl.Close()
205+
}
206+
}
207+
208+
// if no reachable candidate was found, allocate a new device and start a container
209+
if cont.Name == "" {
194210
// allocate new disk
195211
device, err := storage.DeviceAllocate(ctx, config.Size)
196212
if err != nil {
@@ -869,6 +885,7 @@ func socketFile(containerID pkg.ContainerID) string {
869885
// mock it in testing.
870886
var zdbConnection = func(id pkg.ContainerID) zdb.Client {
871887
socket := fmt.Sprintf("unix://%s@%s", string(id), socketFile(id))
888+
log.Debug().Str("Socket", socket).Msg("connecting to zdb container on socket")
872889
return zdb.New(socket)
873890
}
874891

0 commit comments

Comments
 (0)