Merge pull request #83 from mrunalp/ctr_list_fix
Remove containers from in-memory state on pod remove
This commit is contained in:
commit
b0e23c4a24
2 changed files with 35 additions and 2 deletions
|
@ -290,7 +290,8 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
|
||||||
return nil, fmt.Errorf("specified sandbox not found: %s", sandboxID)
|
return nil, fmt.Errorf("specified sandbox not found: %s", sandboxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
podInfraContainer := sb.name + "-infra"
|
podInfraContainerName := sb.name + "-infra"
|
||||||
|
var podInfraContainer *oci.Container
|
||||||
|
|
||||||
// Delete all the containers in the sandbox
|
// Delete all the containers in the sandbox
|
||||||
for _, c := range sb.containers.List() {
|
for _, c := range sb.containers.List() {
|
||||||
|
@ -309,13 +310,17 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
|
||||||
return nil, fmt.Errorf("failed to delete container %s in sandbox %s: %v", c.Name(), sandboxID, err)
|
return nil, fmt.Errorf("failed to delete container %s in sandbox %s: %v", c.Name(), sandboxID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if podInfraContainer == c.Name() {
|
if podInfraContainerName == c.Name() {
|
||||||
|
podInfraContainer = c
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
containerDir := filepath.Join(s.runtime.ContainerDir(), c.Name())
|
containerDir := filepath.Join(s.runtime.ContainerDir(), c.Name())
|
||||||
if err := os.RemoveAll(containerDir); err != nil {
|
if err := os.RemoveAll(containerDir); err != nil {
|
||||||
return nil, fmt.Errorf("failed to remove container %s directory: %v", c.Name(), err)
|
return nil, fmt.Errorf("failed to remove container %s directory: %v", c.Name(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.removeContainer(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the files related to the sandbox
|
// Remove the files related to the sandbox
|
||||||
|
@ -323,6 +328,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
|
||||||
if err := os.RemoveAll(podSandboxDir); err != nil {
|
if err := os.RemoveAll(podSandboxDir); err != nil {
|
||||||
return nil, fmt.Errorf("failed to remove sandbox %s directory: %v", sandboxID, err)
|
return nil, fmt.Errorf("failed to remove sandbox %s directory: %v", sandboxID, err)
|
||||||
}
|
}
|
||||||
|
s.removeContainer(podInfraContainer)
|
||||||
|
|
||||||
s.releasePodName(sb.name)
|
s.releasePodName(sb.name)
|
||||||
s.removeSandbox(sandboxID)
|
s.removeSandbox(sandboxID)
|
||||||
|
|
|
@ -48,10 +48,16 @@ function teardown() {
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
echo "$output"
|
echo "$output"
|
||||||
pod_id="$output"
|
pod_id="$output"
|
||||||
|
run ocic pod list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic ctr create --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
run ocic ctr create --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
ctr_id="$output"
|
ctr_id="$output"
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic ctr status --id "$ctr_id"
|
run ocic ctr status --id "$ctr_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
@ -61,21 +67,42 @@ function teardown() {
|
||||||
run ocic ctr status --id "$ctr_id"
|
run ocic ctr status --id "$ctr_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic ctr stop --id "$ctr_id"
|
run ocic ctr stop --id "$ctr_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
run ocic ctr status --id "$ctr_id"
|
run ocic ctr status --id "$ctr_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic ctr remove --id "$ctr_id"
|
run ocic ctr remove --id "$ctr_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic pod stop --id "$pod_id"
|
run ocic pod stop --id "$pod_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic pod list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
run ocic pod remove --id "$pod_id"
|
run ocic pod remove --id "$pod_id"
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic pod list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
run ocic ctr list
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
stop_ocid
|
stop_ocid
|
||||||
cleanup_pods
|
cleanup_pods
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue