Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/sandbox_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *types.RemovePodSandb
}
}

// Cleanup network resources for this pod
if err := s.networkStop(ctx, sb); err != nil {
return errors.Wrap(err, "stop pod network")
}

s.removeInfraContainer(podInfraContainer)
podInfraContainer.CleanupConmonCgroup()

Expand Down
28 changes: 28 additions & 0 deletions test/network.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bats

# vim:set ft=bash :

load helpers

function setup() {
Expand Down Expand Up @@ -140,3 +142,29 @@ function check_networking() {

check_networking
}

@test "Clean up network if pod sandbox gets killed" {
start_crio

CNI_RESULTS_DIR=/var/lib/cni/results
POD=$(crictl runp "$TESTDATA/sandbox_config.json")

# CNI result is there
# shellcheck disable=SC2010
[[ $(ls $CNI_RESULTS_DIR | grep "$POD") != "" ]]

# kill the sandbox
runtime kill "$POD" KILL

# wait for the pod to be killed
while crictl inspectp "$POD" | jq -e '.status.state != "SANDBOX_NOTREADY"' > /dev/null; do
echo Waiting for sandbox to be stopped
done

# now remove the sandbox
crictl rmp "$POD"

# CNI result is gone
# shellcheck disable=SC2010
[[ $(ls $CNI_RESULTS_DIR | grep "$POD") == "" ]]
}