Skip to content

Commit

Permalink
skip check for arg with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
Hui Kang committed Apr 8, 2021
1 parent 0d0cf3e commit 68cdd97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/apis/rollouts/validation/validation_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,18 @@ func ValidateAnalysisTemplateWithType(rollout *v1alpha1.Rollout, template Analys
}
}
} else if template.TemplateType == BackgroundAnalysis && len(templateSpec.Args) > 0 {
if rollout.Spec.Strategy.Canary == nil || rollout.Spec.Strategy.Canary.Analysis == nil || rollout.Spec.Strategy.Canary.Analysis.Args == nil {
allErrs = append(allErrs, field.Invalid(fldPath, templateName, "missing analysis arguments in rollout spec"))
return allErrs
}

if len(rollout.Spec.Strategy.Canary.Analysis.Args) < len(templateSpec.Args) {
allErrs = append(allErrs, field.Invalid(fldPath, templateName, "not enough analysis arguments in rollout spec"))
return allErrs
}

for _, arg := range templateSpec.Args {
if arg.Value != nil || arg.ValueFrom != nil {
continue
}
if rollout.Spec.Strategy.Canary == nil || rollout.Spec.Strategy.Canary.Analysis == nil || rollout.Spec.Strategy.Canary.Analysis.Args == nil {
allErrs = append(allErrs, field.Invalid(fldPath, templateName, "missing analysis arguments in rollout spec"))
continue
}

foundArg := false
for _, rolloutarg := range rollout.Spec.Strategy.Canary.Analysis.Args {
if arg.Name == rolloutarg.Name {
for _, rolloutArg := range rollout.Spec.Strategy.Canary.Analysis.Args {
if arg.Name == rolloutArg.Name {
foundArg = true
break
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/rollouts/validation/validation_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ func TestValidateAnalysisTemplateWithType(t *testing.T) {
allErrs := ValidateAnalysisTemplateWithType(rollout, template)
assert.Empty(t, allErrs)

// default value should be fine
defaultValue := "value-name"
template.AnalysisTemplate.Spec.Args = []v1alpha1.Argument{
{
Name: "service-name",
Value: &defaultValue,
},
}
allErrs = ValidateAnalysisTemplateWithType(rollout, template)
assert.Empty(t, allErrs)

template.AnalysisTemplate.Spec.Args = []v1alpha1.Argument{
{
Name: "service-name",
Expand Down

0 comments on commit 68cdd97

Please sign in to comment.