Skip to content

Commit

Permalink
dataclients/kubernetes: provide expected network backend address form…
Browse files Browse the repository at this point in the history
…at in the error message

Followup on #2719

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov committed Dec 6, 2023
1 parent 6f1419f commit 2415dae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/webhook/admission/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestRouteGroupAdmitter(t *testing.T) {
{
name: "routegroup with invalid backends",
inputFile: "rg-with-invalid-backend-path.json",
message: `backend address \"http://example.com/foo\" contains path, query or missing scheme\nbackend address \"http://example.com/foo/bar\" contains path, query or missing scheme\nbackend address \"http://example.com/foo/\" contains path, query or missing scheme\nbackend address \"/foo\" contains path, query or missing scheme\nbackend address \"http://example.com/\" contains path, query or missing scheme\nbackend address \"example.com/\" contains path, query or missing scheme\nbackend address \"example.com/foo\" contains path, query or missing scheme\nbackend address \"http://example.com?foo=bar\" contains path, query or missing scheme\nbackend address \"example.com\" contains path, query or missing scheme`,
message: `backend address \"http://example.com/foo\" does not match scheme://host format\nbackend address \"http://example.com/foo/bar\" does not match scheme://host format\nbackend address \"http://example.com/foo/\" does not match scheme://host format\nbackend address \"/foo\" does not match scheme://host format\nbackend address \"http://example.com/\" does not match scheme://host format\nbackend address \"example.com/\" does not match scheme://host format\nbackend address \"example.com/foo\" does not match scheme://host format\nbackend address \"http://example.com?foo=bar\" does not match scheme://host format\nbackend address \"example.com\" does not match scheme://host format`,
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions dataclients/kubernetes/definitions/routegroupvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ func (rgv *RouteGroupValidator) validateBackends(item *RouteGroupItem) error {
address, err := url.Parse(backend.Address)
if err != nil {
errs = append(errs, fmt.Errorf("failed to parse backend address %q: %w", backend.Address, err))
} else if address.Path != "" || address.RawQuery != "" || address.Scheme == "" {
errs = append(errs, fmt.Errorf("backend address %q contains path, query or missing scheme", backend.Address))
} else {
if address.Path != "" || address.RawQuery != "" || address.Scheme == "" || address.Host == "" {
errs = append(errs, fmt.Errorf("backend address %q does not match scheme://host format", backend.Address))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ single predicate expected at "Path(\"/foo\") && Method(\"GET\")"
single predicate expected at ""
single filter expected at "inlineContent(\"/foo\") -> status(200)"
single filter expected at " "
backend address "http://example.com/foo" contains path, query or missing scheme
backend address "http://example.com/foo/bar" contains path, query or missing scheme
backend address "http://example.com/foo/" contains path, query or missing scheme
backend address "/foo" contains path, query or missing scheme
backend address "example.com/" contains path, query or missing scheme
backend address "http://example.com?foo=bar" contains path, query or missing scheme
backend address "example.com" contains path, query or missing scheme
backend address "http://example.com/foo" does not match scheme://host format
backend address "http://example.com/foo/bar" does not match scheme://host format
backend address "http://example.com/foo/" does not match scheme://host format
backend address "/foo" does not match scheme://host format
backend address "example.com/" does not match scheme://host format
backend address "http://example.com?foo=bar" does not match scheme://host format
backend address "example.com" does not match scheme://host format
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
backend address \\\"http://example\.com/foo\\\" contains path, query or missing scheme
backend address \\\"http://example\.com/foo/bar\\\" contains path, query or missing scheme
backend address \\\"/foo\\\" contains path, query or missing scheme
backend address \\\"/foo/bar\\\" contains path, query or missing scheme
backend address \\\"example\.com/foo\\\" contains path, query or missing scheme
backend address \\\"http://example\.com/\\\" contains path, query or missing scheme
backend address \\\"http://example\.com\?foo=bar\\\" contains path, query or missing scheme
backend address \\\"example\.com\\\" contains path, query or missing scheme
backend address \\\"http://example\.com/foo\\\" does not match scheme://host format
backend address \\\"http://example\.com/foo/bar\\\" does not match scheme://host format
backend address \\\"/foo\\\" does not match scheme://host format
backend address \\\"/foo/bar\\\" does not match scheme://host format
backend address \\\"example\.com/foo\\\" does not match scheme://host format
backend address \\\"http://example\.com/\\\" does not match scheme://host format
backend address \\\"http://example\.com\?foo=bar\\\" does not match scheme://host format
backend address \\\"example\.com\\\" does not match scheme://host format

0 comments on commit 2415dae

Please sign in to comment.