Skip to content

Commit

Permalink
Merge pull request #13813 from mfojtik/cancel-condition
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Apr 25, 2017
2 parents 9334452 + 5f32644 commit 3271ed1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 50 deletions.
32 changes: 31 additions & 1 deletion pkg/deploy/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,36 @@ const (
DeploymentReplicaFailure DeploymentConditionType = "ReplicaFailure"
)

type DeploymentConditionReason string

const (
// ReplicationControllerUpdatedReason is added in a deployment config when one of its replication
// controllers is updated as part of the rollout process.
ReplicationControllerUpdatedReason DeploymentConditionReason = "ReplicationControllerUpdated"
// FailedRcCreateReason is added in a deployment config when it cannot create a new replication
// controller.
FailedRcCreateReason DeploymentConditionReason = "ReplicationControllerCreateError"
// NewReplicationControllerReason is added in a deployment config when it creates a new replication
// controller.
NewReplicationControllerReason DeploymentConditionReason = "NewReplicationControllerCreated"
// NewRcAvailableReason is added in a deployment config when its newest replication controller is made
// available ie. the number of new pods that have passed readiness checks and run for at least
// minReadySeconds is at least the minimum available pods that need to run for the deployment config.
NewRcAvailableReason DeploymentConditionReason = "NewReplicationControllerAvailable"
// TimedOutReason is added in a deployment config when its newest replication controller fails to show
// any progress within the given deadline (progressDeadlineSeconds).
TimedOutReason DeploymentConditionReason = "ProgressDeadlineExceeded"
// PausedConfigReason is added in a deployment config when it is paused. Lack of progress shouldn't be
// estimated once a deployment config is paused.
PausedConfigReason DeploymentConditionReason = "DeploymentConfigPaused"
// ResumedConfigReason is added in a deployment config when it is resumed. Useful for not failing accidentally
// deployment configs that paused amidst a rollout.
ResumedConfigReason DeploymentConditionReason = "DeploymentConfigResumed"
// CancelledRolloutReason is added in a deployment config when its newest rollout was
// interrupted by cancellation.
CancelledRolloutReason DeploymentConditionReason = "RolloutCancelled"
)

// DeploymentCondition describes the state of a deployment config at a certain point.
type DeploymentCondition struct {
// Type of deployment condition.
Expand All @@ -450,7 +480,7 @@ type DeploymentCondition struct {
// The last time the condition transitioned from one status to another.
LastTransitionTime unversioned.Time
// The reason for the condition's last transition.
Reason string
Reason DeploymentConditionReason
// A human readable message indicating details about the transition.
Message string
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/api/v1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func autoConvert_v1_DeploymentCondition_To_api_DeploymentCondition(in *Deploymen
out.Status = pkg_api.ConditionStatus(in.Status)
out.LastUpdateTime = in.LastUpdateTime
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Reason = api.DeploymentConditionReason(in.Reason)
out.Message = in.Message
return nil
}
Expand All @@ -188,7 +188,7 @@ func autoConvert_api_DeploymentCondition_To_v1_DeploymentCondition(in *api.Deplo
out.Status = api_v1.ConditionStatus(in.Status)
out.LastUpdateTime = in.LastUpdateTime
out.LastTransitionTime = in.LastTransitionTime
out.Reason = in.Reason
out.Reason = string(in.Reason)
out.Message = in.Message
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/deploy/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ func (s *DeploymentConfigStatusViewer) Status(namespace, name string, desiredRev

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

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

case cond != nil && cond.Reason == deployutil.PausedDeployReason:
case cond != nil && cond.Reason == deployapi.CancelledRolloutReason:
return "", true, errors.New(cond.Message)

case cond != nil && cond.Reason == deployapi.PausedConfigReason:
return "", true, fmt.Errorf("Deployment config %q is paused. Resume to continue watching the status of the rollout.\n", config.Name)

case config.Status.UpdatedReplicas < config.Spec.Replicas:
Expand Down
18 changes: 12 additions & 6 deletions pkg/deploy/controller/deploymentconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
}
c.recorder.Eventf(config, kapi.EventTypeWarning, "DeploymentCreationFailed", "Couldn't deploy version %d: %s", config.Status.LatestVersion, err)
// We don't care about this error since we need to report the create failure.
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployutil.FailedRcCreateReason, err.Error())
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.FailedRcCreateReason, err.Error())
_ = c.updateStatus(config, existingDeployments, *cond)
return fmt.Errorf("couldn't create deployment for deployment config %s: %v", deployutil.LabelForDeploymentConfig(config), err)
}
Expand All @@ -203,7 +203,7 @@ func (c *DeploymentConfigController) Handle(config *deployapi.DeploymentConfig)
c.recorder.Eventf(config, kapi.EventTypeWarning, "DeploymentCleanupFailed", "Couldn't clean up deployments: %v", err)
}

cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.NewReplicationControllerReason, msg)
cond := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.NewReplicationControllerReason, msg)
return c.updateStatus(config, existingDeployments, *cond)
}

Expand Down Expand Up @@ -368,18 +368,24 @@ func updateConditions(config deployapi.DeploymentConfig, newStatus *deployapi.De
if deployutil.IsProgressing(config, *newStatus) {
deployutil.RemoveDeploymentCondition(newStatus, deployapi.DeploymentProgressing)
msg := fmt.Sprintf("replication controller %q is progressing", latestRC.Name)
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.ReplicationControllerUpdatedReason, msg)
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.ReplicationControllerUpdatedReason, msg)
// TODO: Right now, we use lastTransitionTime for storing the last time we had any progress instead
// of the last time the condition transitioned to a new status. We should probably change that.
deployutil.SetDeploymentCondition(newStatus, *condition)
}
case deployapi.DeploymentStatusFailed:
msg := fmt.Sprintf("replication controller %q has failed progressing", latestRC.Name)
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployutil.TimedOutReason, msg)
var condition *deployapi.DeploymentCondition
if deployutil.IsDeploymentCancelled(latestRC) {
msg := fmt.Sprintf("rollout of replication controller %q was cancelled", latestRC.Name)
condition = deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.CancelledRolloutReason, msg)
} else {
msg := fmt.Sprintf("replication controller %q has failed progressing", latestRC.Name)
condition = deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionFalse, deployapi.TimedOutReason, msg)
}
deployutil.SetDeploymentCondition(newStatus, *condition)
case deployapi.DeploymentStatusComplete:
msg := fmt.Sprintf("replication controller %q successfully rolled out", latestRC.Name)
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployutil.NewRcAvailableReason, msg)
condition := deployutil.NewDeploymentCondition(deployapi.DeploymentProgressing, kapi.ConditionTrue, deployapi.NewRcAvailableReason, msg)
deployutil.SetDeploymentCondition(newStatus, *condition)
}
}
Expand Down
29 changes: 1 addition & 28 deletions pkg/deploy/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,8 @@ import (
"github.com/openshift/origin/pkg/util/namer"
)

const (
// Reasons for deployment config conditions:
//
// ReplicationControllerUpdatedReason is added in a deployment config when one of its replication
// controllers is updated as part of the rollout process.
ReplicationControllerUpdatedReason = "ReplicationControllerUpdated"
// FailedRcCreateReason is added in a deployment config when it cannot create a new replication
// controller.
FailedRcCreateReason = "ReplicationControllerCreateError"
// NewReplicationControllerReason is added in a deployment config when it creates a new replication
// controller.
NewReplicationControllerReason = "NewReplicationControllerCreated"
// NewRcAvailableReason is added in a deployment config when its newest replication controller is made
// available ie. the number of new pods that have passed readiness checks and run for at least
// minReadySeconds is at least the minimum available pods that need to run for the deployment config.
NewRcAvailableReason = "NewReplicationControllerAvailable"
// TimedOutReason is added in a deployment config when its newest replication controller fails to show
// any progress within the given deadline (progressDeadlineSeconds).
TimedOutReason = "ProgressDeadlineExceeded"
// PausedDeployReason is added in a deployment config when it is paused. Lack of progress shouldn't be
// estimated once a deployment config is paused.
PausedDeployReason = "DeploymentConfigPaused"
// ResumedDeployReason is added in a deployment config when it is resumed. Useful for not failing accidentally
// deployment configs that paused amidst a rollout.
ResumedDeployReason = "DeploymentConfigResumed"
)

