integration: update recover case for upgrade

The new release containerd should detect dead shim during recover.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
Wei Fu 2024-02-05 12:10:31 +08:00
parent e659cd2752
commit acec60f554

View File

@ -38,6 +38,7 @@ import (
cri "github.com/containerd/containerd/v2/integration/cri-api/pkg/apis" cri "github.com/containerd/containerd/v2/integration/cri-api/pkg/apis"
"github.com/containerd/containerd/v2/integration/images" "github.com/containerd/containerd/v2/integration/images"
"github.com/containerd/containerd/v2/integration/remote" "github.com/containerd/containerd/v2/integration/remote"
"github.com/containerd/containerd/v2/pkg/namespaces"
) )
// upgradeVerifyCaseFunc is used to verify the behavior after upgrade. // upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
@ -147,12 +148,24 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
secondPodCtx := newPodTCtx(t, rSvc, "stopped-pod", "sandbox") secondPodCtx := newPodTCtx(t, rSvc, "stopped-pod", "sandbox")
secondPodCtx.stop(false) secondPodCtx.stop(false)
thirdPodCtx := newPodTCtx(t, rSvc, "kill-before-upgrade", "failpoint")
thirdPodCtx.createContainer("sorry", busyboxImage,
criruntime.ContainerState_CONTAINER_RUNNING,
WithCommand("sleep", "3d"))
thirdPodShimPid := int(thirdPodCtx.shimPid())
hookFunc := func(t *testing.T) {
// Kill the shim after stop previous containerd process
syscall.Kill(thirdPodShimPid, syscall.SIGKILL)
}
return func(t *testing.T, rSvc cri.RuntimeService, _ cri.ImageManagerService) { return func(t *testing.T, rSvc cri.RuntimeService, _ cri.ImageManagerService) {
t.Log("List Pods") t.Log("List Pods")
pods, err := rSvc.ListPodSandbox(nil) pods, err := rSvc.ListPodSandbox(nil)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, pods, 2) require.Len(t, pods, 3)
for _, pod := range pods { for _, pod := range pods {
t.Logf("Checking pod %s", pod.Id) t.Logf("Checking pod %s", pod.Id)
@ -181,11 +194,22 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
case secondPodCtx.id: case secondPodCtx.id:
assert.Equal(t, criruntime.PodSandboxState_SANDBOX_NOTREADY, pod.State) assert.Equal(t, criruntime.PodSandboxState_SANDBOX_NOTREADY, pod.State)
case thirdPodCtx.id:
assert.Equal(t, criruntime.PodSandboxState_SANDBOX_NOTREADY, pod.State)
cntrs, err := rSvc.ListContainers(&criruntime.ContainerFilter{
PodSandboxId: pod.Id,
})
require.NoError(t, err)
require.Equal(t, 1, len(cntrs))
assert.Equal(t, criruntime.ContainerState_CONTAINER_EXITED, cntrs[0].State)
default: default:
t.Errorf("unexpected pod %s", pod.Id) t.Errorf("unexpected pod %s", pod.Id)
} }
} }
}, nil }, hookFunc
} }
func execToExistingContainer(t *testing.T, func execToExistingContainer(t *testing.T,
@ -438,6 +462,21 @@ func (pCtx *podTCtx) containerDataDir(cntrID string) string {
return filepath.Join(rootDir, "containers", status.Id) return filepath.Join(rootDir, "containers", status.Id)
} }
// shimPid returns shim's pid.
func (pCtx *podTCtx) shimPid() uint32 {
t := pCtx.t
cfg := criRuntimeInfo(t, pCtx.rSvc)
ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
// NOTE: use version 2 to be compatible with previous release
shimCli := connectToShim(ctx, t, cfg["containerdEndpoint"].(string), 2, pCtx.id)
return shimPid(ctx, t, shimCli)
}
// dataDir returns pod metadata dir maintained by CRI plugin. // dataDir returns pod metadata dir maintained by CRI plugin.
func (pCtx *podTCtx) dataDir() string { func (pCtx *podTCtx) dataDir() string {
t := pCtx.t t := pCtx.t