Skip to content

Commit

Permalink
Add analysis to experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 committed Oct 29, 2019
1 parent 1486519 commit 26f77e6
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
23 changes: 23 additions & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pkg/apis/rollouts/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions rollout/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions rollout/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ func TestRolloutCreateExperiment(t *testing.T) {
f := newFixture(t)
defer f.Close()

at := analysisTemplate("bar")
steps := []v1alpha1.CanaryStep{{
Experiment: &v1alpha1.RolloutExperimentStep{
Templates: []v1alpha1.RolloutExperimentTemplate{{
Name: "stable-template",
SpecRef: v1alpha1.StableSpecRef,
Replicas: int32(1),
}},
Analysis: &v1alpha1.RolloutAnalysisStep{
TemplateName: at.Name,
},
},
}}

Expand All @@ -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": {
Expand Down

0 comments on commit 26f77e6

Please sign in to comment.