@@ -77,6 +77,7 @@ type DeploymentConfigController struct {
77
77
// Handle implements the loop that processes deployment configs. Since this controller started
78
78
// using caches, the provided config MUST be deep-copied beforehand (see work() in factory.go).
79
79
func (c * DeploymentConfigController ) Handle (config * deployapi.DeploymentConfig ) error {
80
+ glog .V (5 ).Infof ("Reconciling %s/%s" , config .Namespace , config .Name )
80
81
// There's nothing to reconcile until the version is nonzero.
81
82
if config .Status .LatestVersion == 0 {
82
83
return c .updateStatus (config , []kapi.ReplicationController {})
@@ -182,9 +183,13 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
182
183
return c .updateStatus (config , existingDeployments )
183
184
}
184
185
c .recorder .Eventf (config , kapi .EventTypeWarning , "DeploymentCreationFailed" , "Couldn't deploy version %d: %s" , config .Status .LatestVersion , err )
186
+ // We don't care about this error since we need to report the create failure.
187
+ cond := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionFalse , deployutil .FailedRcCreateReason , err .Error ())
188
+ _ = c .updateStatus (config , existingDeployments , * cond )
185
189
return fmt .Errorf ("couldn't create deployment for deployment config %s: %v" , deployutil .LabelForDeploymentConfig (config ), err )
186
190
}
187
- c .recorder .Eventf (config , kapi .EventTypeNormal , "DeploymentCreated" , "Created new deployment %q for version %d" , created .Name , config .Status .LatestVersion )
191
+ msg := fmt .Sprintf ("Created new replication controller %q for version %d" , created .Name , config .Status .LatestVersion )
192
+ c .recorder .Eventf (config , kapi .EventTypeNormal , "DeploymentCreated" , msg )
188
193
189
194
// As we've just created a new deployment, we need to make sure to clean
190
195
// up old deployments if we have reached our deployment history quota
@@ -193,7 +198,8 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
193
198
c .recorder .Eventf (config , kapi .EventTypeWarning , "DeploymentCleanupFailed" , "Couldn't clean up deployments: %v" , err )
194
199
}
195
200
196
- return c .updateStatus (config , existingDeployments )
201
+ cond := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionTrue , deployutil .NewRcAvailableReason , msg )
202
+ return c .updateStatus (config , existingDeployments , * cond )
197
203
}
198
204
199
205
// reconcileDeployments reconciles existing deployment replica counts which
@@ -352,19 +358,15 @@ func (c *DeploymentConfigController) reconcileDeployments(existingDeployments []
352
358
return c .updateStatus (config , updatedDeployments )
353
359
}
354
360
355
- func (c * DeploymentConfigController ) updateStatus (config * deployapi.DeploymentConfig , deployments []kapi.ReplicationController ) error {
356
- newStatus , err := c .calculateStatus (* config , deployments )
361
+ // Update the status of the provided deployment config. Additional conditions will override any other condition in the
362
+ // deployment config status.
363
+ func (c * DeploymentConfigController ) updateStatus (config * deployapi.DeploymentConfig , deployments []kapi.ReplicationController , additional ... deployapi.DeploymentCondition ) error {
364
+ newStatus , err := c .calculateStatus (* config , deployments , additional ... )
357
365
if err != nil {
358
366
glog .V (2 ).Infof ("Cannot calculate the status for %q: %v" , deployutil .LabelForDeploymentConfig (config ), err )
359
367
return err
360
368
}
361
369
362
- latestExists , latestRC := deployutil .LatestDeploymentInfo (config , deployments )
363
- if ! latestExists {
364
- latestRC = nil
365
- }
366
- updateConditions (config , & newStatus , latestRC )
367
-
368
370
// NOTE: We should update the status of the deployment config only if we need to, otherwise
369
371
// we hotloop between updates.
370
372
if reflect .DeepEqual (newStatus , config .Status ) {
@@ -377,6 +379,7 @@ func (c *DeploymentConfigController) updateStatus(config *deployapi.DeploymentCo
377
379
}
378
380
379
381
copied .Status = newStatus
382
+ // TODO: Retry update conficts
380
383
if _ , err := c .dn .DeploymentConfigs (copied .Namespace ).UpdateStatus (copied ); err != nil {
381
384
glog .V (2 ).Infof ("Cannot update the status for %q: %v" , deployutil .LabelForDeploymentConfig (copied ), err )
382
385
return err
@@ -385,8 +388,9 @@ func (c *DeploymentConfigController) updateStatus(config *deployapi.DeploymentCo
385
388
return nil
386
389
}
387
390
388
- func (c * DeploymentConfigController ) calculateStatus (config deployapi.DeploymentConfig , deployments []kapi.ReplicationController ) (deployapi.DeploymentConfigStatus , error ) {
391
+ func (c * DeploymentConfigController ) calculateStatus (config deployapi.DeploymentConfig , deployments []kapi.ReplicationController , additional ... deployapi. DeploymentCondition ) (deployapi.DeploymentConfigStatus , error ) {
389
392
selector := labels .Set (config .Spec .Selector ).AsSelector ()
393
+ // TODO: Replace with using rc.status.availableReplicas that comes with the next rebase.
390
394
pods , err := c .podStore .Pods (config .Namespace ).List (selector )
391
395
if err != nil {
392
396
return config .Status , err
@@ -396,59 +400,67 @@ func (c *DeploymentConfigController) calculateStatus(config deployapi.Deployment
396
400
// UpdatedReplicas represents the replicas that use the deployment config template which means
397
401
// we should inform about the replicas of the latest deployment and not the active.
398
402
latestReplicas := int32 (0 )
399
- for _ , deployment := range deployments {
400
- if deployment .Name == deployutil .LatestDeploymentNameForConfig (& config ) {
401
- updatedDeployment := []kapi.ReplicationController {deployment }
402
- latestReplicas = deployutil .GetStatusReplicaCountForDeployments (updatedDeployment )
403
- break
404
- }
403
+ latestExists , latestRC := deployutil .LatestDeploymentInfo (& config , deployments )
404
+ if ! latestExists {
405
+ latestRC = nil
406
+ } else {
407
+ latestReplicas = deployutil .GetStatusReplicaCountForDeployments ([]kapi.ReplicationController {* latestRC })
405
408
}
406
409
407
410
total := deployutil .GetReplicaCountForDeployments (deployments )
408
411
409
- return deployapi.DeploymentConfigStatus {
412
+ status := deployapi.DeploymentConfigStatus {
410
413
LatestVersion : config .Status .LatestVersion ,
411
414
Details : config .Status .Details ,
412
415
ObservedGeneration : config .Generation ,
413
416
Replicas : deployutil .GetStatusReplicaCountForDeployments (deployments ),
414
417
UpdatedReplicas : latestReplicas ,
415
418
AvailableReplicas : available ,
416
419
UnavailableReplicas : total - available ,
417
- }, nil
420
+ Conditions : config .Status .Conditions ,
421
+ }
422
+
423
+ isProgressing := deployutil .IsProgressing (config , status )
424
+ updateConditions (config , & status , latestRC , isProgressing )
425
+ for _ , cond := range additional {
426
+ deployutil .SetDeploymentCondition (& status , cond )
427
+ }
428
+
429
+ return status , nil
418
430
}
419
431
420
- func updateConditions (config * deployapi.DeploymentConfig , newStatus * deployapi.DeploymentConfigStatus , latestRC * kapi.ReplicationController ) {
432
+ func updateConditions (config deployapi.DeploymentConfig , newStatus * deployapi.DeploymentConfigStatus , latestRC * kapi.ReplicationController , isProgressing bool ) {
421
433
// Availability condition.
422
- if newStatus .AvailableReplicas >= config .Spec .Replicas - deployutil .MaxUnavailable (* config ) {
434
+ if newStatus .AvailableReplicas >= config .Spec .Replicas - deployutil .MaxUnavailable (config ) && newStatus . AvailableReplicas > 0 {
423
435
minAvailability := deployutil .NewDeploymentCondition (deployapi .DeploymentAvailable , kapi .ConditionTrue , "" , "Deployment config has minimum availability." )
424
436
deployutil .SetDeploymentCondition (newStatus , * minAvailability )
425
437
} else {
426
438
noMinAvailability := deployutil .NewDeploymentCondition (deployapi .DeploymentAvailable , kapi .ConditionFalse , "" , "Deployment config does not have minimum availability." )
427
439
deployutil .SetDeploymentCondition (newStatus , * noMinAvailability )
428
440
}
441
+
429
442
// Condition about progress.
430
443
cond := deployutil .GetDeploymentCondition (* newStatus , deployapi .DeploymentProgressing )
431
444
if latestRC != nil {
432
445
switch deployutil .DeploymentStatusFor (latestRC ) {
433
- case deployapi .DeploymentStatusNew , deployapi . DeploymentStatusPending :
434
- msg := fmt .Sprintf ("Waiting on deployer pod for %q to be scheduled" , latestRC .Name )
446
+ case deployapi .DeploymentStatusPending :
447
+ msg := fmt .Sprintf ("Waiting on deployer pod for replication controller %q to be scheduled" , latestRC .Name )
435
448
condition := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionUnknown , "" , msg )
436
449
deployutil .SetDeploymentCondition (newStatus , * condition )
437
450
case deployapi .DeploymentStatusRunning :
438
- msg := fmt .Sprintf ("Replication controller %q is progressing" , latestRC .Name )
439
- condition := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionTrue , deployutil .ReplicationControllerUpdatedReason , msg )
440
- deployutil .SetDeploymentCondition (newStatus , * condition )
441
- case deployapi .DeploymentStatusFailed :
442
- if cond != nil && cond .Reason == deployutil .TimedOutReason {
443
- break
451
+ if isProgressing {
452
+ deployutil .RemoveDeploymentCondition (newStatus , deployapi .DeploymentProgressing )
453
+ msg := fmt .Sprintf ("Replication controller %q is progressing" , latestRC .Name )
454
+ condition := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionTrue , deployutil .ReplicationControllerUpdatedReason , msg )
455
+ // TODO: Right now, we use lastTransitionTime for storing the last time we had any progress instead
456
+ // of the last time the condition transitioned to a new status. We should probably change that.
457
+ deployutil .SetDeploymentCondition (newStatus , * condition )
444
458
}
459
+ case deployapi .DeploymentStatusFailed :
445
460
msg := fmt .Sprintf ("Replication controller %q has failed progressing" , latestRC .Name )
446
461
condition := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionFalse , deployutil .TimedOutReason , msg )
447
462
deployutil .SetDeploymentCondition (newStatus , * condition )
448
463
case deployapi .DeploymentStatusComplete :
449
- if cond != nil && cond .Reason == deployutil .NewRcAvailableReason {
450
- break
451
- }
452
464
msg := fmt .Sprintf ("Replication controller %q has completed progressing" , latestRC .Name )
453
465
condition := deployutil .NewDeploymentCondition (deployapi .DeploymentProgressing , kapi .ConditionTrue , deployutil .NewRcAvailableReason , msg )
454
466
deployutil .SetDeploymentCondition (newStatus , * condition )
0 commit comments