@@ -38,6 +38,7 @@ import (
3838 cri "github.com/containerd/containerd/v2/integration/cri-api/pkg/apis"
3939 "github.com/containerd/containerd/v2/integration/images"
4040 "github.com/containerd/containerd/v2/integration/remote"
41+ "github.com/containerd/containerd/v2/pkg/namespaces"
4142)
4243
4344// upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
@@ -147,12 +148,24 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
147148 secondPodCtx := newPodTCtx (t , rSvc , "stopped-pod" , "sandbox" )
148149 secondPodCtx .stop (false )
149150
151+ thirdPodCtx := newPodTCtx (t , rSvc , "kill-before-upgrade" , "failpoint" )
152+ thirdPodCtx .createContainer ("sorry" , busyboxImage ,
153+ criruntime .ContainerState_CONTAINER_RUNNING ,
154+ WithCommand ("sleep" , "3d" ))
155+
156+ thirdPodShimPid := int (thirdPodCtx .shimPid ())
157+
158+ hookFunc := func (t * testing.T ) {
159+ // Kill the shim after stop previous containerd process
160+ syscall .Kill (thirdPodShimPid , syscall .SIGKILL )
161+ }
162+
150163 return func (t * testing.T , rSvc cri.RuntimeService , _ cri.ImageManagerService ) {
151164 t .Log ("List Pods" )
152165
153166 pods , err := rSvc .ListPodSandbox (nil )
154167 require .NoError (t , err )
155- require .Len (t , pods , 2 )
168+ require .Len (t , pods , 3 )
156169
157170 for _ , pod := range pods {
158171 t .Logf ("Checking pod %s" , pod .Id )
@@ -181,11 +194,22 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
181194
182195 case secondPodCtx .id :
183196 assert .Equal (t , criruntime .PodSandboxState_SANDBOX_NOTREADY , pod .State )
197+
198+ case thirdPodCtx .id :
199+ assert .Equal (t , criruntime .PodSandboxState_SANDBOX_NOTREADY , pod .State )
200+
201+ cntrs , err := rSvc .ListContainers (& criruntime.ContainerFilter {
202+ PodSandboxId : pod .Id ,
203+ })
204+ require .NoError (t , err )
205+ require .Equal (t , 1 , len (cntrs ))
206+ assert .Equal (t , criruntime .ContainerState_CONTAINER_EXITED , cntrs [0 ].State )
207+
184208 default :
185209 t .Errorf ("unexpected pod %s" , pod .Id )
186210 }
187211 }
188- }, nil
212+ }, hookFunc
189213}
190214
191215func execToExistingContainer (t * testing.T ,
@@ -438,6 +462,21 @@ func (pCtx *podTCtx) containerDataDir(cntrID string) string {
438462 return filepath .Join (rootDir , "containers" , status .Id )
439463}
440464
465+ // shimPid returns shim's pid.
466+ func (pCtx * podTCtx ) shimPid () uint32 {
467+ t := pCtx .t
468+ cfg := criRuntimeInfo (t , pCtx .rSvc )
469+
470+ ctx := namespaces .WithNamespace (context .Background (), "k8s.io" )
471+
472+ ctx , cancel := context .WithTimeout (ctx , 30 * time .Second )
473+ defer cancel ()
474+
475+ // NOTE: use version 2 to be compatible with previous release
476+ shimCli := connectToShim (ctx , t , cfg ["containerdEndpoint" ].(string ), 2 , pCtx .id )
477+ return shimPid (ctx , t , shimCli )
478+ }
479+
441480// dataDir returns pod metadata dir maintained by CRI plugin.
442481func (pCtx * podTCtx ) dataDir () string {
443482 t := pCtx .t
0 commit comments