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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/1.6] CRI: Fix no CNI info for pod sandbox on restart #7848

Merged
merged 1 commit into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration/restart_test.go
Expand Up @@ -191,6 +191,21 @@ func TestContainerdRestart(t *testing.T) {
if s.id == loaded.Id {
t.Logf("Checking sandbox state for '%s'", s.name)
assert.Equal(t, s.state, loaded.State)

// See https://github.com/containerd/containerd/issues/7843 for details.
// Test that CNI result and sandbox IPs are still present after restart.
if loaded.State == runtime.PodSandboxState_SANDBOX_READY {
status, info, err := SandboxInfo(loaded.Id)
require.NoError(t, err)

// Check that the NetNS didn't close on us, that we still have
// the CNI result, and that we still have the IP we were given
// for this pod.
require.False(t, info.NetNSClosed)
require.NotNil(t, info.CNIResult)
require.NotNil(t, status.Network)
require.NotEmpty(t, status.Network.Ip)
}
break
}
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/cri/server/sandbox_run.go
Expand Up @@ -295,7 +295,8 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
// Update spec of the container
containerd.UpdateContainerOpts(containerd.WithSpec(spec)),
// Update sandbox metadata to include NetNS info
containerd.UpdateContainerOpts(containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata))); err != nil {
containerd.UpdateContainerOpts(containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata)),
); err != nil {
return nil, fmt.Errorf("failed to update the network namespace for the sandbox container %q: %w", id, err)
}

Expand Down Expand Up @@ -325,6 +326,14 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
return nil, fmt.Errorf("failed to setup network for sandbox %q: %w", id, err)
}

// Update metadata here to save CNI result and pod IPs to disk.
if err := container.Update(ctx,
// Update sandbox metadata to include NetNS info
containerd.UpdateContainerOpts(containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata)),
); err != nil {
return nil, fmt.Errorf("failed to update the network namespace for the sandbox container %q: %w", id, err)
}

sandboxCreateNetworkTimer.UpdateSince(netStart)
}

Expand Down