/
udproute.go
62 lines (49 loc) · 1.24 KB
/
udproute.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
package store
import (
"k8s.io/apimachinery/pkg/types"
stnrgwv1 "github.com/l7mp/stunner-gateway-operator/api/v1"
)
var UDPRoutes = NewUDPRouteStore()
var UDPRoutesV1A2 = NewUDPRouteStore()
type UDPRouteStore struct {
Store
}
func NewUDPRouteStore() *UDPRouteStore {
return &UDPRouteStore{
Store: NewStore(),
}
}
// GetAll returns all UDPRoute objects from the global storage
func (s *UDPRouteStore) GetAll() []*stnrgwv1.UDPRoute {
ret := make([]*stnrgwv1.UDPRoute, 0)
objects := s.Objects()
for i := range objects {
r, ok := objects[i].(*stnrgwv1.UDPRoute)
if !ok {
// this is critical: throw up hands and die
panic("access to an invalid object in the global UDPRouteStore")
}
ret = append(ret, r)
}
return ret
}
// GetObject returns a named UDPRoute object from the global storage
func (s *UDPRouteStore) GetObject(nsName types.NamespacedName) *stnrgwv1.UDPRoute {
o := s.Get(nsName)
if o == nil {
return nil
}
r, ok := o.(*stnrgwv1.UDPRoute)
if !ok {
// this is critical: throw up hands and die
panic("access to an invalid object in the global UDPRouteStore")
}
return r
}
func (s *UDPRouteStore) DeepCopy() *UDPRouteStore {
ret := NewUDPRouteStore()
for _, o := range s.GetAll() {
ret.Upsert(o)
}
return ret
}