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