-
Notifications
You must be signed in to change notification settings - Fork 725
Expand file tree
/
Copy pathtypes.go
More file actions
228 lines (198 loc) · 8.19 KB
/
types.go
File metadata and controls
228 lines (198 loc) · 8.19 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.
package message
import (
"context"
"reflect"
"github.com/telepresenceio/watchable"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
"github.com/envoyproxy/gateway/internal/ir"
)
// ProviderResources message
type ProviderResources struct {
// GatewayAPIResources is a map from a GatewayClass name to
// a group of gateway API and other related resources with trace context.
GatewayAPIResources watchable.Map[string, *resource.ControllerResourcesContext]
// GatewayAPIStatuses is a group of gateway api
// resource statuses maps.
GatewayAPIStatuses
// PolicyStatuses is a group of policy statuses maps.
PolicyStatuses
// ExtensionStatuses is a group of gw-api extension resource statuses map.
ExtensionStatuses
}
func (p *ProviderResources) GetResources() []*resource.Resources {
if p.GatewayAPIResources.Len() == 0 {
return nil
}
for _, v := range p.GatewayAPIResources.LoadAll() {
if v != nil && v.Resources != nil {
return *v.Resources
}
}
return nil
}
func (p *ProviderResources) GetResourcesByGatewayClass(name string) *resource.Resources {
for _, r := range p.GetResources() {
if r != nil && r.GatewayClass != nil && r.GatewayClass.Name == name {
return r
}
}
return nil
}
func (p *ProviderResources) GetResourcesKey() string {
if p.GatewayAPIResources.Len() == 0 {
return ""
}
for k := range p.GatewayAPIResources.LoadAll() {
return k
}
return ""
}
func (p *ProviderResources) Close() {
p.GatewayAPIResources.Close()
p.GatewayAPIStatuses.Close()
p.PolicyStatuses.Close()
p.ExtensionStatuses.Close()
}
// GatewayAPIStatuses contains gateway API resources statuses
type GatewayAPIStatuses struct {
GatewayClassStatuses watchable.Map[types.NamespacedName, *gwapiv1.GatewayClassStatus]
GatewayStatuses watchable.Map[types.NamespacedName, *gwapiv1.GatewayStatus]
HTTPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1.HTTPRouteStatus]
GRPCRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1.GRPCRouteStatus]
TLSRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1.TLSRouteStatus]
TCPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.TCPRouteStatus]
UDPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.UDPRouteStatus]
ListenerSetStatuses watchable.Map[types.NamespacedName, *gwapiv1.ListenerSetStatus]
}
func (s *GatewayAPIStatuses) Close() {
s.GatewayClassStatuses.Close()
s.GatewayStatuses.Close()
s.HTTPRouteStatuses.Close()
s.GRPCRouteStatuses.Close()
s.TLSRouteStatuses.Close()
s.TCPRouteStatuses.Close()
s.UDPRouteStatuses.Close()
s.ListenerSetStatuses.Close()
}
type NamespacedNameAndGVK struct {
types.NamespacedName
schema.GroupVersionKind
}
// PolicyStatuses contains policy related resources statuses
type PolicyStatuses struct {
ClientTrafficPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
BackendTrafficPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
EnvoyPatchPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
SecurityPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
BackendTLSPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
EnvoyExtensionPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1.PolicyStatus]
ExtensionPolicyStatuses watchable.Map[NamespacedNameAndGVK, *gwapiv1.PolicyStatus]
}
// ExtensionStatuses contains statuses related to gw-api extension resources
type ExtensionStatuses struct {
BackendStatuses watchable.Map[types.NamespacedName, *egv1a1.BackendStatus]
}
func (p *PolicyStatuses) Close() {
p.ClientTrafficPolicyStatuses.Close()
p.BackendTrafficPolicyStatuses.Close()
p.SecurityPolicyStatuses.Close()
p.EnvoyPatchPolicyStatuses.Close()
p.BackendTLSPolicyStatuses.Close()
p.EnvoyExtensionPolicyStatuses.Close()
p.ExtensionPolicyStatuses.Close()
}
func (e *ExtensionStatuses) Close() {
e.BackendStatuses.Close()
}
type XdsIRWithContext struct {
XdsIR *ir.Xds
Context context.Context
}
// DeepCopy creates a new ControllerResourcesContext.
// The Context field is preserved (not deep copied) since contexts are meant to be passed around.
func (x *XdsIRWithContext) DeepCopy() *XdsIRWithContext {
if x == nil {
return nil
}
var xdsIRCopy *ir.Xds
if x.XdsIR != nil {
xdsIRCopy = x.XdsIR.DeepCopy()
}
return &XdsIRWithContext{
XdsIR: xdsIRCopy,
Context: x.Context,
}
}
func (x *XdsIRWithContext) Equal(other *XdsIRWithContext) bool {
if x == nil && other == nil {
return true
}
if x == nil || other == nil {
return false
}
if x.XdsIR == nil && other.XdsIR == nil {
return true
}
if x.XdsIR == nil || other.XdsIR == nil {
return false
}
return reflect.DeepEqual(x.XdsIR, other.XdsIR)
}
// XdsIR message
type XdsIR struct {
watchable.Map[string, *XdsIRWithContext]
}
// InfraIR message
type InfraIR struct {
watchable.Map[string, *ir.Infra]
}
type MessageName string
const (
// XDSIRMessageName is a message containing xds-ir translated from provider-resources
XDSIRMessageName MessageName = "xds-ir"
// InfraIRMessageName is a message containing infra-ir translated from provider-resources
InfraIRMessageName MessageName = "infra-ir"
// ProviderResourcesMessageName is a message containing gw-api and envoy gateway resources from the provider
ProviderResourcesMessageName MessageName = "provider-resources"
// BackendStatusMessageName is a message containing updates to Backend status
BackendStatusMessageName MessageName = "backend-status"
// ExtensionServerPoliciesStatusMessageName is a message containing updates to ExtensionServerPolicy status
ExtensionServerPoliciesStatusMessageName MessageName = "extensionserverpolicies-status"
// EnvoyExtensionPolicyStatusMessageName is a message containing updates to EnvoyExtensionPolicy status
EnvoyExtensionPolicyStatusMessageName MessageName = "envoyextensionpolicy-status"
// EnvoyPatchPolicyStatusMessageName is a message containing updates to EnvoyPatchPolicy status
EnvoyPatchPolicyStatusMessageName MessageName = "envoypatchpolicy-status"
// SecurityPolicyStatusMessageName is a message containing updates to SecurityPolicy status
SecurityPolicyStatusMessageName MessageName = "securitypolicy-status"
// BackendTrafficPolicyStatusMessageName is a message containing updates to BackendTrafficPolicy status
BackendTrafficPolicyStatusMessageName MessageName = "backendtrafficpolicy-status"
// ClientTrafficPolicyStatusMessageName is a message containing updates to ClientTrafficPolicy status
ClientTrafficPolicyStatusMessageName MessageName = "clienttrafficpolicy-status"
// BackendTLSPolicyStatusMessageName is a message containing updates to BackendTLSPolicy status
BackendTLSPolicyStatusMessageName MessageName = "backendtlspolicy-status"
// UDPRouteStatusMessageName is a message containing updates to UDPRoute status
UDPRouteStatusMessageName MessageName = "udproute-status"
// TCPRouteStatusMessageName is a message containing updates to TCPRoute status
TCPRouteStatusMessageName MessageName = "tcproute-status"
// TLSRouteStatusMessageName is a message containing updates to TLSRoute status
TLSRouteStatusMessageName MessageName = "tlsroute-status"
// GRPCRouteStatusMessageName is a message containing updates to GRPCRoute status
GRPCRouteStatusMessageName MessageName = "grpcroute-status"
// HTTPRouteStatusMessageName is a message containing updates to HTTPRoute status
HTTPRouteStatusMessageName MessageName = "httproute-status"
// GatewayStatusMessageName is a message containing updates to Gateway status
GatewayStatusMessageName MessageName = "gateway-status"
// ListenerSetStatusMessageName is a message containing updates to ListenerSet status
ListenerSetStatusMessageName MessageName = "listenerset-status"
// GatewayClassStatusMessageName is a message containing updates to GatewayClass status
GatewayClassStatusMessageName MessageName = "gatewayclass-status"
)