From 63f5e195c10451d40fe8d889b764e3452163cfb7 Mon Sep 17 00:00:00 2001 From: Ludovic Logiou Date: Sat, 24 Aug 2024 10:48:21 +0200 Subject: [PATCH] [api-gateway]: Support http(s) as AppProtocol in Kubernetes svc (#6616) * [api-gateway]: Support http, https and www-http as AppProtocol in kubernetes' service Fix #6560 Signed-off-by: Ludovic Logiou * Remove legacy www-http Signed-off-by: Ludovic Logiou * Fix undefined vars Signed-off-by: Ludovic Logiou * Add changelog Signed-off-by: Ludovic Logiou * Fix issues found by the linter Signed-off-by: Ludovic Logiou * Fix format and add unit tests Signed-off-by: Ludovic Logiou --------- Signed-off-by: Ludovic Logiou --- changelogs/unreleased/6616-Krast76-small.md | 1 + internal/dag/accessors.go | 4 ++++ internal/dag/accessors_test.go | 22 +++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 changelogs/unreleased/6616-Krast76-small.md diff --git a/changelogs/unreleased/6616-Krast76-small.md b/changelogs/unreleased/6616-Krast76-small.md new file mode 100644 index 00000000000..b44b28c7263 --- /dev/null +++ b/changelogs/unreleased/6616-Krast76-small.md @@ -0,0 +1 @@ +Contour, support http and https as AppProtocol in k8s' services diff --git a/internal/dag/accessors.go b/internal/dag/accessors.go index c039d28ccba..c3b78f71bc2 100644 --- a/internal/dag/accessors.go +++ b/internal/dag/accessors.go @@ -110,6 +110,8 @@ 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) { @@ -117,6 +119,8 @@ func toContourProtocol(appProtocol string) (string, bool) { // *NOTE: for gateway-api: the websocket is enabled by default protoK8sWS: "", protoK8sH2C: "h2c", + protoHTTP: "", + protoHTTPS: "tls", }[appProtocol] return proto, ok } diff --git a/internal/dag/accessors_test.go b/internal/dag/accessors_test.go index bc3e2b8692e..99c9470bd3b 100644 --- a/internal/dag/accessors_test.go +++ b/internal/dag/accessors_test.go @@ -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, + }, }, }, } @@ -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 {