add abnormally progressing condition to let users know some special cases

Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
This commit is contained in:
mingzhou.swx 2022-09-16 14:38:04 +08:00
parent f21c3fb763
commit 3cb4218a5a
2 changed files with 43 additions and 6 deletions

View File

@ -217,6 +217,13 @@ const (
// Terminating Reason // Terminating Reason
TerminatingReasonInTerminating = "InTerminating" TerminatingReasonInTerminating = "InTerminating"
TerminatingReasonCompleted = "Completed" TerminatingReasonCompleted = "Completed"
// RolloutConditionAbnormallyProgressing means the rollout want to progress, but abnormally.
RolloutConditionAbnormallyProgressing RolloutConditionType = "AbnormallyProgressing"
// AbnormallyProgressingReasonInvalidRolloutIDChange is the case that rollout id is changed, but workload revision not.
AbnormallyProgressingReasonInvalidRolloutIDChange = "InvalidRolloutIDChange"
// AbnormallyProgressingReasonFirstDeploy is the case that Rollout or workload is deployed at first, rollout will not progress.
AbnormallyProgressingReasonFirstDeploy = "FirstDeploy"
) )
// CanaryStatus status fields that only pertain to the canary rollout // CanaryStatus status fields that only pertain to the canary rollout

View File

@ -26,6 +26,7 @@ import (
rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1" rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1"
"github.com/openkruise/rollouts/pkg/util" "github.com/openkruise/rollouts/pkg/util"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/util/retry" "k8s.io/client-go/util/retry"
@ -77,15 +78,27 @@ func (r *RolloutReconciler) updateRolloutStatus(rollout *rolloutv1alpha1.Rollout
done = false done = false
return return
} }
newStatus.StableRevision = workload.StableRevision
// update workload generation to canaryStatus.ObservedWorkloadGeneration // update workload generation to canaryStatus.ObservedWorkloadGeneration
// rollout is a target ref bypass, so there needs to be a field to identify the rollout execution process or results, // rollout is a target ref bypass, so there needs to be a field to identify the rollout execution process or results,
// which version of deployment is targeted, ObservedWorkloadGeneration that is to compare with the workload generation // which version of deployment is targeted, ObservedWorkloadGeneration that is to compare with the workload generation
if newStatus.CanaryStatus != nil && newStatus.CanaryStatus.CanaryRevision != "" && if newStatus.CanaryStatus != nil && newStatus.CanaryStatus.CanaryRevision != "" {
newStatus.CanaryStatus.CanaryRevision == workload.CanaryRevision { if newStatus.CanaryStatus.CanaryRevision == workload.CanaryRevision {
newStatus.CanaryStatus.ObservedRolloutID = getRolloutID(workload, rollout) currentRolloutID := getRolloutID(workload, rollout)
newStatus.CanaryStatus.ObservedWorkloadGeneration = workload.Generation if newStatus.CanaryStatus.ObservedRolloutID != "" &&
newStatus.CanaryStatus.ObservedRolloutID != currentRolloutID &&
newStatus.StableRevision == workload.StableRevision { // except rollout case
abnormallyProgressingConditionTransition(&newStatus, rolloutv1alpha1.AbnormallyProgressingReasonInvalidRolloutIDChange)
} }
newStatus.CanaryStatus.ObservedRolloutID = currentRolloutID
newStatus.CanaryStatus.ObservedWorkloadGeneration = workload.Generation
} else if newStatus.CanaryStatus.CanaryRevision != workload.CanaryRevision || // try to publish a new revision
newStatus.CanaryStatus.CanaryRevision != workload.StableRevision { // try to rollback
// if a new release is published or try to roll back, remove the condition
util.RemoveRolloutCondition(&newStatus, rolloutv1alpha1.RolloutConditionAbnormallyProgressing)
}
}
newStatus.StableRevision = workload.StableRevision
switch newStatus.Phase { switch newStatus.Phase {
case rolloutv1alpha1.RolloutPhaseInitial: case rolloutv1alpha1.RolloutPhaseInitial:
@ -112,7 +125,6 @@ func (r *RolloutReconciler) updateRolloutStatus(rollout *rolloutv1alpha1.Rollout
// But at the first deployment of Rollout/Workload, CanaryStatus isn't set due to no rollout progression, // 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 // 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. // to update the status just like the rollout was completed.
newStatus.CanaryStatus = &rolloutv1alpha1.CanaryStatus{ newStatus.CanaryStatus = &rolloutv1alpha1.CanaryStatus{
CanaryReplicas: workload.CanaryReplicas, CanaryReplicas: workload.CanaryReplicas,
CanaryReadyReplicas: workload.CanaryReadyReplicas, CanaryReadyReplicas: workload.CanaryReadyReplicas,
@ -124,6 +136,7 @@ func (r *RolloutReconciler) updateRolloutStatus(rollout *rolloutv1alpha1.Rollout
CurrentStepState: rolloutv1alpha1.CanaryStepStateCompleted, CurrentStepState: rolloutv1alpha1.CanaryStepStateCompleted,
} }
newStatus.Message = "workload deployment is completed" newStatus.Message = "workload deployment is completed"
abnormallyProgressingConditionTransition(&newStatus, rolloutv1alpha1.AbnormallyProgressingReasonFirstDeploy)
} }
case rolloutv1alpha1.RolloutPhaseProgressing: case rolloutv1alpha1.RolloutPhaseProgressing:
cond := util.GetRolloutCondition(newStatus, rolloutv1alpha1.RolloutConditionProgressing) cond := util.GetRolloutCondition(newStatus, rolloutv1alpha1.RolloutConditionProgressing)
@ -165,6 +178,7 @@ func resetStatus(status *rolloutv1alpha1.RolloutStatus) {
//util.RemoveRolloutCondition(status, rolloutv1alpha1.RolloutConditionProgressing) //util.RemoveRolloutCondition(status, rolloutv1alpha1.RolloutConditionProgressing)
status.Phase = rolloutv1alpha1.RolloutPhaseInitial status.Phase = rolloutv1alpha1.RolloutPhaseInitial
status.Message = "workload not found" status.Message = "workload not found"
util.RemoveRolloutCondition(status, rolloutv1alpha1.RolloutConditionAbnormallyProgressing)
} }
func (r *RolloutReconciler) calculateRolloutHash(rollout *rolloutv1alpha1.Rollout) error { func (r *RolloutReconciler) calculateRolloutHash(rollout *rolloutv1alpha1.Rollout) error {
@ -196,3 +210,19 @@ func (r *RolloutReconciler) calculateRolloutHash(rollout *rolloutv1alpha1.Rollou
func hash(data string) string { func hash(data string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(data))) return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
} }
func abnormallyProgressingConditionTransition(newStatus *rolloutv1alpha1.RolloutStatus, reason string) {
var message string
var status corev1.ConditionStatus = "False"
switch reason {
case rolloutv1alpha1.AbnormallyProgressingReasonInvalidRolloutIDChange:
status = corev1.ConditionStatus(v1.ConditionTrue)
message = "rollout id changed, but workload revision not"
case rolloutv1alpha1.AbnormallyProgressingReasonFirstDeploy:
status = corev1.ConditionStatus(v1.ConditionTrue)
message = "it is the first deployment of rollout or workload"
}
newCond := util.NewRolloutCondition(rolloutv1alpha1.RolloutConditionAbnormallyProgressing, status, reason, message)
_ = util.SetRolloutCondition(newStatus, *newCond)
}