@@ -38,6 +38,7 @@ import (
38
38
cri "github.com/containerd/containerd/v2/integration/cri-api/pkg/apis"
39
39
"github.com/containerd/containerd/v2/integration/images"
40
40
"github.com/containerd/containerd/v2/integration/remote"
41
+ "github.com/containerd/containerd/v2/pkg/namespaces"
41
42
)
42
43
43
44
// upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
@@ -147,12 +148,24 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
147
148
secondPodCtx := newPodTCtx (t , rSvc , "stopped-pod" , "sandbox" )
148
149
secondPodCtx .stop (false )
149
150
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
+
150
163
return func (t * testing.T , rSvc cri.RuntimeService , _ cri.ImageManagerService ) {
151
164
t .Log ("List Pods" )
152
165
153
166
pods , err := rSvc .ListPodSandbox (nil )
154
167
require .NoError (t , err )
155
- require .Len (t , pods , 2 )
168
+ require .Len (t , pods , 3 )
156
169
157
170
for _ , pod := range pods {
158
171
t .Logf ("Checking pod %s" , pod .Id )
@@ -181,11 +194,22 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T,
181
194
182
195
case secondPodCtx .id :
183
196
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
+
184
208
default :
185
209
t .Errorf ("unexpected pod %s" , pod .Id )
186
210
}
187
211
}
188
- }, nil
212
+ }, hookFunc
189
213
}
190
214
191
215
func execToExistingContainer (t * testing.T ,
@@ -438,6 +462,21 @@ func (pCtx *podTCtx) containerDataDir(cntrID string) string {
438
462
return filepath .Join (rootDir , "containers" , status .Id )
439
463
}
440
464
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
+
441
480
// dataDir returns pod metadata dir maintained by CRI plugin.
442
481
func (pCtx * podTCtx ) dataDir () string {
443
482
t := pCtx .t
0 commit comments