Skip to content

Commit

Permalink
Merge pull request #7207 from Luap99/pod/ctr-exists-error
Browse files Browse the repository at this point in the history
Improve error message when creating a pod/ctr with the same name
  • Loading branch information
openshift-merge-robot authored Aug 4, 2020
2 parents 93d6320 + 97b2b07 commit d4cf3c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions libpod/boltdb_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2347,11 +2347,19 @@ func (s *BoltState) AddPod(pod *Pod) error {
// Check if we already have something with the given ID and name
idExist := idsBkt.Get(podID)
if idExist != nil {
return errors.Wrapf(define.ErrPodExists, "ID %s is in use", pod.ID())
err = define.ErrPodExists
if allPodsBkt.Get(idExist) == nil {
err = define.ErrCtrExists
}
return errors.Wrapf(err, "ID \"%s\" is in use", pod.ID())
}
nameExist := namesBkt.Get(podName)
if nameExist != nil {
return errors.Wrapf(define.ErrPodExists, "name %s is in use", pod.Name())
err = define.ErrPodExists
if allPodsBkt.Get(nameExist) == nil {
err = define.ErrCtrExists
}
return errors.Wrapf(err, "name \"%s\" is in use", pod.Name())
}

// We are good to add the pod
Expand Down
12 changes: 10 additions & 2 deletions libpod/boltdb_state_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,19 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
// Check if we already have a container with the given ID and name
idExist := idsBucket.Get(ctrID)
if idExist != nil {
return errors.Wrapf(define.ErrCtrExists, "ID %s is in use", ctr.ID())
err = define.ErrCtrExists
if allCtrsBucket.Get(idExist) == nil {
err = define.ErrPodExists
}
return errors.Wrapf(err, "ID \"%s\" is in use", ctr.ID())
}
nameExist := namesBucket.Get(ctrName)
if nameExist != nil {
return errors.Wrapf(define.ErrCtrExists, "name %s is in use", ctr.Name())
err = define.ErrCtrExists
if allCtrsBucket.Get(nameExist) == nil {
err = define.ErrPodExists
}
return errors.Wrapf(err, "name \"%s\" is in use", ctr.Name())
}

// No overlapping containers
Expand Down

0 comments on commit d4cf3c5

Please sign in to comment.