From 79468793f63e27c42d1c1e756de69d52dacaa710 Mon Sep 17 00:00:00 2001 From: Chris Piraino Date: Thu, 14 May 2020 14:49:57 -0500 Subject: [PATCH] Do not return an error if requested service is not a gateway This commit converts the previous error into just a Warn-level log message. By returning an error when the requested service was not a gateway, we did not appropriately update envoy because the cache Fetch returned an error and thus did not propagate the update through proxycfg and xds packages. --- agent/consul/internal_endpoint.go | 9 ++++++++- agent/consul/internal_endpoint_test.go | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/agent/consul/internal_endpoint.go b/agent/consul/internal_endpoint.go index 31a084c79f..0a9ea16f2c 100644 --- a/agent/consul/internal_endpoint.go +++ b/agent/consul/internal_endpoint.go @@ -414,8 +414,15 @@ func (m *Internal) GatewayServices(args *structs.ServiceSpecificRequest, reply * } } + // We log a warning here to indicate that there is a potential + // misconfiguration. We explicitly do NOT return an error because this + // can occur in the course of normal operation by deleting a + // configuration entry or starting the proxy before registering the + // config entry. if !found { - return fmt.Errorf("service %q is not a configured terminating-gateway or ingress-gateway", args.ServiceName) + m.logger.Warn("no terminating-gateway or ingress-gateway associated with this gateway", + "gateway", args.ServiceName, + ) } index, services, err = state.GatewayServices(ws, args.ServiceName, &args.EnterpriseMeta) diff --git a/agent/consul/internal_endpoint_test.go b/agent/consul/internal_endpoint_test.go index a88e3f98a6..b49a9d5682 100644 --- a/agent/consul/internal_endpoint_test.go +++ b/agent/consul/internal_endpoint_test.go @@ -954,8 +954,11 @@ func TestInternal_GatewayServices_BothGateways(t *testing.T) { } var resp structs.IndexedGatewayServices err := msgpackrpc.CallWithCodec(codec, "Internal.GatewayServices", &req, &resp) - assert.Error(t, err) - assert.Contains(t, err.Error(), `service "api" is not a configured terminating-gateway or ingress-gateway`) + assert.NoError(t, err) + assert.Empty(t, resp.Services) + // Ensure that the index is not zero so that a blocking query still gets the + // latest GatewayServices index + assert.NotEqual(t, 0, resp.Index) } func TestInternal_GatewayServices_ACLFiltering(t *testing.T) {