@@ -41,7 +41,10 @@ import (
41
41
)
42
42
43
43
// upgradeVerifyCaseFunc is used to verify the behavior after upgrade.
44
- type upgradeVerifyCaseFunc func (t * testing.T , criRuntimeService cri.RuntimeService , criImageService cri.ImageManagerService )
44
+ type upgradeVerifyCaseFunc func (* testing.T , cri.RuntimeService , cri.ImageManagerService )
45
+
46
+ // beforeUpgradeHookFunc is a hook before upgrade.
47
+ type beforeUpgradeHookFunc func (* testing.T )
45
48
46
49
// TODO: Support Windows
47
50
func TestUpgrade (t * testing.T ) {
@@ -58,7 +61,7 @@ func TestUpgrade(t *testing.T) {
58
61
59
62
func runUpgradeTestCase (
60
63
previousReleaseBinDir string ,
61
- setupUpgradeVerifyCase func (t * testing.T , criRuntimeService cri.RuntimeService , criImageService cri.ImageManagerService ) upgradeVerifyCaseFunc ,
64
+ setupUpgradeVerifyCase func (* testing.T , cri.RuntimeService , cri.ImageManagerService ) ( upgradeVerifyCaseFunc , beforeUpgradeHookFunc ) ,
62
65
) func (t * testing.T ) {
63
66
return func (t * testing.T ) {
64
67
// NOTE: Using t.TempDir() here is to ensure there are no leaky
@@ -88,13 +91,18 @@ func runUpgradeTestCase(
88
91
})
89
92
90
93
t .Log ("Prepare pods for current release" )
91
- upgradeCaseFunc := setupUpgradeVerifyCase (t , previousProc .criRuntimeService (t ), previousProc .criImageService (t ))
94
+ upgradeCaseFunc , hookFunc := setupUpgradeVerifyCase (t , previousProc .criRuntimeService (t ), previousProc .criImageService (t ))
92
95
needToCleanup = false
93
96
94
97
t .Log ("Gracefully stop previous release's containerd process" )
95
98
require .NoError (t , previousProc .kill (syscall .SIGTERM ))
96
99
require .NoError (t , previousProc .wait (5 * time .Minute ))
97
100
101
+ if hookFunc != nil {
102
+ t .Log ("Run hook before upgrade" )
103
+ hookFunc (t )
104
+ }
105
+
98
106
t .Log ("Install default config for current release" )
99
107
currentReleaseCtrdDefaultConfig (t , workDir )
100
108
@@ -115,7 +123,9 @@ func runUpgradeTestCase(
115
123
}
116
124
}
117
125
118
- func shouldRecoverAllThePodsAfterUpgrade (t * testing.T , rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) upgradeVerifyCaseFunc {
126
+ func shouldRecoverAllThePodsAfterUpgrade (t * testing.T ,
127
+ rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) (upgradeVerifyCaseFunc , beforeUpgradeHookFunc ) {
128
+
119
129
var busyboxImage = images .Get (images .BusyBox )
120
130
121
131
pullImagesByCRI (t , iSvc , busyboxImage )
@@ -175,10 +185,12 @@ func shouldRecoverAllThePodsAfterUpgrade(t *testing.T, rSvc cri.RuntimeService,
175
185
t .Errorf ("unexpected pod %s" , pod .Id )
176
186
}
177
187
}
178
- }
188
+ }, nil
179
189
}
180
190
181
- func execToExistingContainer (t * testing.T , rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) upgradeVerifyCaseFunc {
191
+ func execToExistingContainer (t * testing.T ,
192
+ rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) (upgradeVerifyCaseFunc , beforeUpgradeHookFunc ) {
193
+
182
194
var busyboxImage = images .Get (images .BusyBox )
183
195
184
196
pullImagesByCRI (t , iSvc , busyboxImage )
@@ -231,7 +243,7 @@ func execToExistingContainer(t *testing.T, rSvc cri.RuntimeService, iSvc cri.Ima
231
243
require .NoError (t , err )
232
244
require .Len (t , stderr , 0 )
233
245
require .Equal (t , "true" , string (stdout ))
234
- }
246
+ }, nil
235
247
}
236
248
237
249
// getFileSize returns file's size.
@@ -241,7 +253,9 @@ func getFileSize(t *testing.T, filePath string) int64 {
241
253
return st .Size ()
242
254
}
243
255
244
- func shouldManipulateContainersInPodAfterUpgrade (t * testing.T , rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) upgradeVerifyCaseFunc {
256
+ func shouldManipulateContainersInPodAfterUpgrade (t * testing.T ,
257
+ rSvc cri.RuntimeService , iSvc cri.ImageManagerService ) (upgradeVerifyCaseFunc , beforeUpgradeHookFunc ) {
258
+
245
259
var busyboxImage = images .Get (images .BusyBox )
246
260
247
261
pullImagesByCRI (t , iSvc , busyboxImage )
@@ -335,10 +349,12 @@ func shouldManipulateContainersInPodAfterUpgrade(t *testing.T, rSvc cri.RuntimeS
335
349
ents , err := os .ReadDir (cntrDataDir )
336
350
require .NoError (t , err )
337
351
require .Len (t , ents , 0 , cntrDataDir )
338
- }
352
+ }, nil
339
353
}
340
354
341
- func shouldRecoverExistingImages (t * testing.T , _ cri.RuntimeService , iSvc cri.ImageManagerService ) upgradeVerifyCaseFunc {
355
+ func shouldRecoverExistingImages (t * testing.T ,
356
+ _ cri.RuntimeService , iSvc cri.ImageManagerService ) (upgradeVerifyCaseFunc , beforeUpgradeHookFunc ) {
357
+
342
358
images := []string {images .Get (images .BusyBox ), images .Get (images .Alpine )}
343
359
expectedRefs := pullImagesByCRI (t , iSvc , images ... )
344
360
@@ -354,7 +370,7 @@ func shouldRecoverExistingImages(t *testing.T, _ cri.RuntimeService, iSvc cri.Im
354
370
require .NoError (t , err )
355
371
require .Equal (t , expectedRefs [idx ], gotImg .Id )
356
372
}
357
- }
373
+ }, nil
358
374
}
359
375
360
376
func newPodTCtx (t * testing.T , rSvc cri.RuntimeService ,
0 commit comments