Skip to content

Commit

Permalink
Allow multiple analyses in experiments created by rollouts
Browse files Browse the repository at this point in the history
  • Loading branch information
dthomson25 committed Oct 30, 2019
1 parent 5033ac5 commit 4327aa8
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 86 deletions.
57 changes: 34 additions & 23 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
canaryService:
Expand Down Expand Up @@ -165,36 +168,44 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
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
analyses:
items:
properties:
arguments:
items:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
podTemplateHashValue:
type: string
type: object
required:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
type: array
duration:
format: int32
type: integer
Expand Down
57 changes: 34 additions & 23 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7856,9 +7856,12 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
canaryService:
Expand Down Expand Up @@ -7892,36 +7895,44 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
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
analyses:
items:
properties:
arguments:
items:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
podTemplateHashValue:
type: string
type: object
required:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
type: array
duration:
format: int32
type: integer
Expand Down
57 changes: 34 additions & 23 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7856,9 +7856,12 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
canaryService:
Expand Down Expand Up @@ -7892,36 +7895,44 @@ spec:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
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
analyses:
items:
properties:
arguments:
items:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
podTemplateHashValue:
type: string
type: object
required:
- name
type: object
type: array
name:
type: string
templateName:
type: string
required:
- name
- templateName
type: object
type: array
duration:
format: int32
type: integer
Expand Down
22 changes: 18 additions & 4 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.

6 changes: 4 additions & 2 deletions pkg/apis/rollouts/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ type RolloutExperimentStep struct {
// Duration is the duration in seconds that the experiment should run for
// +optional
Duration *int32 `json:"duration,omitempty"`
//AnalysisTemplate what analysis to run with the experiment
Analysis *RolloutAnalysisStep `json:"analysis,omitempty"`
//Analyses what analyses to run with the experiment
Analyses []RolloutAnalysisStep `json:"analyses,omitempty"`
}

// RolloutExperimentTemplate defines the template used to create experiments for the Rollout's experiment canary step
Expand Down Expand Up @@ -207,6 +207,8 @@ type CanaryStep struct {

// RolloutAnalysisStep defines a template that is used to create a analysisRun
type RolloutAnalysisStep struct {
// Name the name for the analysisRun
Name string `json:"name"`
// TemplateName reference of the AnalysisTemplate name used by the Rollout to create the run
TemplateName string `json:"templateName"`
// Arguments the arguments that will be added to the AnalysisRuns
Expand Down
10 changes: 6 additions & 4 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.

2 changes: 1 addition & 1 deletion rollout/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (c *RolloutController) getAnalysisRunFromRollout(roCtx *canaryContext, roll

ar := v1alpha1.AnalysisRun{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-%s-%s-", r.Name, rolloutAnalysisStep.TemplateName, podHash),
GenerateName: fmt.Sprintf("%s-%s-%s-", r.Name, rolloutAnalysisStep.Name, podHash),
Namespace: r.Namespace,
Labels: labels,
Annotations: map[string]string{
Expand Down
3 changes: 3 additions & 0 deletions rollout/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestCreateBackgroundAnalysisRun(t *testing.T) {
ar := analysisRun(at, v1alpha1.RolloutTypeBackgroundRunLabel, r2)
r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisStep{
TemplateName: at.Name,
Name: at.Name,
}

rs1 := newReplicaSetWithStatus(r1, 10, 10)
Expand Down Expand Up @@ -113,6 +114,7 @@ func TestCreateAnalysisRunOnAnalysisStep(t *testing.T) {
steps := []v1alpha1.CanaryStep{{
Analysis: &v1alpha1.RolloutAnalysisStep{
TemplateName: at.Name,
Name: at.Name,
},
}}

Expand Down Expand Up @@ -164,6 +166,7 @@ func TestFailCreateStepAnalysisRunIfInvalidTemplateRef(t *testing.T) {
steps := []v1alpha1.CanaryStep{{
Analysis: &v1alpha1.RolloutAnalysisStep{
TemplateName: "invalid-template-ref",
Name: "invalid-template-ref",
},
}}

Expand Down
8 changes: 4 additions & 4 deletions rollout/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ 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
for i := range step.Analyses {
analysis := step.Analyses[i]
args := analysisutil.BuildArgumentsForRolloutAnalysisRun(&analysis, stableRS, newRS)
analysisTemplate := v1alpha1.ExperimentAnalysisTemplateRef{
Name: analysis.TemplateName,
Name: analysis.Name,
TemplateName: analysis.TemplateName,
Arguments: args,
}
Expand Down
6 changes: 4 additions & 2 deletions rollout/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func TestRolloutCreateExperiment(t *testing.T) {
SpecRef: v1alpha1.StableSpecRef,
Replicas: pointer.Int32Ptr(1),
}},
Analysis: &v1alpha1.RolloutAnalysisStep{
Analyses: []v1alpha1.RolloutAnalysisStep{{
Name: "test",
TemplateName: at.Name,
},
}},
},
}}

Expand All @@ -54,6 +55,7 @@ func TestRolloutCreateExperiment(t *testing.T) {
createdEx := f.getCreatedExperiment(createExIndex)
assert.Equal(t, createdEx.GenerateName, ex.GenerateName)
assert.Equal(t, createdEx.Spec.Analyses[0].TemplateName, at.Name)
assert.Equal(t, createdEx.Spec.Analyses[0].Name, "test")
patch := f.getPatchedRollout(patchIndex)
expectedPatch := `{
"status": {
Expand Down

0 comments on commit 4327aa8

Please sign in to comment.