Skip to content

Commit 33a55c6

Browse files
committed
agent: expose the list of supported envoy versions on /v1/agent/self (#8545)
1 parent f23c704 commit 33a55c6

File tree

5 files changed

+79
-30
lines changed

5 files changed

+79
-30
lines changed

.changelog/8545.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:feature
2+
agent: expose the list of supported envoy versions on /v1/agent/self
3+
```

agent/agent_endpoint.go

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/hashicorp/consul/agent/debug"
1818
"github.com/hashicorp/consul/agent/structs"
1919
token_store "github.com/hashicorp/consul/agent/token"
20+
"github.com/hashicorp/consul/agent/xds/proxysupport"
2021
"github.com/hashicorp/consul/api"
2122
"github.com/hashicorp/consul/ipaddr"
2223
"github.com/hashicorp/consul/lib"
@@ -38,6 +39,11 @@ type Self struct {
3839
Member serf.Member
3940
Stats map[string]map[string]string
4041
Meta map[string]string
42+
XDS *xdsSelf `json:"xDS,omitempty"`
43+
}
44+
45+
type xdsSelf struct {
46+
SupportedProxies map[string][]string
4147
}
4248

4349
func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
@@ -60,6 +66,15 @@ func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (int
6066
}
6167
}
6268

69+
var xds *xdsSelf
70+
if s.agent.grpcServer != nil {
71+
xds = &xdsSelf{
72+
SupportedProxies: map[string][]string{
73+
"envoy": proxysupport.EnvoyVersions,
74+
},
75+
}
76+
}
77+
6378
config := struct {
6479
Datacenter string
6580
NodeName string
@@ -82,6 +97,7 @@ func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (int
8297
Member: s.agent.LocalMember(),
8398
Stats: s.agent.Stats(),
8499
Meta: s.agent.State.Metadata(),
100+
XDS: xds,
85101
}, nil
86102
}
87103

agent/agent_endpoint_test.go

+55-29
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/http"
1212
"net/http/httptest"
1313
"net/url"
14-
"reflect"
1514
"strconv"
1615
"strings"
1716
"testing"
@@ -25,6 +24,7 @@ import (
2524
"github.com/hashicorp/consul/agent/structs"
2625
"github.com/hashicorp/consul/agent/token"
2726
tokenStore "github.com/hashicorp/consul/agent/token"
27+
"github.com/hashicorp/consul/agent/xds/proxysupport"
2828
"github.com/hashicorp/consul/api"
2929
"github.com/hashicorp/consul/lib"
3030
"github.com/hashicorp/consul/sdk/testutil"
@@ -1175,39 +1175,65 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
11751175

11761176
func TestAgent_Self(t *testing.T) {
11771177
t.Parallel()
1178-
a := NewTestAgent(t, t.Name(), `
1179-
node_meta {
1180-
somekey = "somevalue"
1181-
}
1182-
`)
1183-
defer a.Shutdown()
11841178

1185-
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
1186-
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
1187-
obj, err := a.srv.AgentSelf(nil, req)
1188-
if err != nil {
1189-
t.Fatalf("err: %v", err)
1179+
cases := map[string]struct {
1180+
hcl string
1181+
expectXDS bool
1182+
}{
1183+
"normal": {
1184+
hcl: `
1185+
node_meta {
1186+
somekey = "somevalue"
1187+
}
1188+
`,
1189+
expectXDS: true,
1190+
},
1191+
"no grpc": {
1192+
hcl: `
1193+
node_meta {
1194+
somekey = "somevalue"
1195+
}
1196+
ports = {
1197+
grpc = -1
1198+
}
1199+
`,
1200+
expectXDS: false,
1201+
},
11901202
}
11911203

1192-
val := obj.(Self)
1193-
if int(val.Member.Port) != a.Config.SerfPortLAN {
1194-
t.Fatalf("incorrect port: %v", obj)
1195-
}
1204+
for name, tc := range cases {
1205+
tc := tc
1206+
t.Run(name, func(t *testing.T) {
1207+
a := NewTestAgent(t, t.Name(), tc.hcl)
1208+
defer a.Shutdown()
11961209

1197-
if val.DebugConfig["SerfPortLAN"].(int) != a.Config.SerfPortLAN {
1198-
t.Fatalf("incorrect port: %v", obj)
1199-
}
1210+
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
1211+
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
1212+
obj, err := a.srv.AgentSelf(nil, req)
1213+
require.NoError(t, err)
12001214

1201-
cs, err := a.GetLANCoordinate()
1202-
if err != nil {
1203-
t.Fatalf("err: %v", err)
1204-
}
1205-
if c := cs[a.config.SegmentName]; !reflect.DeepEqual(c, val.Coord) {
1206-
t.Fatalf("coordinates are not equal: %v != %v", c, val.Coord)
1207-
}
1208-
delete(val.Meta, structs.MetaSegmentKey) // Added later, not in config.
1209-
if !reflect.DeepEqual(a.config.NodeMeta, val.Meta) {
1210-
t.Fatalf("meta fields are not equal: %v != %v", a.config.NodeMeta, val.Meta)
1215+
val := obj.(Self)
1216+
require.Equal(t, a.Config.SerfPortLAN, int(val.Member.Port))
1217+
require.Equal(t, a.Config.SerfPortLAN, val.DebugConfig["SerfPortLAN"].(int))
1218+
1219+
cs, err := a.GetLANCoordinate()
1220+
require.NoError(t, err)
1221+
require.Equal(t, cs[a.config.SegmentName], val.Coord)
1222+
1223+
delete(val.Meta, structs.MetaSegmentKey) // Added later, not in config.
1224+
require.Equal(t, a.config.NodeMeta, val.Meta)
1225+
1226+
if tc.expectXDS {
1227+
require.NotNil(t, val.XDS, "xds component missing when gRPC is enabled")
1228+
require.Equal(t,
1229+
map[string][]string{"envoy": proxysupport.EnvoyVersions},
1230+
val.XDS.SupportedProxies,
1231+
)
1232+
1233+
} else {
1234+
require.Nil(t, val.XDS, "xds component should be missing when gRPC is disabled")
1235+
}
1236+
})
12111237
}
12121238
}
12131239

agent/testagent.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func (a *TestAgent) consulConfig() *consul.Config {
378378
// Instead of relying on one set of ports to be sufficient we retry
379379
// starting the agent with different ports on port conflict.
380380
func randomPortsSource(tls bool) (src config.Source, returnPortsFn func()) {
381-
ports := freeport.MustTake(6)
381+
ports := freeport.MustTake(7)
382382

383383
var http, https int
384384
if tls {
@@ -400,6 +400,7 @@ func randomPortsSource(tls bool) (src config.Source, returnPortsFn func()) {
400400
serf_lan = ` + strconv.Itoa(ports[3]) + `
401401
serf_wan = ` + strconv.Itoa(ports[4]) + `
402402
server = ` + strconv.Itoa(ports[5]) + `
403+
grpc = ` + strconv.Itoa(ports[6]) + `
403404
}
404405
`,
405406
}, func() { freeport.Return(ports) }

agent/xds/proxysupport/proxysupport.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package proxysupport
22

33
// EnvoyVersions lists the latest officially supported versions of envoy.
44
//
5+
// This list must be sorted by semver descending. Only one point release for
6+
// each major release should be present.
7+
//
58
// see: https://www.consul.io/docs/connect/proxies/envoy#supported-versions
69
var EnvoyVersions = []string{
710
"1.13.1",

0 commit comments

Comments
 (0)