Skip to content

Commit

Permalink
network: pass pod UID to ocicni when performing network operations
Browse files Browse the repository at this point in the history
This allows plugins to more correctly cancel long-running sandbox
operations when the pod is deleted/re-created in the Kube API
while the call is ongoing.

Signed-off-by: Dan Williams <dcbw@redhat.com>
  • Loading branch information
dcbw committed Jun 23, 2021
1 parent 860edbe commit 6e8d370
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/sandbox_network.go
Expand Up @@ -221,6 +221,7 @@ func (s *Server) newPodNetwork(sb *sandbox.Sandbox) (ocicni.PodNetwork, error) {
return ocicni.PodNetwork{
Name: sb.KubeName(),
Namespace: sb.Namespace(),
UID: sb.Metadata().UID,
Networks: []ocicni.NetAttachment{},
ID: sb.ID(),
NetNS: sb.NetNsPath(),
Expand Down
5 changes: 5 additions & 0 deletions test/cni_plugin_helper.bash
Expand Up @@ -20,6 +20,8 @@ for arg in "${array[@]}"; do
K8S_POD_NAMESPACE="${item[1]}"
elif [[ "${item[0]}" == "K8S_POD_NAME" ]]; then
K8S_POD_NAME="${item[1]}"
elif [[ "${item[0]}" == "K8S_POD_UID" ]]; then
K8S_POD_UID="${item[1]}"
fi
done

Expand All @@ -29,6 +31,8 @@ elif [[ -z "${K8S_POD_NAMESPACE}" ]]; then
exit 1
elif [[ -z "${K8S_POD_NAME}" ]]; then
exit 1
elif [[ -z "${K8S_POD_UID}" ]]; then
exit 1
fi

TEST_DIR=%TEST_DIR%
Expand All @@ -37,6 +41,7 @@ cat <<EOT >"$TEST_DIR/plugin_test_args.out"
FOUND_CNI_CONTAINERID="${CNI_CONTAINERID}"
FOUND_K8S_POD_NAMESPACE="${K8S_POD_NAMESPACE}"
FOUND_K8S_POD_NAME="${K8S_POD_NAME}"
FOUND_K8S_POD_UID="${K8S_POD_UID}"
EOT

# shellcheck disable=1090
Expand Down
1 change: 1 addition & 0 deletions test/network.bats
Expand Up @@ -76,6 +76,7 @@ function teardown() {
[ "$FOUND_CNI_CONTAINERID" != "podsandbox1" ]
[ "$FOUND_K8S_POD_NAMESPACE" = "redhat.test.crio" ]
[ "$FOUND_K8S_POD_NAME" = "podsandbox1" ]
[ "$FOUND_K8S_POD_UID" = "redhat-test-crio" ]
}

@test "Connect to pod hostport from the host" {
Expand Down

0 comments on commit 6e8d370

Please sign in to comment.