Skip to content

Commit 3271ed1

Browse files
author
OpenShift Bot
authored
Merge pull request #13813 from mfojtik/cancel-condition
Merged by openshift-bot
2 parents 9334452 + 5f32644 commit 3271ed1

File tree

8 files changed

+57
-50
lines changed

8 files changed

+57
-50
lines changed

pkg/deploy/api/types.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,36 @@ const (
439439
DeploymentReplicaFailure DeploymentConditionType = "ReplicaFailure"
440440
)
441441

442+
type DeploymentConditionReason string
443+
444+
const (
445+
// ReplicationControllerUpdatedReason is added in a deployment config when one of its replication
446+
// controllers is updated as part of the rollout process.
447+
ReplicationControllerUpdatedReason DeploymentConditionReason = "ReplicationControllerUpdated"
448+
// FailedRcCreateReason is added in a deployment config when it cannot create a new replication
449+
// controller.
450+
FailedRcCreateReason DeploymentConditionReason = "ReplicationControllerCreateError"
451+
// NewReplicationControllerReason is added in a deployment config when it creates a new replication
452+
// controller.
453+
NewReplicationControllerReason DeploymentConditionReason = "NewReplicationControllerCreated"
454+
// NewRcAvailableReason is added in a deployment config when its newest replication controller is made
455+
// available ie. the number of new pods that have passed readiness checks and run for at least
456+
// minReadySeconds is at least the minimum available pods that need to run for the deployment config.
457+
NewRcAvailableReason DeploymentConditionReason = "NewReplicationControllerAvailable"
458+
// TimedOutReason is added in a deployment config when its newest replication controller fails to show
459+
// any progress within the given deadline (progressDeadlineSeconds).
460+
TimedOutReason DeploymentConditionReason = "ProgressDeadlineExceeded"
461+
// PausedConfigReason is added in a deployment config when it is paused. Lack of progress shouldn't be
462+
// estimated once a deployment config is paused.
463+
PausedConfigReason DeploymentConditionReason = "DeploymentConfigPaused"
464+
// ResumedConfigReason is added in a deployment config when it is resumed. Useful for not failing accidentally
465+
// deployment configs that paused amidst a rollout.
466+
ResumedConfigReason DeploymentConditionReason = "DeploymentConfigResumed"
467+
// CancelledRolloutReason is added in a deployment config when its newest rollout was
468+
// interrupted by cancellation.
469+
CancelledRolloutReason DeploymentConditionReason = "RolloutCancelled"
470+
)
471+
442472
// DeploymentCondition describes the state of a deployment config at a certain point.
443473
type DeploymentCondition struct {
444474
// Type of deployment condition.
@@ -450,7 +480,7 @@ type DeploymentCondition struct {
450480
// The last time the condition transitioned from one status to another.
451481
LastTransitionTime unversioned.Time
452482
// The reason for the condition's last transition.
453-
Reason string
483+
Reason DeploymentConditionReason
454484
// A human readable message indicating details about the transition.
455485
Message string
456486
}

pkg/deploy/api/v1/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func autoConvert_v1_DeploymentCondition_To_api_DeploymentCondition(in *Deploymen
174174
out.Status = pkg_api.ConditionStatus(in.Status)
175175
out.LastUpdateTime = in.LastUpdateTime
176176
out.LastTransitionTime = in.LastTransitionTime
177-
out.Reason = in.Reason
177+
out.Reason = api.DeploymentConditionReason(in.Reason)
178178
out.Message = in.Message
179179
return nil
180180
}
@@ -188,7 +188,7 @@ func autoConvert_api_DeploymentCondition_To_v1_DeploymentCondition(in *api.Deplo
188188
out.Status = api_v1.ConditionStatus(in.Status)
189189
out.LastUpdateTime = in.LastUpdateTime
190190
out.LastTransitionTime = in.LastTransitionTime
191-
out.Reason = in.Reason
191+
out.Reason = string(in.Reason)
192192
out.Message = in.Message
193193
return nil
194194
}

pkg/deploy/cmd/status.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ func (s *DeploymentConfigStatusViewer) Status(namespace, name string, desiredRev
4949

5050
if config.Generation <= config.Status.ObservedGeneration {
5151
switch {
52-
case cond != nil && cond.Reason == deployutil.NewRcAvailableReason:
52+
case cond != nil && cond.Reason == deployapi.NewRcAvailableReason:
5353
return fmt.Sprintf("%s\n", cond.Message), true, nil
5454

55-
case cond != nil && cond.Reason == deployutil.TimedOutReason:
55+
case cond != nil && cond.Reason == deployapi.TimedOutReason:
5656
return "", true, errors.New(cond.Message)
5757

58-
case cond != nil && cond.Reason == deployutil.PausedDeployReason:
58+
case cond != nil && cond.Reason == deployapi.CancelledRolloutReason:
59+
return "", true, errors.New(cond.Message)
60+
61+
case cond != nil && cond.Reason == deployapi.PausedConfigReason:
5962
return "", true, fmt.Errorf("Deployment config %q is paused. Resume to continue watching the status of the rollout.\n", config.Name)
6063

6164
case config.Status.UpdatedReplicas < config.Spec.Replicas:

pkg/deploy/controller/deploymentconfig/controller.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
189189
}
190190
c.recorder.Eventf(config, kapi.EventTypeWarning, "DeploymentCreationFailed", "Couldn't deploy version %d: %s", config.Status.LatestVersion, err)
191191
// We don't care about this error since we need to report the create failure.
192-
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployutil.FailedRcCreateReason, err.Error())
192+
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.FailedRcCreateReason, err.Error())
193193
_ = c.updateStatus(config, existingDeployments, *cond)
194194
return fmt.Errorf("couldn't create deployment for deployment config %s: %v", deployutil.LabelForDeploymentConfig(config), err)
195195
}
@@ -203,7 +203,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
203203
c.recorder.Eventf(config, kapi.EventTypeWarning, "DeploymentCleanupFailed", "Couldn't clean up deployments: %v", err)
204204
}
205205

