-
Notifications
You must be signed in to change notification settings - Fork 476
/
envoy.go
150 lines (127 loc) · 4.73 KB
/
envoy.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package kubernetes
import "github.com/mitchellh/mapstructure"
// Root of ConfigDump
type ConfigDump struct {
Configs []interface{} `json:"configs"`
}
type ClusterDump struct {
DynamicClusters []EnvoyClusterWrapper `mapstructure:"dynamic_active_clusters"`
StaticClusters []EnvoyClusterWrapper `mapstructure:"static_clusters"`
}
type EnvoyClusterWrapper struct {
Cluster EnvoyCluster `mapstructure:"cluster"`
}
type EnvoyCluster struct {
Name string `mapstructure:"name"`
Type string `mapstructure:"type"`
Metadata *EnvoyMetadata `mapstructure:"metadata,omitempty"`
}
type EnvoyMetadata struct {
FilterMetadata *struct {
Istio *struct {
Config string `mapstructure:"config,omitempty"`
} `mapstructure:"istio,omitempty"`
} `mapstructure:"filter_metadata,omitempty"`
}
type RouteDump struct {
DynamicRouteConfigs []EnvoyRouteConfig `mapstructure:"dynamic_route_configs"`
StaticRouteConfigs []EnvoyRouteConfig `mapstructure:"static_route_configs"`
}
type EnvoyRouteConfig struct {
RouteConfig *RouteConfig `mapstructure:"route_config,omitempty"`
}
type ListenerDump struct {
DynamicListeners []DynamicListener `mapstructure:"dynamic_listeners"`
StaticListeners []StaticListener `mapstructure:"static_listeners"`
}
type DynamicListener struct {
Name string `mapstructure:"name"`
ActiveState StaticListener `mapstructure:"active_state"`
}
type StaticListener struct {
LastUpdated string `mapstructure:"last_updated"`
VersionInfo string `mapstructure:"version_info"`
Listener EnvoyListener `mapstructure:"listener"`
}
type EnvoyListener struct {
Address struct {
SocketAddress struct {
Address string `mapstructure:"address"`
PortValue float64 `mapstructure:"port_value"`
} `mapstructure:"socket_address"`
} `mapstructure:"address"`
FilterChains []EnvoyFilterChain `mapstructure:"filter_chains,omitempty"`
DefaultFilterChain *EnvoyFilterChain `mapstructure:"default_filter_chain,omitempty"`
}
type EnvoyFilterChain struct {
Filters []EnvoyListenerFilter `mapstructure:"filters"`
FilterChainMatch *FilterChainMatch `mapstructure:"filter_chain_match"`
}
type EnvoyListenerFilter struct {
Name string `mapstructure:"name"`
TypedConfig struct {
Type string `mapstructure:"@type"`
Cluster string `mapstructure:"cluster"`
RouteConfig *RouteConfig `mapstructure:"route_config,omitempty"`
Rds *struct {
RouteConfigName string `mapstructure:"route_config_name"`
} `mapstructure:"rds,omitempty"`
} `mapstructure:"typed_config"`
}
type RouteConfig struct {
Name string `mapstructure:"name"`
VirtualHosts []VirtualHostFilter `mapstructure:"virtual_hosts,omitempty"`
}
type VirtualHostFilter struct {
Domains []string `mapstructure:"domains,omitempty"`
Name string `mapstructure:"name,omitempty"`
Routes []struct {
Name string `mapstructure:"name"`
Match map[string]interface{} `mapstructure:"match"`
Metadata *EnvoyMetadata `mapstructure:"metadata,omitempty"`
Route *struct {
Cluster string `mapstructure:"cluster,omitempty"`
} `mapstructure:"route,omitempty"`
} `mapstructure:"routes,omitempty"`
}
type FilterChainMatch struct {
ApplicationProtocols []string `mapstructure:"application_protocols,omitempty"`
TransportProtocol string `mapstructure:"transport_protocol,omitempty"`
ServerNames []string `mapstructure:"server_names,omitempty"`
DestinationPort *int32 `mapstructure:"destination_port,omitempty"`
PrefixRanges []struct {
AddressPrefix string `mapstructure:"address_prefix"`
PrefixLen int `mapstructure:"prefix_len"`
} `mapstructure:"prefix_ranges"`
}
func (cd *ConfigDump) GetListeners() (*ListenerDump, error) {
listenersDumpRaw := cd.GetConfig("type.googleapis.com/envoy.admin.v3.ListenersConfigDump")
var listenersDump ListenerDump
return &listenersDump, mapstructure.Decode(listenersDumpRaw, &listenersDump)
}
func (cd *ConfigDump) GetClusters() (*ClusterDump, error) {
clusterDumpRaw := cd.GetConfig("type.googleapis.com/envoy.admin.v3.ClustersConfigDump")
var clusterDump ClusterDump
return &clusterDump, mapstructure.Decode(clusterDumpRaw, &clusterDump)
}
func (cd *ConfigDump) GetRoutes() (*RouteDump, error) {
routeDumpRaw := cd.GetConfig("type.googleapis.com/envoy.admin.v3.RoutesConfigDump")
var routeDump RouteDump
return &routeDump, mapstructure.Decode(routeDumpRaw, &routeDump)
}
func (cd *ConfigDump) GetConfig(objectType string) map[string]interface{} {
for _, configRaw := range cd.Configs {
conf, ok := configRaw.(map[string]interface{})
if !ok {
continue
}
configType, ok := conf["@type"]
if !ok {
continue
}
if configType == objectType {
return conf
}
}
return nil
}