Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries support for vs/vsr #628

Merged
merged 15 commits into from
Jul 26, 2019
8 changes: 2 additions & 6 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,17 +931,13 @@ func TestGenerateString(t *testing.T) {
expected string
}{
{
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
inputS: "error timeout",
expected: "error timeout",
inputS: "http_404",
expected: "http_404",
},
{
inputS: "",
expected: "error timeout",
},
{
inputS: "http_404",
expected: "http_404",
},
}

for _, test := range tests {
Expand Down
17 changes: 8 additions & 9 deletions pkg/apis/configuration/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func validateUpstreams(upstreams []v1alpha1.Upstream, fieldPath *field.Path, isP
return allErrs, upstreamNames
}

var validVariableParams = map[string]bool{
var validNextUpstreamParams = map[string]bool{
"error": true,
"timeout": true,
"invalid_header": true,
Expand All @@ -172,23 +172,22 @@ var validVariableParams = map[string]bool{
"http_429": true,
"non_idempotent": true,
"off": true,
"": true,
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
}

// validateNextUpstream checks the values given for passing queries to a upstream
func validateNextUpstream(nextUpstream string, fieldPath *field.Path) field.ErrorList {
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
allErrs := field.ErrorList{}
var occur int
allParams := sets.String{}
params := strings.Fields(nextUpstream)
for _, para := range params {
if !validVariableParams[para] {
if !validNextUpstreamParams[para] {
allErrs = append(allErrs, field.Invalid(fieldPath, para, "not a valid parameter"))
}
for _, p := range params {
if p == para {
occur++
} else if occur > 1 {
allErrs = append(allErrs, field.Invalid(fieldPath, para, "can not have recurring parameters"))
}
if allParams.Has(para) {
allErrs = append(allErrs, field.Invalid(fieldPath, para, "can not have duplicate parameters"))
} else {
allParams.Insert(para)
}
}
return allErrs
Expand Down
8 changes: 2 additions & 6 deletions pkg/apis/configuration/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,13 @@ func TestValidateNextUpstream(t *testing.T) {
inputS: "error timeout",
},
{

inputS: "http_404 timeout",
},
}
for _, test := range tests {
allErrs := validateNextUpstream(test.inputS, field.NewPath("next-upstreams"))
if len(allErrs) > 0 {
t.Errorf("validateNextUpstream() returned errors %v for valid input for the case of %s", allErrs, test.inputS)
t.Errorf("validateNextUpstream(%q) returned errors %v for valid input for the case of %s", test.inputS, allErrs, test.inputS)
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -333,17 +332,14 @@ func TestValidateNextUpstreamFails(t *testing.T) {
{
inputS: "error error",
},
{
inputS: "",
},
{
inputS: "https_404",
},
}
for _, test := range tests {
allErrs := validateNextUpstream(test.inputS, field.NewPath("next-upstreams"))
if len(allErrs) < 0 {
t.Errorf("validateNextUpstream() didn't return errors %v for invalid input for the case of %s", allErrs, test.inputS)
t.Errorf("validateNextUpstream(%q) didn't return errors %v for invalid input for the case of %s", test.inputS, allErrs, test.inputS)
LorcanMcVeigh marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down