diff --git a/manifests/crds/rollout-crd.yaml b/manifests/crds/rollout-crd.yaml index ae0fdea244..6b895d4d92 100644 --- a/manifests/crds/rollout-crd.yaml +++ b/manifests/crds/rollout-crd.yaml @@ -172,6 +172,29 @@ spec: type: object experiment: properties: + analysis: + properties: + arguments: + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + podTemplateHashValue: + type: string + type: object + required: + - name + type: object + type: array + templateName: + type: string + required: + - templateName + type: object duration: format: int32 type: integer diff --git a/manifests/install.yaml b/manifests/install.yaml index f77da00497..86e4ada011 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -7899,6 +7899,29 @@ spec: type: object experiment: properties: + analysis: + properties: + arguments: + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + podTemplateHashValue: + type: string + type: object + required: + - name + type: object + type: array + templateName: + type: string + required: + - templateName + type: object duration: format: int32 type: integer diff --git a/manifests/namespace-install.yaml b/manifests/namespace-install.yaml index 45d58c4fc0..a9e9956bf9 100644 --- a/manifests/namespace-install.yaml +++ b/manifests/namespace-install.yaml @@ -7899,6 +7899,29 @@ spec: type: object experiment: properties: + analysis: + properties: + arguments: + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + podTemplateHashValue: + type: string + type: object + required: + - name + type: object + type: array + templateName: + type: string + required: + - templateName + type: object duration: format: int32 type: integer diff --git a/pkg/apis/rollouts/v1alpha1/openapi_generated.go b/pkg/apis/rollouts/v1alpha1/openapi_generated.go index d3dc91e322..fee125f9d7 100644 --- a/pkg/apis/rollouts/v1alpha1/openapi_generated.go +++ b/pkg/apis/rollouts/v1alpha1/openapi_generated.go @@ -1149,7 +1149,7 @@ func schema_pkg_apis_rollouts_v1alpha1_Measurement(ref common.ReferenceCallback) }, "resumeAt": { SchemaProps: spec.SchemaProps{ - Description: "ResumeAt is the earliest timestamp when the analysisRun should take another measurement for the metric", + Description: "ResumeAt is the timestamp when the analysisRun should try to resume the measurement", Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), }, }, @@ -1617,12 +1617,18 @@ func schema_pkg_apis_rollouts_v1alpha1_RolloutExperimentStep(ref common.Referenc }, }, }, + "analysis": { + SchemaProps: spec.SchemaProps{ + Description: "AnalysisTemplate what analysis to run with the experiment", + Ref: ref("github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1.RolloutAnalysisStep"), + }, + }, }, Required: []string{"duration", "templates"}, }, }, Dependencies: []string{ - "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1.RolloutExperimentTemplate"}, + "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1.RolloutAnalysisStep", "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1.RolloutExperimentTemplate"}, } } diff --git a/pkg/apis/rollouts/v1alpha1/types.go b/pkg/apis/rollouts/v1alpha1/types.go index ed6c5b8978..8cb36e309b 100644 --- a/pkg/apis/rollouts/v1alpha1/types.go +++ b/pkg/apis/rollouts/v1alpha1/types.go @@ -152,7 +152,8 @@ type RolloutExperimentStep struct { Duration int32 `json:"duration"` // Templates what templates that should be added to the experiment. Should be non-nil Templates []RolloutExperimentTemplate `json:"templates"` - //ProgressingDeadlineSeconds Is it ncessary? + //AnalysisTemplate what analysis to run with the experiment + Analysis *RolloutAnalysisStep `json:"analysis,omitempty"` } // RolloutExperimentTemplate defines the template used to create experiments for the Rollout's experiment canary step diff --git a/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go index a7b2e261b8..47a20b9cd8 100644 --- a/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go @@ -899,6 +899,11 @@ func (in *RolloutExperimentStep) DeepCopyInto(out *RolloutExperimentStep) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Analysis != nil { + in, out := &in.Analysis, &out.Analysis + *out = new(RolloutAnalysisStep) + (*in).DeepCopyInto(*out) + } return } diff --git a/rollout/experiment.go b/rollout/experiment.go index 9736e98f0e..482d1f3769 100644 --- a/rollout/experiment.go +++ b/rollout/experiment.go @@ -12,6 +12,7 @@ import ( "k8s.io/utils/pointer" "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" + analysisutil "github.com/argoproj/argo-rollouts/utils/analysis" "github.com/argoproj/argo-rollouts/utils/defaults" experimentutil "github.com/argoproj/argo-rollouts/utils/experiment" replicasetutil "github.com/argoproj/argo-rollouts/utils/replicaset" @@ -77,6 +78,17 @@ func GetExperimentFromTemplate(r *v1alpha1.Rollout, stableRS, newRS *appsv1.Repl experiment.Spec.Templates = append(experiment.Spec.Templates, template) } + if step.Analysis != nil { + args := analysisutil.BuildArgumentsForRolloutAnalysisRun(step.Analysis, stableRS, newRS) + analysis := step.Analysis + analysisTemplate := v1alpha1.ExperimentAnalysisTemplateRef{ + Name: analysis.TemplateName, + TemplateName: analysis.TemplateName, + Arguments: args, + } + experiment.Spec.Analyses = append(experiment.Spec.Analyses, analysisTemplate) + } + return experiment, nil } diff --git a/rollout/experiment_test.go b/rollout/experiment_test.go index 5fadbcdb55..5a8d21c50b 100644 --- a/rollout/experiment_test.go +++ b/rollout/experiment_test.go @@ -18,6 +18,7 @@ func TestRolloutCreateExperiment(t *testing.T) { f := newFixture(t) defer f.Close() + at := analysisTemplate("bar") steps := []v1alpha1.CanaryStep{{ Experiment: &v1alpha1.RolloutExperimentStep{ Templates: []v1alpha1.RolloutExperimentTemplate{{ @@ -25,6 +26,9 @@ func TestRolloutCreateExperiment(t *testing.T) { SpecRef: v1alpha1.StableSpecRef, Replicas: int32(1), }}, + Analysis: &v1alpha1.RolloutAnalysisStep{ + TemplateName: at.Name, + }, }, }} @@ -49,6 +53,7 @@ func TestRolloutCreateExperiment(t *testing.T) { f.run(getKey(r2, t)) createdEx := f.getCreatedExperiment(createExIndex) assert.Equal(t, createdEx.GenerateName, ex.GenerateName) + assert.Equal(t, createdEx.Spec.Analyses[0].TemplateName, at.Name) patch := f.getPatchedRollout(patchIndex) expectedPatch := `{ "status": {