forked from argoproj/argo-rollouts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditions and duration to experiments
- Loading branch information
1 parent
4205f99
commit 98f1bdb
Showing
14 changed files
with
1,087 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package experiments | ||
|
||
import ( | ||
"fmt" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
"github.com/argoproj/argo-rollouts/utils/conditions" | ||
) | ||
|
||
func (ec *ExperimentController) calculateExperimentConditions(experiment *v1alpha1.Experiment, newStatus v1alpha1.ExperimentStatus, templateRSs map[string]*appsv1.ReplicaSet) v1alpha1.ExperimentStatus { | ||
switch { | ||
case conditions.ExperimentCompleted(newStatus): | ||
msg := fmt.Sprintf(conditions.ExperimentCompletedMessage, experiment.Name) | ||
condition := conditions.NewExperimentConditions(v1alpha1.ExperimentProgressing, corev1.ConditionFalse, conditions.ExperimentCompleteReason, msg) | ||
conditions.SetExperimentCondition(&newStatus, *condition) | ||
case conditions.ExperimentProgressing(experiment, newStatus): | ||
currentCond := conditions.GetExperimentCondition(experiment.Status, v1alpha1.ExperimentProgressing) | ||
// If there is any progress made, continue by not checking if the experiment failed. This | ||
// behavior emulates the rolling updater progressDeadline check. | ||
msg := fmt.Sprintf(conditions.ExperimentProgressingMessage, experiment.Name) | ||
condition := conditions.NewExperimentConditions(v1alpha1.ExperimentProgressing, corev1.ConditionTrue, conditions.ReplicaSetUpdatedReason, msg) | ||
// Update the current Progressing condition or add a new one if it doesn't exist. | ||
// If a Progressing condition with status=true already exists, we should update | ||
// everything but lastTransitionTime. SetExperimentCondition already does that but | ||
// it also is not updating conditions when the reason of the new condition is the | ||
// same as the old. The Progressing condition is a special case because we want to | ||
// update with the same reason and change just lastUpdateTime iff we notice any | ||
// progress. That's why we handle it here. | ||
if currentCond != nil { | ||
if currentCond.Status == corev1.ConditionTrue { | ||
condition.LastTransitionTime = currentCond.LastTransitionTime | ||
} | ||
conditions.RemoveExperimentCondition(&newStatus, v1alpha1.ExperimentProgressing) | ||
} | ||
conditions.SetExperimentCondition(&newStatus, *condition) | ||
case conditions.ExperimentRunning(experiment): | ||
// Update the experiment conditions with a message for the new replica sets that | ||
// was successfully deployed and is running for the timed duration from the | ||
// `spec.duration` field. If the condition already exists, we ignore this update. | ||
msg := fmt.Sprintf(conditions.ExperimentRunningMessage, experiment.Name) | ||
condition := conditions.NewExperimentConditions(v1alpha1.ExperimentProgressing, corev1.ConditionTrue, conditions.NewRSAvailableReason, msg) | ||
conditions.SetExperimentCondition(&newStatus, *condition) | ||
case conditions.ExperimentTimeOut(experiment, newStatus): | ||
// Update the experiments with a timeout condition. If the condition already exists, | ||
// we ignore this update. | ||
msg := fmt.Sprintf(conditions.ExperimentTimeOutMessage, experiment.Name) | ||
condition := conditions.NewExperimentConditions(v1alpha1.ExperimentProgressing, corev1.ConditionFalse, conditions.TimedOutReason, msg) | ||
conditions.SetExperimentCondition(&newStatus, *condition) | ||
} | ||
return newStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package experiments | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/pointer" | ||
|
||
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
"github.com/argoproj/argo-rollouts/utils/conditions" | ||
) | ||
|
||
func TestUpdateProgressingLastUpdateTime(t *testing.T) { | ||
f := newFixture(t) | ||
defer f.Close() | ||
|
||
templates := generateTemplates("bar") | ||
templates[0].Replicas = pointer.Int32Ptr(2) | ||
e := newExperiment("foo", templates, 0, pointer.BoolPtr(true)) | ||
e.Status.TemplateStatuses = []v1alpha1.TemplateStatus{{ | ||
Name: "bar", | ||
}} | ||
prevCond := newCondition(conditions.ReplicaSetUpdatedReason, e) | ||
prevTime := metav1.NewTime(metav1.Now().Add(-10 * time.Second)) | ||
prevCond.LastUpdateTime = prevTime | ||
prevCond.LastTransitionTime = prevTime | ||
e.Status.Conditions = []v1alpha1.ExperimentCondition{ | ||
*prevCond, | ||
} | ||
|
||
f.experimentLister = append(f.experimentLister, e) | ||
f.objects = append(f.objects, e) | ||
rs := templateToRS(e, templates[0], 1) | ||
f.replicaSetLister = append(f.replicaSetLister, rs) | ||
f.kubeobjects = append(f.kubeobjects, rs) | ||
|
||
patchIndex := f.expectPatchExperimentAction(e) | ||
|
||
f.run(getKey(e, t)) | ||
|
||
patch := f.getPatchedExperiment(patchIndex) | ||
cond := []v1alpha1.ExperimentCondition{*newCondition(conditions.ReplicaSetUpdatedReason, e)} | ||
cond[0].LastTransitionTime = prevTime.Rfc3339Copy() | ||
templateStatuses := []v1alpha1.TemplateStatus{ | ||
generateTemplatesStatus("bar", 1, 1), | ||
} | ||
validatePatch(t, patch, nil, NoChange, templateStatuses, cond) | ||
} | ||
|
||
func TestEnterTimeoutDegradedState(t *testing.T) { | ||
f := newFixture(t) | ||
defer f.Close() | ||
|
||
templates := generateTemplates("bar") | ||
e := newExperiment("foo", templates, 0, pointer.BoolPtr(true)) | ||
e.Status.TemplateStatuses = []v1alpha1.TemplateStatus{{ | ||
Name: "bar", | ||
}} | ||
e.Spec.ProgressDeadlineSeconds = pointer.Int32Ptr(30) | ||
prevCond := newCondition(conditions.ReplicaSetUpdatedReason, e) | ||
prevTime := metav1.NewTime(metav1.Now().Add(-1 * time.Minute)) | ||
prevCond.LastUpdateTime = prevTime | ||
prevCond.LastTransitionTime = prevTime | ||
e.Status.Conditions = []v1alpha1.ExperimentCondition{ | ||
*prevCond, | ||
} | ||
|
||
f.experimentLister = append(f.experimentLister, e) | ||
f.objects = append(f.objects, e) | ||
rs := templateToRS(e, templates[0], 0) | ||
f.replicaSetLister = append(f.replicaSetLister, rs) | ||
f.kubeobjects = append(f.kubeobjects, rs) | ||
|
||
patchIndex := f.expectPatchExperimentAction(e) | ||
|
||
f.run(getKey(e, t)) | ||
|
||
patch := f.getPatchedExperiment(patchIndex) | ||
cond := []v1alpha1.ExperimentCondition{*newCondition(conditions.TimedOutReason, e)} | ||
validatePatch(t, patch, nil, NoChange, nil, cond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.