Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Recreate a container if inexplicably deleted
in CI, containers sometimes get purged
  • Loading branch information
matthewmcneely committed Oct 20, 2025
commit 34d2da6edc77bcafdef95da05bf4e4dd7d520217
9 changes: 9 additions & 0 deletions dgraphtest/dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type dnode interface {
alphaURL(*LocalCluster) (string, error)
zeroURL(*LocalCluster) (string, error)
changeStatus(bool)
setContainerID(string)
}

type zero struct {
Expand Down Expand Up @@ -170,6 +171,10 @@ func (z *zero) changeStatus(isRunning bool) {
z.isRunning = isRunning
}

func (z *zero) setContainerID(cid string) {
z.containerID = cid
}

func (z *zero) assignURL(c *LocalCluster) (string, error) {
publicPort, err := publicPort(c.dcli, z, zeroHttpPort)
if err != nil {
Expand Down Expand Up @@ -364,6 +369,10 @@ func (a *alpha) changeStatus(isRunning bool) {
a.isRunning = isRunning
}

func (a *alpha) setContainerID(cid string) {
a.containerID = cid
}

func (a *alpha) zeroURL(c *LocalCluster) (string, error) {
return "", errNotImplemented
}
Expand Down
16 changes: 16 additions & 0 deletions dgraphtest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,22 @@ func (c *LocalCluster) StartAlpha(id int) error {
func (c *LocalCluster) startContainer(dc dnode) error {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()

// verify the container still exists
_, err := c.dcli.ContainerInspect(ctx, dc.cid())
if err != nil {
log.Printf("[WARNING] container %s (ID: %s) not found, attempting to recreate", dc.cname(), dc.cid())
newCID, createErr := c.createContainer(dc)
if createErr != nil {
return errors.Wrapf(createErr, "error recreating missing container [%v]", dc.cname())
}
switch node := dc.(type) {
case *alpha, *zero:
node.setContainerID(newCID)
}
log.Printf("[INFO] successfully recreated container %s with new ID: %s", dc.cname(), newCID)
}

if err := c.dcli.ContainerStart(ctx, dc.cid(), container.StartOptions{}); err != nil {
return errors.Wrapf(err, "error starting container [%v]", dc.cname())
}
Expand Down
Loading