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

Fix Gateway API TLS TCP Route #4213

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions source/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,18 @@ func uniqueTargets(targets endpoint.Targets) endpoint.Targets {

// gwProtocolMatches returns whether a and b are the same protocol,
// where HTTP and HTTPS are considered the same.
// and TLS and TCP are considered the same.
func gwProtocolMatches(a, b v1.ProtocolType) bool {
if a == v1.HTTPSProtocolType {
a = v1.HTTPProtocolType
}
if b == v1.HTTPSProtocolType {
b = v1.HTTPProtocolType
}
// if Listener is TLS and Route is TCP set Listener type to TCP as to pass true and return valid match
if a == v1.TCPProtocolType && b == v1.TLSProtocolType {
b = v1.TCPProtocolType
}
return a == b
}

Expand Down
56 changes: 56 additions & 0 deletions source/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package source
import (
"strings"
"testing"

v1 "sigs.k8s.io/gateway-api/apis/v1"
)

func TestGatewayMatchingHost(t *testing.T) {
Expand Down Expand Up @@ -105,6 +107,60 @@ func TestGatewayMatchingHost(t *testing.T) {
}
}

func TestGatewayMatchingProtocol(t *testing.T) {
tests := []struct {
route, lis string
desc string
ok bool
}{
{
desc: "protocol-matches-lis-https-route-http",
route: "HTTP",
lis: "HTTPS",
ok: true,
},
{
desc: "protocol-match-invalid-list-https-route-tcp",
route: "TCP",
lis: "HTTPS",
ok: false,
},
{
desc: "protocol-match-valid-lis-tls-route-tls",
route: "TLS",
lis: "TLS",
ok: true,
},
{
desc: "protocol-match-valid-lis-TLS-route-TCP",
route: "TCP",
lis: "TLS",
ok: true,
},
{
desc: "protocol-match-valid-lis-TLS-route-TCP",
route: "TLS",
lis: "TCP",
ok: false,
},
}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
for i := 0; i < 2; i++ {
if ok := gwProtocolMatches(v1.ProtocolType(tt.route), v1.ProtocolType(tt.lis)); ok != tt.ok {
t.Errorf(
"gwProtocolMatches(%q, %q); got: %v; want: %v",
tt.route, tt.lis, ok, tt.ok,
)
}
//tt.a, tt.b = tt.b, tt.a
}
})

}
}

func TestIsDNS1123Domain(t *testing.T) {
tests := []struct {
desc string
Expand Down
Loading