Add basic smoke test to make sure an APIGateway runs (#16217)

This commit is contained in:
Andrew Stucki 2023-02-09 11:32:10 -05:00 committed by GitHub
parent 0891b4554d
commit f4210d47dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1326 additions and 1117 deletions

View File

@ -1575,7 +1575,7 @@ func (s *NodeService) ValidateForAgent() error {
// Gateway validation
if s.IsGateway() {
// Non-ingress gateways must have a port
if s.Port == 0 && s.Kind != ServiceKindIngressGateway {
if s.Port == 0 && s.Kind != ServiceKindIngressGateway && s.Kind != ServiceKindAPIGateway {
result = multierror.Append(result, fmt.Errorf("Port must be non-zero for a %s", s.Kind))
}

View File

@ -49,6 +49,38 @@ func ConfigEntryToStructs(s *ConfigEntry) structs.ConfigEntry {
pbcommon.RaftIndexToStructs(s.RaftIndex, &target.RaftIndex)
pbcommon.EnterpriseMetaToStructs(s.EnterpriseMeta, &target.EnterpriseMeta)
return &target
case Kind_KindAPIGateway:
var target structs.APIGatewayConfigEntry
target.Name = s.Name
APIGatewayToStructs(s.GetAPIGateway(), &target)
pbcommon.RaftIndexToStructs(s.RaftIndex, &target.RaftIndex)
pbcommon.EnterpriseMetaToStructs(s.EnterpriseMeta, &target.EnterpriseMeta)
return &target
case Kind_KindBoundAPIGateway:
var target structs.BoundAPIGatewayConfigEntry
target.Name = s.Name
BoundAPIGatewayToStructs(s.GetBoundAPIGateway(), &target)
pbcommon.RaftIndexToStructs(s.RaftIndex, &target.RaftIndex)
pbcommon.EnterpriseMetaToStructs(s.EnterpriseMeta, &target.EnterpriseMeta)
return &target
case Kind_KindTCPRoute:
var target structs.TCPRouteConfigEntry
target.Name = s.Name
TCPRouteToStructs(s.GetTCPRoute(), &target)
pbcommon.RaftIndexToStructs(s.RaftIndex, &target.RaftIndex)
pbcommon.EnterpriseMetaToStructs(s.EnterpriseMeta, &target.EnterpriseMeta)
return &target
case Kind_KindHTTPRoute:
var target structs.HTTPRouteConfigEntry
target.Name = s.Name
HTTPRouteToStructs(s.GetHTTPRoute(), &target)
pbcommon.RaftIndexToStructs(s.RaftIndex, &target.RaftIndex)
pbcommon.EnterpriseMetaToStructs(s.EnterpriseMeta, &target.EnterpriseMeta)
return &target
case Kind_KindServiceDefaults:
var target structs.ServiceConfigEntry
target.Name = s.Name
@ -113,6 +145,38 @@ func ConfigEntryFromStructs(s structs.ConfigEntry) *ConfigEntry {
configEntry.Entry = &ConfigEntry_ServiceDefaults{
ServiceDefaults: &serviceDefaults,
}
case *structs.APIGatewayConfigEntry:
var apiGateway APIGateway
APIGatewayFromStructs(v, &apiGateway)
configEntry.Kind = Kind_KindAPIGateway
configEntry.Entry = &ConfigEntry_APIGateway{
APIGateway: &apiGateway,
}
case *structs.BoundAPIGatewayConfigEntry:
var apiGateway BoundAPIGateway
BoundAPIGatewayFromStructs(v, &apiGateway)
configEntry.Kind = Kind_KindBoundAPIGateway
configEntry.Entry = &ConfigEntry_BoundAPIGateway{
BoundAPIGateway: &apiGateway,
}
case *structs.TCPRouteConfigEntry:
var route TCPRoute
TCPRouteFromStructs(v, &route)
configEntry.Kind = Kind_KindTCPRoute
configEntry.Entry = &ConfigEntry_TCPRoute{
TCPRoute: &route,
}
case *structs.HTTPRouteConfigEntry:
var route HTTPRoute
HTTPRouteFromStructs(v, &route)
configEntry.Kind = Kind_KindHTTPRoute
configEntry.Entry = &ConfigEntry_HTTPRoute{
HTTPRoute: &route,
}
default:
panic(fmt.Sprintf("unable to convert %T to proto", s))
}

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,10 @@ message ConfigEntry {
IngressGateway IngressGateway = 7;
ServiceIntentions ServiceIntentions = 8;
ServiceDefaults ServiceDefaults = 9;
APIGateway APIGateway = 10;
BoundAPIGateway BoundAPIGateway = 11;
TCPRoute TCPRoute = 12;
HTTPRoute HTTPRoute = 13;
}
}

View File

@ -0,0 +1,3 @@
#!/bin/bash
snapshot_envoy_admin localhost:20000 api-gateway primary || true

View File

@ -0,0 +1,4 @@
services {
name = "api-gateway"
kind = "api-gateway"
}

View File

@ -0,0 +1,35 @@
#!/bin/bash
set -euo pipefail
upsert_config_entry primary '
kind = "api-gateway"
name = "api-gateway"
listeners = [
{
port = 9999
protocol = "tcp"
}
]
'
upsert_config_entry primary '
kind = "tcp-route"
name = "api-gateway-route"
services = [
{
name = "s1"
}
]
parents = [
{
name = "api-gateway"
}
]
'
register_services primary
gen_envoy_bootstrap api-gateway 20000 primary true
gen_envoy_bootstrap s1 19000
gen_envoy_bootstrap s2 19001

View File

@ -0,0 +1,3 @@
#!/bin/bash
export REQUIRED_SERVICES="$DEFAULT_REQUIRED_SERVICES api-gateway-primary"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bats
load helpers
@test "api gateway proxy admin is up on :20000" {
retry_default curl -f -s localhost:20000/stats -o /dev/null
}

View File

@ -803,6 +803,10 @@ function run_container_ingress-gateway-primary {
common_run_container_gateway ingress-gateway primary
}
function run_container_api-gateway-primary {
common_run_container_gateway api-gateway primary
}
function run_container_terminating-gateway-primary {
common_run_container_gateway terminating-gateway primary
}