206-
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.NewReplicationControllerReason, msg)
206+
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.NewReplicationControllerReason, msg)
207207
return c.updateStatus(config, existingDeployments, *cond)
208208
}
209209

@@ -368,18 +368,24 @@ func updateConditions(config deployapi.DeploymentConfig, newStatus *deployapi.De
368368
if deployutil.IsProgressing(config, *newStatus) {
369369
deployutil.RemoveDeploymentCondition(newStatus, deployapi.DeploymentProgressing)
370370
msg := fmt.Sprintf("replication controller %q is progressing", latestRC.Name)
371-
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.ReplicationControllerUpdatedReason, msg)
371+
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.ReplicationControllerUpdatedReason, msg)
372372
// TODO: Right now, we use lastTransitionTime for storing the last time we had any progress instead
373373
// of the last time the condition transitioned to a new status. We should probably change that.
374374
deployutil.SetDeploymentCondition(newStatus, *condition)
375375
}
376376
case deployapi.DeploymentStatusFailed:
377-
msg := fmt.Sprintf("replication controller %q has failed progressing", latestRC.Name)
378-
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployutil.TimedOutReason, msg)
377+
var condition *deployapi.DeploymentCondition
378+
if deployutil.IsDeploymentCancelled(latestRC) {
379+
msg := fmt.Sprintf("rollout of replication controller %q was cancelled", latestRC.Name)
380+
condition = deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.CancelledRolloutReason, msg)
381+
} else {
382+
msg := fmt.Sprintf("replication controller %q has failed progressing", latestRC.Name)
383+
condition = deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.TimedOutReason, msg)
384+
}
379385
deployutil.SetDeploymentCondition(newStatus, *condition)
380386
case deployapi.DeploymentStatusComplete:
381387
msg := fmt.Sprintf("replication controller %q successfully rolled out", latestRC.Name)
382-
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.NewRcAvailableReason, msg)
388+
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.NewRcAvailableReason, msg)
383389
deployutil.SetDeploymentCondition(newStatus, *condition)
384390
}
385391
}

pkg/deploy/util/util.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,8 @@ import (
2121
"github.com/openshift/origin/pkg/util/namer"
2222
)
2323

