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

[istio] fix: handle wildcard hosts in VirtualServices #155

Merged
merged 7 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ go.work

# GolangCI-Lint cache
/cache

# goland
.idea
4 changes: 4 additions & 0 deletions pkg/i2gw/providers/istio/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ func (c *converter) convertVsHTTPRoutes(virtualService metav1.ObjectMeta, istioH
// set istio hostnames as is, without extra filters. If it's not a fqdn, it would be rejected by K8S API implementation
hostnames := make([]gatewayv1.Hostname, 0, len(allowedHostnames))
for _, host := range allowedHostnames {
// '*' is valid in istio, but not in HTTPRoute
if host == "*" {
continue
}
hostnames = append(hostnames, gatewayv1.Hostname(host))
}

Expand Down
90 changes: 90 additions & 0 deletions pkg/i2gw/providers/istio/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,96 @@ func Test_converter_convertVsHTTPRoutes(t *testing.T) {
},
},
},
{
name: "hosts with '*'",
args: args{
virtualService: metav1.ObjectMeta{
Name: "test",
Namespace: "ns",
},
istioHTTPRoutes: []*istiov1beta1.HTTPRoute{
{
Headers: &istiov1beta1.Headers{
Request: &istiov1beta1.Headers_HeaderOperations{
Set: map[string]string{
"h1": "v1",
},
Add: map[string]string{
"h2": "v2",
},
Remove: []string{"h3"},
},
Response: &istiov1beta1.Headers_HeaderOperations{
Set: map[string]string{
"h4": "v4",
},
Add: map[string]string{
"h5": "v5",
},
Remove: []string{"h6"},
},
},
},
},
allowedHostnames: []string{"*"},
},
want: []*gatewayv1.HTTPRoute{
{
TypeMeta: metav1.TypeMeta{
Kind: "HTTPRoute",
APIVersion: "gateway.networking.k8s.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-idx-0",
Namespace: "ns",
},
Spec: gatewayv1.HTTPRouteSpec{
Rules: []gatewayv1.HTTPRouteRule{
{
Filters: []gatewayv1.HTTPRouteFilter{
{
Type: gatewayv1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1.HTTPHeaderFilter{
Set: []gatewayv1.HTTPHeader{
{
Name: "h1",
Value: "v1",
},
},
Add: []gatewayv1.HTTPHeader{
{
Name: "h2",
Value: "v2",
},
},
Remove: []string{"h3"},
},
},
{
Type: gatewayv1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1.HTTPHeaderFilter{
Set: []gatewayv1.HTTPHeader{
{
Name: "h4",
Value: "v4",
},
},
Add: []gatewayv1.HTTPHeader{
{
Name: "h5",
Value: "v5",
},
},
Remove: []string{"h6"},
},
},
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down