/
listener.go
51 lines (46 loc) · 1.72 KB
/
listener.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package v3
import (
listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
hcmv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
xdswellknown "github.com/envoyproxy/go-control-plane/pkg/wellknown"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"github.com/api7/apisix-mesh-agent/pkg/log"
)
var (
_hcmv3 = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
)
func (adaptor *adaptor) CollectRouteNamesAndConfigs(l *listenerv3.Listener) ([]string, []*routev3.RouteConfiguration, error) {
var (
rdsNames []string
staticConfigs []*routev3.RouteConfiguration
)
for _, fc := range l.FilterChains {
for _, f := range fc.Filters {
if f.Name == xdswellknown.HTTPConnectionManager && f.GetTypedConfig().GetTypeUrl() == _hcmv3 {
var hcm hcmv3.HttpConnectionManager
if err := anypb.UnmarshalTo(f.GetTypedConfig(), &hcm, proto.UnmarshalOptions{}); err != nil {
log.Errorw("failed to unmarshal HttpConnectionManager config",
zap.Error(err),
zap.Any("listener", l),
)
return nil, nil, err
}
if hcm.GetRds() != nil {
rdsNames = append(rdsNames, hcm.GetRds().GetRouteConfigName())
} else if hcm.GetRouteConfig() != nil {
// TODO deep copy?
staticConfigs = append(staticConfigs, hcm.GetRouteConfig())
}
}
}
}
adaptor.logger.Debugw("got route names and config from listener",
zap.Strings("route_names", rdsNames),
zap.Any("route_configs", staticConfigs),
zap.Any("listener", l),
)
return rdsNames, staticConfigs, nil
}