// NewDeploymentCondition creates a new deployment condition.
func NewDeploymentCondition(condType deployapi.DeploymentConditionType, status api.ConditionStatus, reason, message string) *deployapi.DeploymentCondition {
func NewDeploymentCondition(condType deployapi.DeploymentConditionType, status api.ConditionStatus, reason deployapi.DeploymentConditionReason, message string) *deployapi.DeploymentCondition {
return &deployapi.DeploymentCondition{
Type: condType,
Status: status,
Expand Down
9 changes: 2 additions & 7 deletions pkg/deploy/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ var (
Type: deployapi.DeploymentProgressing,
Status: kapi.ConditionTrue,
LastTransitionTime: now,
Reason: "ForSomeReason",
}
}

Expand All @@ -372,7 +371,6 @@ var (
Type: deployapi.DeploymentProgressing,
Status: kapi.ConditionTrue,
LastTransitionTime: later,
Reason: "ForSomeReason",
}
}

Expand All @@ -381,7 +379,7 @@ var (
Type: deployapi.DeploymentProgressing,
Status: kapi.ConditionTrue,
LastTransitionTime: later,
Reason: "BecauseItIs",
Reason: deployapi.NewReplicationControllerReason,
}
}

Expand All @@ -391,15 +389,13 @@ var (
Status: kapi.ConditionFalse,
LastUpdateTime: earlier,
LastTransitionTime: earlier,
Reason: "NotYet",
}
}

condAvailable = func() deployapi.DeploymentCondition {
return deployapi.DeploymentCondition{
Type: deployapi.DeploymentAvailable,
Status: kapi.ConditionTrue,
Reason: "AwesomeController",
}
}
)
Expand All @@ -417,7 +413,6 @@ func TestGetCondition(t *testing.T) {
status deployapi.DeploymentConfigStatus
condType deployapi.DeploymentConditionType
condStatus kapi.ConditionStatus
condReason string

expected bool
}{
Expand Down Expand Up @@ -515,7 +510,7 @@ func TestSetCondition(t *testing.T) {
// Note that LastTransitionTime stays the same.
LastTransitionTime: now,
// Only the reason changes.
Reason: "BecauseItIs",
Reason: deployapi.NewReplicationControllerReason,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/extended/deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ var _ = g.Describe("deploymentconfigs", func() {
}
conditions = dc.Status.Conditions
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
return cond != nil && cond.Reason == deployutil.NewReplicationControllerReason, nil
return cond != nil && cond.Reason == deployapi.NewReplicationControllerReason, nil
})
if err == wait.ErrWaitTimeout {
err = fmt.Errorf("deployment config %q never updated its conditions: %#v", name, conditions)
Expand Down
4 changes: 2 additions & 2 deletions test/extended/deployments/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func deploymentReachedCompletion(dc *deployapi.DeploymentConfig, rcs []*kapi.Rep
return false, nil
}
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
if cond == nil || cond.Reason != deployutil.NewRcAvailableReason {
if cond == nil || cond.Reason != deployapi.NewRcAvailableReason {
return false, nil
}
expectedReplicas := dc.Spec.Replicas
Expand Down Expand Up @@ -208,7 +208,7 @@ func deploymentFailed(dc *deployapi.DeploymentConfig, rcs []*kapi.ReplicationCon
return false, nil
}
cond := deployutil.GetDeploymentCondition(dc.Status, deployapi.DeploymentProgressing)
return cond != nil && cond.Reason == deployutil.TimedOutReason, nil
return cond != nil && cond.Reason == deployapi.TimedOutReason, nil
}

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

0 comments on commit 3271ed1

Please sign in to comment.