@@ -1160,4 +1160,221 @@ var _ = g.Describe("[Feature:DeploymentConfig] deploymentconfigs", func() {
1160
1160
})
1161
1161
})
1162
1162
})
1163
+
1164
+ g .Describe ("keep the deployer pod invariant valid [Conformance]" , func () {
1165
+ dcName := "deployment-simple"
1166
+
1167
+ g .AfterEach (func () {
1168
+ failureTrap (oc , dcName , g .CurrentGinkgoTestDescription ().Failed )
1169
+ })
1170
+
1171
+ g .It ("should deal with cancellation of running deployment" , func () {
1172
+ namespace := oc .Namespace ()
1173
+
1174
+ g .By ("creating DC" )
1175
+ dc , err := readDCFixture (simpleDeploymentFixture )
1176
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1177
+ o .Expect (dc .Name ).To (o .Equal (dcName ))
1178
+
1179
+ dc .Spec .Replicas = 1
1180
+ // Make sure the deployer pod doesn't end too soon
1181
+ dc .Spec .MinReadySeconds = 60
1182
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (namespace ).Create (dc )
1183
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1184
+
1185
+ g .By ("waiting for RC to be created" )
1186
+ dc , err = waitForDCModification (oc , namespace , dcName , deploymentRunTimeout ,
1187
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1188
+ cond := deployutil .GetDeploymentCondition (config .Status , deployapi .DeploymentProgressing )
1189
+ if cond != nil && cond .Reason == deployapi .NewReplicationControllerReason {
1190
+ return true , nil
1191
+ }
1192
+ return false , nil
1193
+ })
1194
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1195
+ o .Expect (dc .Status .LatestVersion ).To (o .BeEquivalentTo (1 ))
1196
+
1197
+ g .By ("waiting for deployer pod to be running" )
1198
+ rc , err := waitForRCModification (oc , namespace , deployutil .LatestDeploymentNameForConfig (dc ), deploymentRunTimeout ,
1199
+ "" , func (currentRC * kapiv1.ReplicationController ) (bool , error ) {
1200
+ if deployutil .DeploymentStatusFor (currentRC ) == deployapi .DeploymentStatusRunning {
1201
+ return true , nil
1202
+ }
1203
+ return false , nil
1204
+ })
1205
+
1206
+ g .By ("canceling the deployment" )
1207
+ rc , err = oc .KubeClient ().CoreV1 ().ReplicationControllers (namespace ).Patch (
1208
+ deployutil .LatestDeploymentNameForConfig (dc ), types .StrategicMergePatchType ,
1209
+ []byte (fmt .Sprintf (`{"metadata":{"annotations":{%q: %q, %q: %q}}}` ,
1210
+ deployapi .DeploymentCancelledAnnotation , deployapi .DeploymentCancelledAnnotationValue ,
1211
+ deployapi .DeploymentStatusReasonAnnotation , deployapi .DeploymentCancelledByUser ,
1212
+ )))
1213
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1214
+ o .Expect (deployutil .DeploymentVersionFor (rc )).To (o .Equal (dc .Status .LatestVersion ))
1215
+
1216
+ g .By ("redeploying immediately by config change" )
1217
+ o .Expect (dc .Spec .Template .Annotations ["foo" ]).NotTo (o .Equal ("bar" ))
1218
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (dc .Namespace ).Patch (dc .Name , types .StrategicMergePatchType ,
1219
+ []byte (`{"spec":{"template":{"metadata":{"annotations":{"foo": "bar"}}}}}` ))
1220
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1221
+ dc , err = waitForDCModification (oc , namespace , dcName , deploymentRunTimeout ,
1222
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1223
+ if config .Status .LatestVersion == 2 {
1224
+ return true , nil
1225
+ }
1226
+ return false , nil
1227
+ })
1228
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1229
+
1230
+ // Wait for deployment pod to be running
1231
+ rc , err = waitForRCModification (oc , namespace , deployutil .LatestDeploymentNameForConfig (dc ), deploymentRunTimeout ,
1232
+ "" , func (currentRC * kapiv1.ReplicationController ) (bool , error ) {
1233
+ if deployutil .DeploymentStatusFor (currentRC ) == deployapi .DeploymentStatusRunning {
1234
+ return true , nil
1235
+ }
1236
+ return false , nil
1237
+ })
1238
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1239
+ })
1240
+
1241
+ g .It ("should deal with config change in case the deployment is still running" , func () {
1242
+ namespace := oc .Namespace ()
1243
+
1244
+ g .By ("creating DC" )
1245
+ dc , err := readDCFixture (simpleDeploymentFixture )
1246
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1247
+ o .Expect (dc .Name ).To (o .Equal (dcName ))
1248
+
1249
+ dc .Spec .Replicas = 1
1250
+ // Make sure the deployer pod doesn't end too soon
1251
+ dc .Spec .MinReadySeconds = 60
1252
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (namespace ).Create (dc )
1253
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1254
+
1255
+ g .By ("waiting for RC to be created" )
1256
+ dc , err = waitForDCModification (oc , namespace , dc .Name , deploymentRunTimeout ,
1257
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1258
+ cond := deployutil .GetDeploymentCondition (config .Status , deployapi .DeploymentProgressing )
1259
+ if cond != nil && cond .Reason == deployapi .NewReplicationControllerReason {
1260
+ return true , nil
1261
+ }
1262
+ return false , nil
1263
+ })
1264
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1265
+ o .Expect (dc .Status .LatestVersion ).To (o .BeEquivalentTo (1 ))
1266
+
1267
+ g .By ("waiting for deployer pod to be running" )
1268
+ _ , err = waitForRCModification (oc , namespace , deployutil .LatestDeploymentNameForConfig (dc ), deploymentRunTimeout ,
1269
+ "" , func (currentRC * kapiv1.ReplicationController ) (bool , error ) {
1270
+ if deployutil .DeploymentStatusFor (currentRC ) == deployapi .DeploymentStatusRunning {
1271
+ return true , nil
1272
+ }
1273
+ return false , nil
1274
+ })
1275
+
1276
+ g .By ("redeploying immediately by config change" )
1277
+ o .Expect (dc .Spec .Template .Annotations ["foo" ]).NotTo (o .Equal ("bar" ))
1278
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (dc .Namespace ).Patch (dc .Name , types .StrategicMergePatchType ,
1279
+ []byte (`{"spec":{"template":{"metadata":{"annotations":{"foo": "bar"}}}}}` ))
1280
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1281
+ dc , err = waitForDCModification (oc , namespace , dcName , deploymentRunTimeout ,
1282
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1283
+ if config .Status .LatestVersion == 2 {
1284
+ return true , nil
1285
+ }
1286
+ return false , nil
1287
+ })
1288
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1289
+
1290
+ // Wait for deployment pod to be running
1291
+ _ , err = waitForRCModification (oc , namespace , deployutil .LatestDeploymentNameForConfig (dc ), deploymentRunTimeout ,
1292
+ "" , func (currentRC * kapiv1.ReplicationController ) (bool , error ) {
1293
+ if deployutil .DeploymentStatusFor (currentRC ) == deployapi .DeploymentStatusRunning {
1294
+ return true , nil
1295
+ }
1296
+ return false , nil
1297
+ })
1298
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1299
+ })
1300
+
1301
+ g .It ("should deal with cancellation after deployer pod succeeded" , func () {
1302
+ namespace := oc .Namespace ()
1303
+
1304
+ g .By ("creating DC" )
1305
+ dc , err := readDCFixture (simpleDeploymentFixture )
1306
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1307
+ o .Expect (dc .Name ).To (o .Equal (dcName ))
1308
+
1309
+ dc .Spec .Replicas = 1
1310
+ // Make sure the deployer pod doesn't immediately
1311
+ dc .Spec .MinReadySeconds = 3
1312
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (namespace ).Create (dc )
1313
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1314
+
1315
+ g .By ("waiting for RC to be created" )
1316
+ dc , err = waitForDCModification (oc , namespace , dc .Name , deploymentRunTimeout ,
1317
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1318
+ cond := deployutil .GetDeploymentCondition (config .Status , deployapi .DeploymentProgressing )
1319
+ if cond != nil && cond .Reason == deployapi .NewReplicationControllerReason {
1320
+ return true , nil
1321
+ }
1322
+ return false , nil
1323
+ })
1324
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1325
+ o .Expect (dc .Status .LatestVersion ).To (o .BeEquivalentTo (1 ))
1326
+
1327
+ rcName := deployutil .LatestDeploymentNameForConfig (dc )
1328
+
1329
+ g .By ("waiting for deployer to be completed" )
1330
+ _ , err = waitForPodModification (oc , namespace ,
1331
+ deployutil .DeployerPodNameForDeployment (rcName ),
1332
+ deploymentRunTimeout , "" ,
1333
+ func (pod * kapiv1.Pod ) (bool , error ) {
1334
+ switch pod .Status .Phase {
1335
+ case kapiv1 .PodSucceeded :
1336
+ return true , nil
1337
+ case kapiv1 .PodFailed :
1338
+ return true , errors .New ("pod failed" )
1339
+ default :
1340
+ return false , nil
1341
+ }
1342
+ })
1343
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1344
+
1345
+ g .By ("canceling the deployment" )
1346
+ rc , err := oc .KubeClient ().CoreV1 ().ReplicationControllers (namespace ).Patch (
1347
+ rcName , types .StrategicMergePatchType ,
1348
+ []byte (fmt .Sprintf (`{"metadata":{"annotations":{%q: %q, %q: %q}}}` ,
1349
+ deployapi .DeploymentCancelledAnnotation , deployapi .DeploymentCancelledAnnotationValue ,
1350
+ deployapi .DeploymentStatusReasonAnnotation , deployapi .DeploymentCancelledByUser ,
1351
+ )))
1352
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1353
+ o .Expect (deployutil .DeploymentVersionFor (rc )).To (o .BeEquivalentTo (1 ))
1354
+
1355
+ g .By ("redeploying immediately by config change" )
1356
+ o .Expect (dc .Spec .Template .Annotations ["foo" ]).NotTo (o .Equal ("bar" ))
1357
+ dc , err = oc .AppsClient ().Apps ().DeploymentConfigs (dc .Namespace ).Patch (dc .Name , types .StrategicMergePatchType ,
1358
+ []byte (`{"spec":{"template":{"metadata":{"annotations":{"foo": "bar"}}}}}` ))
1359
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1360
+ dc , err = waitForDCModification (oc , namespace , dcName , deploymentRunTimeout ,
1361
+ dc .GetResourceVersion (), func (config * deployapi.DeploymentConfig ) (bool , error ) {
1362
+ if config .Status .LatestVersion == 2 {
1363
+ return true , nil
1364
+ }
1365
+ return false , nil
1366
+ })
1367
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1368
+
1369
+ // Wait for deployment pod to be running
1370
+ _ , err = waitForRCModification (oc , namespace , deployutil .LatestDeploymentNameForConfig (dc ), deploymentRunTimeout ,
1371
+ "" , func (currentRC * kapiv1.ReplicationController ) (bool , error ) {
1372
+ if deployutil .DeploymentStatusFor (currentRC ) == deployapi .DeploymentStatusRunning {
1373
+ return true , nil
1374
+ }
1375
+ return false , nil
1376
+ })
1377
+ o .Expect (err ).NotTo (o .HaveOccurred ())
1378
+ })
1379
+ })
1163
1380
})
0 commit comments