Skip to content

Commit 7bfbd31

Browse files
committed
fix: Add the logic to clean up an orphaned etchosts directory
This commit adds the logic to clean up an orphaned etchosts directory for the container that failed to create. Signed-off-by: Hayato Kiwata <[email protected]>
1 parent e3d2710 commit 7bfbd31

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/cmd/container/create.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,17 @@ func generateGcFunc(ctx context.Context, container containerd.Container, ns, id,
888888
if netGcErr != nil {
889889
log.G(ctx).WithError(netGcErr).Warnf("failed to revert container %q networking settings", id)
890890
}
891+
} else {
892+
hs, err := hostsstore.New(dataStore, internalLabels.namespace)
893+
if err != nil {
894+
log.G(ctx).WithError(err).Warnf("failed to instantiate hostsstore for %q", internalLabels.namespace)
895+
} else {
896+
if _, err := hs.HostsPath(id); err != nil {
897+
log.G(ctx).WithError(err).Warnf("an etchosts directory for container %q dosen't exist", id)
898+
} else if err = hs.Delete(id); err != nil {
899+
log.G(ctx).WithError(err).Warnf("failed to remove an etchosts directory for container %q", id)
900+
}
901+
}
891902
}
892903

893904
ipc, ipcErr := ipcutil.DecodeIPCLabel(internalLabels.ipc)

0 commit comments

Comments
 (0)