Skip to content

Commit

Permalink
[api-gateway]: Support http(s) as AppProtocol in Kubernetes svc (#6616)
Browse files Browse the repository at this point in the history
* [api-gateway]: Support http, https and www-http as AppProtocol in kubernetes' service

Fix #6560

Signed-off-by: Ludovic Logiou <[email protected]>

* Remove legacy www-http

Signed-off-by: Ludovic Logiou <[email protected]>

* Fix undefined vars

Signed-off-by: Ludovic Logiou <[email protected]>

* Add changelog

Signed-off-by: Ludovic Logiou <[email protected]>

* Fix issues found by the linter

Signed-off-by: Ludovic Logiou <[email protected]>

* Fix format and add unit tests

Signed-off-by: Ludovic Logiou <[email protected]>

---------

Signed-off-by: Ludovic Logiou <[email protected]>
  • Loading branch information
Krast76 authored Aug 24, 2024
1 parent 20e57df commit 63f5e19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6616-Krast76-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contour, support http and https as AppProtocol in k8s' services
4 changes: 4 additions & 0 deletions internal/dag/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ func validateExternalName(svc *core_v1.Service, enableExternalNameSvc bool) erro
const (
protoK8sH2C = "kubernetes.io/h2c"
protoK8sWS = "kubernetes.io/ws"
protoHTTPS = "https"
protoHTTP = "http"
)

func toContourProtocol(appProtocol string) (string, bool) {
proto, ok := map[string]string{
// *NOTE: for gateway-api: the websocket is enabled by default
protoK8sWS: "",
protoK8sH2C: "h2c",
protoHTTP: "",
protoHTTPS: "tls",
}[appProtocol]
return proto, ok
}
Expand Down
22 changes: 22 additions & 0 deletions internal/dag/accessors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ func TestBuilderLookupService(t *testing.T) {
AppProtocol: ptr.To("kubernetes.io/wss"),
Port: 8444,
},
{
Name: "iana-https",
Protocol: "TCP",
AppProtocol: ptr.To("https"),
Port: 8445,
},
{
Name: "iana-http",
Protocol: "TCP",
AppProtocol: ptr.To("http"),
Port: 8446,
},
},
},
}
Expand Down Expand Up @@ -218,6 +230,16 @@ func TestBuilderLookupService(t *testing.T) {
port: 8444,
want: appProtcolService(appProtoService, "", 1),
},
"lookup service by port number with supported IANA app protocol: https": {
NamespacedName: types.NamespacedName{Name: appProtoService.Name, Namespace: appProtoService.Namespace},
port: 8445,
want: appProtcolService(appProtoService, "tls", 2),
},
"lookup service by port number with supported IANA app protocol: http": {
NamespacedName: types.NamespacedName{Name: appProtoService.Name, Namespace: appProtoService.Namespace},
port: 8446,
want: appProtcolService(appProtoService, "", 3),
},
}

for name, tc := range tests {
Expand Down

0 comments on commit 63f5e19

Please sign in to comment.