update canary status after the first deployment of rollout (#72)

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
Co-authored-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
This commit is contained in:
Wei-Xiang Sun 2022-09-01 14:39:35 +08:00 committed by GitHub
parent 7a39b8103d
commit e1ba1b0ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 9 deletions

View File

@ -93,12 +93,37 @@ func (r *RolloutReconciler) updateRolloutStatus(rollout *rolloutv1alpha1.Rollout
newStatus.Phase = rolloutv1alpha1.RolloutPhaseHealthy
newStatus.Message = "rollout is healthy"
case rolloutv1alpha1.RolloutPhaseHealthy:
// from healthy to progressing
if workload.InRolloutProgressing {
// from healthy to progressing
klog.Infof("rollout(%s/%s) status phase from(%s) -> to(%s)", rollout.Namespace, rollout.Name, rolloutv1alpha1.RolloutPhaseHealthy, rolloutv1alpha1.RolloutPhaseProgressing)
newStatus.Phase = rolloutv1alpha1.RolloutPhaseProgressing
cond := util.NewRolloutCondition(rolloutv1alpha1.RolloutConditionProgressing, corev1.ConditionFalse, rolloutv1alpha1.ProgressingReasonInitializing, "Rollout is in Progressing")
util.SetRolloutCondition(&newStatus, *cond)
} else if workload.IsInStable && newStatus.CanaryStatus == nil {
// The following logic is to make PaaS be able to judge whether the rollout is ready
// at the first deployment of the Rollout/Workload. For example: generally, a PaaS
// platform can use the following code to judge whether the rollout progression is completed:
// ```
// if getRolloutID(workload, rollout) == rollout.Status.CanaryStatus.ObservedRolloutID &&
// rollout.Status.CanaryStatus.CurrentStepState == "Completed" {
// // do something after rollout
// }
//```
// But at the first deployment of Rollout/Workload, CanaryStatus isn't set due to no rollout progression,
// and PaaS platform cannot judge whether the deployment is completed base on the code above. So we have
// to update the status just like the rollout was completed.
newStatus.CanaryStatus = &rolloutv1alpha1.CanaryStatus{
CanaryReplicas: workload.CanaryReplicas,
CanaryReadyReplicas: workload.CanaryReadyReplicas,
ObservedRolloutID: getRolloutID(workload, rollout),
ObservedWorkloadGeneration: workload.Generation,
PodTemplateHash: workload.PodTemplateHash,
CanaryRevision: workload.CanaryRevision,
CurrentStepIndex: int32(len(rollout.Spec.Strategy.Canary.Steps)),
CurrentStepState: rolloutv1alpha1.CanaryStepStateCompleted,
}
newStatus.Message = "workload deployment is completed"
}
case rolloutv1alpha1.RolloutPhaseProgressing:
cond := util.GetRolloutCondition(newStatus, rolloutv1alpha1.RolloutConditionProgressing)

View File

@ -54,6 +54,8 @@ type Workload struct {
// Revision hash key
RevisionLabelKey string
// Is it in stable and no need to publish
IsInStable bool
// Is it in rollback phase
IsInRollback bool
// indicate whether the workload can enter the rollout process
@ -140,13 +142,15 @@ func (r *ControllerFinder) getKruiseCloneSet(namespace string, ref *rolloutv1alp
PodTemplateHash: cloneSet.Status.UpdateRevision[strings.LastIndex(cloneSet.Status.UpdateRevision, "-")+1:],
IsStatusConsistent: true,
}
// not in rollout progressing
if _, ok = workload.Annotations[InRolloutProgressingAnnotation]; !ok {
return workload, nil
}
// no need to progress
if cloneSet.Status.Replicas == cloneSet.Status.UpdatedReplicas && cloneSet.Status.CurrentRevision == cloneSet.Status.UpdateRevision {
workload.IsInStable = true
return workload, nil
}
// not in rollout progressing
if _, ok = workload.Annotations[InRolloutProgressingAnnotation]; !ok {
return workload, nil
}
@ -192,6 +196,12 @@ func (r *ControllerFinder) getDeployment(namespace string, ref *rolloutv1alpha1.
CanaryRevision: ComputeHash(&stable.Spec.Template, nil),
RevisionLabelKey: apps.DefaultDeploymentUniqueLabelKey,
}
// deployment is stable
if stable.Status.Replicas == stable.Status.UpdatedReplicas {
workload.IsInStable = true
}
// not in rollout progressing
if _, ok = workload.Annotations[InRolloutProgressingAnnotation]; !ok {
return workload, nil
@ -256,13 +266,15 @@ func (r *ControllerFinder) getStatefulSetLikeWorkload(namespace string, ref *rol
PodTemplateHash: workloadInfo.Status.UpdateRevision,
IsStatusConsistent: true,
}
// not in rollout progressing
if _, ok := workload.Annotations[InRolloutProgressingAnnotation]; !ok {
return workload, nil
}
// no need to progress
if workloadInfo.Status.Replicas == workloadInfo.Status.UpdatedReplicas && workloadInfo.Status.StableRevision == workloadInfo.Status.UpdateRevision {
workload.IsInStable = true
return workload, nil
}
// not in rollout progressing
if _, ok := workload.Annotations[InRolloutProgressingAnnotation]; !ok {
return workload, nil
}