Skip to content

Commit

Permalink
Fix grpc health check validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed Nov 30, 2021
1 parent 0a31878 commit bdc766c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/configuration/validation/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ func validateGrpcService(service string, fieldPath *field.Path) field.ErrorList
allErrs := field.ErrorList{}

if service == "" {
return append(allErrs, field.Required(fieldPath, ""))
return allErrs
}

if !grpcRegexp.MatchString(service) {
Expand Down
55 changes: 34 additions & 21 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2354,33 +2354,46 @@ func TestValidateUpstreamHealthCheck(t *testing.T) {
}

func TestValidateGrpcUpstreamHealthCheck(t *testing.T) {
hc := &v1.HealthCheck{
Enable: true,
Interval: "4s",
Jitter: "2s",
Fails: 3,
Passes: 2,
Port: 8080,
TLS: &v1.UpstreamTLS{
Enable: true,
tests := []struct {
hc *v1.HealthCheck
}{
{
hc: &v1.HealthCheck{
Enable: true,
Interval: "4s",
Jitter: "2s",
Fails: 3,
Passes: 2,
Port: 8080,
TLS: &v1.UpstreamTLS{
Enable: true,
},
ConnectTimeout: "1s",
ReadTimeout: "1s",
SendTimeout: "1s",
Headers: []v1.Header{
{
Name: "Host",
Value: "my.service",
},
},
GRPCStatus: createPointerFromInt(12),
GRPCService: "tea-servicev2",
},
},
ConnectTimeout: "1s",
ReadTimeout: "1s",
SendTimeout: "1s",
Headers: []v1.Header{
{
Name: "Host",
Value: "my.service",
{
hc: &v1.HealthCheck{
Enable: true,
},
},
GRPCStatus: createPointerFromInt(12),
GRPCService: "tea-servicev2",
}

allErrs := validateUpstreamHealthCheck(hc, "grpc", field.NewPath("healthCheck"))
for _, test := range tests {
allErrs := validateUpstreamHealthCheck(test.hc, "grpc", field.NewPath("healthCheck"))

if len(allErrs) != 0 {
t.Errorf("validateUpstreamHealthCheck() returned errors for valid input %v", hc)
if len(allErrs) != 0 {
t.Errorf("validateUpstreamHealthCheck() returned errors for valid input %v", test.hc)
}
}
}

Expand Down

0 comments on commit bdc766c

Please sign in to comment.