mirror of https://github.com/containers/podman.git
Ensure pods are part of the set namespace when added
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
parent
7b30659629
commit
84afa32493
|
|
@ -542,6 +542,10 @@ func (s *InMemoryState) AddPod(pod *Pod) error {
|
|||
return errors.Wrapf(ErrPodRemoved, "pod %s is not valid and cannot be added", pod.ID())
|
||||
}
|
||||
|
||||
if err := s.checkNSMatch(pod.ID(), pod.Namespace()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, ok := s.pods[pod.ID()]; ok {
|
||||
return errors.Wrapf(ErrPodExists, "pod with ID %s already exists in state", pod.ID())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1790,6 +1790,47 @@ func TestAddPodCtrNameConflictFails(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAddPodSameNamespaceSucceeds(t *testing.T) {
|
||||
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
|
||||
testPod, err := getTestPod1(lockPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testPod.config.Namespace = "test1"
|
||||
|
||||
state.SetNamespace("test1")
|
||||
|
||||
err = state.AddPod(testPod)
|
||||
assert.NoError(t, err)
|
||||
|
||||
allPods, err := state.AllPods()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(allPods))
|
||||
|
||||
testPodsEqual(t, testPod, allPods[0])
|
||||
assert.Equal(t, testPod.valid, allPods[0].valid)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddPodDifferentNamespaceFails(t *testing.T) {
|
||||
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
|
||||
testPod, err := getTestPod1(lockPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testPod.config.Namespace = "test1"
|
||||
|
||||
state.SetNamespace("test2")
|
||||
|
||||
err = state.AddPod(testPod)
|
||||
assert.Error(t, err)
|
||||
|
||||
state.SetNamespace("")
|
||||
|
||||
allPods, err := state.AllPods()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 0, len(allPods))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemovePodInvalidPodErrors(t *testing.T) {
|
||||
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
|
||||
err := state.RemovePod(&Pod{config: &PodConfig{}})
|
||||
|
|
|
|||
Loading…
Reference in New Issue