24-
const (
25-
// Reasons for deployment config conditions:
26-
//
27-
// ReplicationControllerUpdatedReason is added in a deployment config when one of its replication
28-
// controllers is updated as part of the rollout process.
29-
ReplicationControllerUpdatedReason = "ReplicationControllerUpdated"
30-
// FailedRcCreateReason is added in a deployment config when it cannot create a new replication
31-
// controller.
32-
FailedRcCreateReason = "ReplicationControllerCreateError"
33-
// NewReplicationControllerReason is added in a deployment config when it creates a new replication
34-
// controller.
35-
NewReplicationControllerReason = "NewReplicationControllerCreated"
36-
// NewRcAvailableReason is added in a deployment config when its newest replication controller is made
37-
// available ie. the number of new pods that have passed readiness checks and run for at least
38-
// minReadySeconds is at least the minimum available pods that need to run for the deployment config.
39-
NewRcAvailableReason = "NewReplicationControllerAvailable"
40-
// TimedOutReason is added in a deployment config when its newest replication controller fails to show
41-
// any progress within the given deadline (progressDeadlineSeconds).
42-
TimedOutReason = "ProgressDeadlineExceeded"
43-
// PausedDeployReason is added in a deployment config when it is paused. Lack of progress shouldn't be
44-
// estimated once a deployment config is paused.
45-
PausedDeployReason = "DeploymentConfigPaused"
46-
// ResumedDeployReason is added in a deployment config when it is resumed. Useful for not failing accidentally
47-
// deployment configs that paused amidst a rollout.
48-
ResumedDeployReason = "DeploymentConfigResumed"
49-
)
50-
5124
// NewDeploymentCondition creates a new deployment condition.
52-
func NewDeploymentCondition(condType deployapi.DeploymentConditionType, status api.ConditionStatus, reason, message string) *deployapi.DeploymentCondition {
25+
func NewDeploymentCondition(condType deployapi.DeploymentConditionType, status api.ConditionStatus, reason deployapi.DeploymentConditionReason, message string) *deployapi.DeploymentCondition {
5326
return &deployapi.DeploymentCondition{
5427
Type: condType,
5528
Status: status,

pkg/deploy/util/util_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ var (
363363
Type: deployapi.DeploymentProgressing,
364364
Status: kapi.ConditionTrue,
365365
LastTransitionTime: now,
366-
Reason: "ForSomeReason",
367366
}
368367
}
369368

@@ -372,7 +371,6 @@ var (
372371
Type: deployapi.DeploymentProgressing,
373372
Status: kapi.ConditionTrue,
374373
LastTransitionTime: later,
375-
Reason: "ForSomeReason",
376374
}
377375
}
378376

@@ -381,7 +379,7 @@ var (
381379
Type: deployapi.DeploymentProgressing,
382380
Status: kapi.ConditionTrue,
383381
LastTransitionTime: later,
384-
Reason: "BecauseItIs",
382+
Reason: deployapi.NewReplicationControllerReason,
385383
}
386384
}
387385

@@ -391,15 +389,13 @@ var (
391389
Status: kapi.ConditionFalse,
392390
LastUpdateTime: earlier,
393391
LastTransitionTime: earlier,
394-
Reason: "NotYet",
395392
}
396393
}
397394

398395
condAvailable = func() deployapi.DeploymentCondition {
399396
return deployapi.DeploymentCondition{
400397
Type: deployapi.DeploymentAvailable,
401398
Status: kapi.ConditionTrue,
402-
Reason: "AwesomeController",
403399
}
404400
}
405401
)
@@ -417,7 +413,6 @@ func TestGetCondition(t *testing.T) {
417413
status deployapi.DeploymentConfigStatus
418414
condType deployapi.DeploymentConditionType
419415
condStatus kapi.ConditionStatus
420-
condReason string
421416

422417
expected bool
423418
}{
@@ -515,7 +510,7 @@ func TestSetCondition(t *testing.T) {
515510
// Note that LastTransitionTime stays the same.
516511
LastTransitionTime: now,
517512
// Only the reason changes.
518-
Reason: "BecauseItIs",
513+
Reason: deployapi.NewReplicationControllerReason,
519514
},
520515
},
521516
},

test/extended/deployments/deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ var _ = g.Describe("deploymentconfigs", func() {
889889
}
890890
conditions = dc.Status.Conditions
891891
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
892-
return cond != nil && cond.Reason == deployutil.NewReplicationControllerReason, nil
892+
return cond != nil && cond.Reason == deployapi.NewReplicationControllerReason, nil
893893
})
894894
if err == wait.ErrWaitTimeout {
895895
err = fmt.Errorf("deployment config %q never updated its conditions: %#v", name, conditions)

test/extended/deployments/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func deploymentReachedCompletion(dc *deployapi.DeploymentConfig, rcs []*kapi.Rep
177177
return false, nil
178178
}
179179
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
180-
if cond == nil || cond.Reason != deployutil.NewRcAvailableReason {
180+
if cond == nil || cond.Reason != deployapi.NewRcAvailableReason {
181181
return false, nil
182182
}
183183
expectedReplicas := dc.Spec.Replicas
@@ -208,7 +208,7 @@ func deploymentFailed(dc *deployapi.DeploymentConfig, rcs []*kapi.ReplicationCon
208208
return false, nil
209209
}
210210
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
211-
return cond != nil && cond.Reason == deployutil.TimedOutReason, nil
211+
return cond != nil && cond.Reason == deployapi.TimedOutReason, nil
212212
}
213213

214214
func deploymentRunning(dc *deployapi.DeploymentConfig, rcs []*kapi.ReplicationController, pods []kapi.Pod) (bool, error) {

0 commit comments

Comments
 (0)