-
Notifications
You must be signed in to change notification settings - Fork 363
/
types.go
129 lines (108 loc) · 3.78 KB
/
types.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
// 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 (
"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"
"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/internal/ir"
xdstypes "github.com/envoyproxy/gateway/internal/xds/types"
)
// ProviderResources message
type ProviderResources struct {
// GatewayAPIResources is a map from a GatewayClass name to
// a group of gateway API and other related resources.
GatewayAPIResources watchable.Map[string, *gatewayapi.ControllerResources]
// GatewayAPIStatuses is a group of gateway api
// resource statuses maps.
GatewayAPIStatuses
// PolicyStatuses is a group of policy statuses maps.
PolicyStatuses
}
func (p *ProviderResources) GetResources() []*gatewayapi.Resources {
if p.GatewayAPIResources.Len() == 0 {
return nil
}
for _, v := range p.GatewayAPIResources.LoadAll() {
return *v
}
return nil
}
func (p *ProviderResources) GetResourcesByGatewayClass(name string) *gatewayapi.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()
}
// GatewayAPIStatuses contains gateway API resources statuses
type GatewayAPIStatuses struct {
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, *gwapiv1a2.TLSRouteStatus]
TCPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.TCPRouteStatus]
UDPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.UDPRouteStatus]
}
func (s *GatewayAPIStatuses) Close() {
s.GatewayStatuses.Close()
s.HTTPRouteStatuses.Close()
s.GRPCRouteStatuses.Close()
s.TLSRouteStatuses.Close()
s.TCPRouteStatuses.Close()
s.UDPRouteStatuses.Close()
}
type NamespacedNameAndGVK struct {
types.NamespacedName
schema.GroupVersionKind
}
// PolicyStatuses contains policy related resources statuses
type PolicyStatuses struct {
ClientTrafficPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
BackendTrafficPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
EnvoyPatchPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
SecurityPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
BackendTLSPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
EnvoyExtensionPolicyStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.PolicyStatus]
ExtensionPolicyStatuses watchable.Map[NamespacedNameAndGVK, *gwapiv1a2.PolicyStatus]
}
func (p *PolicyStatuses) Close() {
p.ClientTrafficPolicyStatuses.Close()
p.SecurityPolicyStatuses.Close()
p.EnvoyPatchPolicyStatuses.Close()
p.BackendTLSPolicyStatuses.Close()
p.EnvoyExtensionPolicyStatuses.Close()
p.ExtensionPolicyStatuses.Close()
}
// XdsIR message
type XdsIR struct {
watchable.Map[string, *ir.Xds]
}
// InfraIR message
type InfraIR struct {
watchable.Map[string, *ir.Infra]
}
// Xds message
type Xds struct {
watchable.Map[string, *xdstypes.ResourceVersionTable]
}