| ... | ... |
@@ -89,6 +89,9 @@ func (c *DeployerPodController) Handle(pod *kapi.Pod) error {
|
| 89 | 89 |
nextStatus = deployapi.DeploymentStatusFailed |
| 90 | 90 |
} |
| 91 | 91 |
} |
| 92 |
+ if nextStatus == deployapi.DeploymentStatusComplete {
|
|
| 93 |
+ delete(deployment.Annotations, deployapi.DesiredReplicasAnnotation) |
|
| 94 |
+ } |
|
| 92 | 95 |
case kapi.PodFailed: |
| 93 | 96 |
// if the deployment is already marked Failed, do not attempt clean up again |
| 94 | 97 |
if currentStatus != deployapi.DeploymentStatusFailed {
|
| ... | ... |
@@ -371,6 +371,63 @@ func TestHandle_cleanupDeploymentFailure(t *testing.T) {
|
| 371 | 371 |
} |
| 372 | 372 |
} |
| 373 | 373 |
|
| 374 |
+// TestHandle_cleanupDesiredReplicasAnnotation ensures that the desired replicas annotation |
|
| 375 |
+// will be cleaned up in a complete deployment and stay around in a failed deployment |
|
| 376 |
+func TestHandle_cleanupDesiredReplicasAnnotation(t *testing.T) {
|
|
| 377 |
+ deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codec) |
|
| 378 |
+ |
|
| 379 |
+ tests := []struct {
|
|
| 380 |
+ name string |
|
| 381 |
+ pod *kapi.Pod |
|
| 382 |
+ expected bool |
|
| 383 |
+ }{
|
|
| 384 |
+ {
|
|
| 385 |
+ name: "complete deployment - cleaned up annotation", |
|
| 386 |
+ pod: succeededPod(deployment), |
|
| 387 |
+ expected: false, |
|
| 388 |
+ }, |
|
| 389 |
+ {
|
|
| 390 |
+ name: "failed deployment - annotation stays", |
|
| 391 |
+ pod: terminatedPod(deployment), |
|
| 392 |
+ expected: true, |
|
| 393 |
+ }, |
|
| 394 |
+ } |
|
| 395 |
+ |
|
| 396 |
+ for _, test := range tests {
|
|
| 397 |
+ var updatedDeployment *kapi.ReplicationController |
|
| 398 |
+ deployment.Annotations[deployapi.DesiredReplicasAnnotation] = "1" |
|
| 399 |
+ |
|
| 400 |
+ controller := &DeployerPodController{
|
|
| 401 |
+ deploymentClient: &deploymentClientImpl{
|
|
| 402 |
+ getDeploymentFunc: func(namespace, name string) (*kapi.ReplicationController, error) {
|
|
| 403 |
+ return deployment, nil |
|
| 404 |
+ }, |
|
| 405 |
+ updateDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
|
|
| 406 |
+ updatedDeployment = deployment |
|
| 407 |
+ return deployment, nil |
|
| 408 |
+ }, |
|
| 409 |
+ listDeploymentsForConfigFunc: func(namespace, configName string) (*kapi.ReplicationControllerList, error) {
|
|
| 410 |
+ return &kapi.ReplicationControllerList{Items: []kapi.ReplicationController{*deployment}}, nil
|
|
| 411 |
+ }, |
|
| 412 |
+ }, |
|
| 413 |
+ } |
|
| 414 |
+ |
|
| 415 |
+ if err := controller.Handle(test.pod); err != nil {
|
|
| 416 |
+ t.Errorf("%s: unexpected error: %v", test.name, err)
|
|
| 417 |
+ continue |
|
| 418 |
+ } |
|
| 419 |
+ |
|
| 420 |
+ if updatedDeployment == nil {
|
|
| 421 |
+ t.Errorf("%s: expected deployment update", test.name)
|
|
| 422 |
+ continue |
|
| 423 |
+ } |
|
| 424 |
+ |
|
| 425 |
+ if _, got := updatedDeployment.Annotations[deployapi.DesiredReplicasAnnotation]; got != test.expected {
|
|
| 426 |
+ t.Errorf("%s: expected annotation: %t, got %t", test.name, test.expected, got)
|
|
| 427 |
+ } |
|
| 428 |
+ } |
|
| 429 |
+} |
|
| 430 |
+ |
|
| 374 | 431 |
func okPod(deployment *kapi.ReplicationController) *kapi.Pod {
|
| 375 | 432 |
return &kapi.Pod{
|
| 376 | 433 |
ObjectMeta: kapi.ObjectMeta{
|