diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-08 15:36:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 15:36:58 +0100 |
commit | a58c0bb39ada24ea21204702d07117bf24d24156 (patch) | |
tree | 3d4c8d3b1832e9dc9bbed261515c50e1db701db5 /libpod/container_internal.go | |
parent | d6ef903164512e6fa7903bb0b85a1852117df37b (diff) | |
parent | 6444f2402839330f977cfe1c701ca331a915047b (diff) | |
download | podman-a58c0bb39ada24ea21204702d07117bf24d24156.tar.gz podman-a58c0bb39ada24ea21204702d07117bf24d24156.tar.bz2 podman-a58c0bb39ada24ea21204702d07117bf24d24156.zip |
Merge pull request #12137 from vrothberg/fix-11735
pod/container create: resolve conflicts of generated names
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 19b48e14b..fbc2c1f38 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -496,9 +496,27 @@ func (c *Container) setupStorage(ctx context.Context) error { c.setupStorageMapping(&options.IDMappingOptions, &c.config.IDMappings) - containerInfo, err := c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, options) - if err != nil { - return errors.Wrapf(err, "error creating container storage") + // Unless the user has specified a name, use a randomly generated one. + // Note that name conflicts may occur (see #11735), so we need to loop. + generateName := c.config.Name == "" + var containerInfo ContainerInfo + var containerInfoErr error + for { + if generateName { + name, err := c.runtime.generateName() + if err != nil { + return err + } + c.config.Name = name + } + containerInfo, containerInfoErr = c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, options) + + if !generateName || errors.Cause(containerInfoErr) != storage.ErrDuplicateName { + break + } + } + if containerInfoErr != nil { + return errors.Wrapf(containerInfoErr, "error creating container storage") } // only reconfig IDMappings if layer was mounted from storage |