From ec76090be93c5d6be3132bba38f379c8c56f396e Mon Sep 17 00:00:00 2001 From: John Maguire Date: Mon, 12 Feb 2024 11:24:56 -0500 Subject: [PATCH] [NET-7450] Fix listenerToProtocol function for input (#20536) * make listenerProtocolToCatalogProtocol function more forgiving for different cased input * update tests --- .../internal/controllers/apigateways/controller.go | 9 +++++++-- .../controllers/apigateways/controller_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/mesh/internal/controllers/apigateways/controller.go b/internal/mesh/internal/controllers/apigateways/controller.go index d4d8cefcc3..63c30af926 100644 --- a/internal/mesh/internal/controllers/apigateways/controller.go +++ b/internal/mesh/internal/controllers/apigateways/controller.go @@ -5,6 +5,8 @@ package apigateways import ( "context" + "fmt" + "strings" "github.com/hashicorp/consul/internal/controller" "github.com/hashicorp/consul/internal/mesh/internal/controllers/apigateways/fetcher" @@ -67,6 +69,7 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c serviceData, err := anypb.New(service) if err != nil { + rt.Logger.Trace("error creating the serviceData", "apigatewayID", req.ID, "error", err) return err } @@ -81,14 +84,16 @@ func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req c }) if err != nil { + rt.Logger.Trace("error writing the service", "apigatewayID", req.ID, "error", err) return err } + rt.Logger.Trace("successfully reconciled APIGateway", "apigatewayID", req.ID) return nil } func listenerProtocolToCatalogProtocol(listenerProtocol string) pbcatalog.Protocol { - switch listenerProtocol { + switch strings.ToLower(listenerProtocol) { case "http": return pbcatalog.Protocol_PROTOCOL_HTTP case "tcp": @@ -96,6 +101,6 @@ func listenerProtocolToCatalogProtocol(listenerProtocol string) pbcatalog.Protoc case "grpc": return pbcatalog.Protocol_PROTOCOL_GRPC default: - panic("this is a programmer error, the only available protocols are tcp/http/grpc") + panic(fmt.Sprintf("this is a programmer error, the only available protocols are tcp/http/grpc. You provided: %q", listenerProtocol)) } } diff --git a/internal/mesh/internal/controllers/apigateways/controller_test.go b/internal/mesh/internal/controllers/apigateways/controller_test.go index 37f570c8b8..a865f94c8f 100644 --- a/internal/mesh/internal/controllers/apigateways/controller_test.go +++ b/internal/mesh/internal/controllers/apigateways/controller_test.go @@ -81,6 +81,11 @@ func (suite *apigatewayControllerSuite) TestReconciler_Reconcile() { TargetPort: "tcp-listener", Protocol: pbcatalog.Protocol_PROTOCOL_TCP, }, + { + VirtualPort: 8081, + TargetPort: "tcp-upper", + Protocol: pbcatalog.Protocol_PROTOCOL_TCP, + }, }, } req := controller.Request{ID: id} @@ -140,6 +145,11 @@ func (suite *apigatewayControllerSuite) setupSuiteWithTenancy(tenancy *pbresourc Port: 8080, Protocol: "tcp", }, + { + Name: "tcp-upper", + Port: 8081, + Protocol: "TCP", + }, }, }). WithTenancy(tenancy).