Skip to content

Commit 6564754

Browse files
EItanyapeterj
andcommitted
enable websockets (#4)
Signed-off-by: Peter Jausovec <peter.jausovec@solo.io> Co-authored-by: Peter Jausovec <peter.jausovec@solo.io>
1 parent 5169cdd commit 6564754

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

cmd/atenet/internal/app/router/xds.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const (
6262
IngressHTTPSListener = "ingress_https_listener"
6363
RouteName = "substrate_routes"
6464
ClusterName = "ate-cluster"
65+
websocketUpgradeType = "websocket"
6566
)
6667

6768
// XdsServer implements an aggregated discovery service server for dynamic Envoy router nodes.
@@ -287,6 +288,9 @@ func (x *XdsServer) buildRoutes() *routev3.RouteConfiguration {
287288
Cluster: "dynamic_forward_proxy_cluster",
288289
},
289290
Timeout: durationpb.New(10 * time.Second),
291+
UpgradeConfigs: []*routev3.RouteAction_UpgradeConfig{
292+
{UpgradeType: websocketUpgradeType},
293+
},
290294
},
291295
},
292296
},
@@ -334,6 +338,10 @@ func (x *XdsServer) buildHcm(statPrefix string) *anypb.Any {
334338
hcm, _ := anypb.New(&hcmv3.HttpConnectionManager{
335339
StatPrefix: statPrefix,
336340
GenerateRequestId: &wrapperspb.BoolValue{Value: true},
341+
UpgradeConfigs: []*hcmv3.HttpConnectionManager_UpgradeConfig{
342+
{UpgradeType: websocketUpgradeType},
343+
},
344+
StreamIdleTimeout: durationpb.New(0),
337345
AccessLog: []*accesslogv3.AccessLog{
338346
{
339347
Name: "envoy.access_loggers.stdout",

cmd/atenet/internal/app/router/xds_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
2525
listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
2626
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
27+
hcmv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
2728
cachev3 "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
2829
resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
2930
)
@@ -116,6 +117,10 @@ func TestXdsServer_UpdateSnapshot(t *testing.T) {
116117
if fallbackRoute.GetMatch().GetPrefix() != "/" {
117118
t.Errorf("Expected path mapping prefix '/', got '%s'", fallbackRoute.GetMatch().GetPrefix())
118119
}
120+
routeAction := fallbackRoute.GetRoute()
121+
if len(routeAction.GetUpgradeConfigs()) != 1 || routeAction.GetUpgradeConfigs()[0].GetUpgradeType() != websocketUpgradeType {
122+
t.Errorf("Expected route websocket upgrade config, got %+v", routeAction.GetUpgradeConfigs())
123+
}
119124
}
120125

121126
// Verify listeners generated
@@ -135,6 +140,15 @@ func TestXdsServer_UpdateSnapshot(t *testing.T) {
135140
if sa.GetAddress() != "0.0.0.0" {
136141
t.Errorf("Expected address '0.0.0.0', got %s", sa.GetAddress())
137142
}
143+
144+
hcmAny := l.GetFilterChains()[0].GetFilters()[0].GetTypedConfig()
145+
hcm := &hcmv3.HttpConnectionManager{}
146+
if err := hcmAny.UnmarshalTo(hcm); err != nil {
147+
t.Fatalf("Failed to unmarshal HCM: %v", err)
148+
}
149+
if len(hcm.GetUpgradeConfigs()) != 1 || hcm.GetUpgradeConfigs()[0].GetUpgradeType() != websocketUpgradeType {
150+
t.Errorf("Expected HCM websocket upgrade config, got %+v", hcm.GetUpgradeConfigs())
151+
}
138152
}
139153
}
140154

0 commit comments

Comments
 (0)