Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression tests for sandbox pods when no CNI plugins are initialized #10771

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions integration/sandbox_run_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,41 @@ func sbserverSandboxInfo(id string) (*criapiv1.PodSandboxStatus, *types.SandboxI
return status, &info, nil
}

// TestRunPodSandboxNoCNIPlugins checks if the sandbox creation fails
// with the expected error message when no CNI plugins are initialized.
func TestRunPodSandboxNoCNIPlugins(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip()
}

t.Log("Init PodSandboxConfig with specific label")
labels := map[string]string{
t.Name(): "true",
}

sbConfig := PodSandboxConfig(t.Name(), "nocni", WithPodLabels(labels))
t.Log("Inject CNI plugin initialization failpoint")
conf := &failpointConf{
Add: "1*error(no CNI plugins initialized)",
}
injectCNIFailpoint(t, sbConfig, conf)

t.Log("Create a pod sandbox while having no CNI plugins initialized")
_, err := runtimeService.RunPodSandbox(sbConfig, failpointRuntimeHandler)
require.Error(t, err)
require.ErrorContains(t, err, "no CNI plugins initialized")

t.Log("No pods should be up, as CNI failure is expected to clean up the pod that was attempted to be created")
l, err := runtimeService.ListPodSandbox(&criapiv1.PodSandboxFilter{LabelSelector: labels})
require.NoError(t, err)
assert.Len(t, l, 0)

if len(l) > 0 {
t.Log("Cleanup leaky pod(s)")
cleanupPods(t, runtimeService)
}
}

func ensureCNIAddRunning(t *testing.T, sbName string) error {
return Eventually(func() (bool, error) {
pids, err := PidsOf(failpointCNIBinary)
Expand Down
Loading