...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "sync"
20
21 "sigs.k8s.io/controller-runtime/pkg/client"
22 )
23
24
25
26
27 type chaosKindMap struct {
28 sync.RWMutex
29 kinds map[string]*ChaosKind
30 }
31
32 func (c *chaosKindMap) register(name string, kind *ChaosKind) {
33 c.Lock()
34 defer c.Unlock()
35 c.kinds[name] = kind
36 }
37
38
39 func (c *chaosKindMap) clone() map[string]*ChaosKind {
40 c.RLock()
41 defer c.RUnlock()
42
43 out := make(map[string]*ChaosKind)
44 for key, kind := range c.kinds {
45 out[key] = &ChaosKind{
46 chaos: kind.chaos,
47 list: kind.list,
48 }
49 }
50
51 return out
52 }
53
54
55 func AllKinds() map[string]*ChaosKind {
56 return all.clone()
57 }
58
59 func AllKindsIncludeScheduleAndWorkflow() map[string]*ChaosKind {
60 all := chaosKindMap{
61 kinds: all.clone(),
62 }
63 all.register(KindSchedule, &ChaosKind{
64 chaos: &Schedule{},
65 list: &ScheduleList{},
66 })
67 all.register(KindWorkflow, &ChaosKind{
68 chaos: &Workflow{},
69 list: &WorkflowList{},
70 })
71
72 return all.kinds
73 }
74
75
76 var all = &chaosKindMap{
77 kinds: make(map[string]*ChaosKind),
78 }
79
80
81
82
83 type ChaosKind struct {
84 chaos client.Object
85 list GenericChaosList
86 }
87
88
89 func (it *ChaosKind) SpawnObject() client.Object {
90 return it.chaos.DeepCopyObject().(client.Object)
91 }
92
93
94 func (it *ChaosKind) SpawnList() GenericChaosList {
95 return it.list.DeepCopyList()
96 }
97
98
99 func AllScheduleItemKinds() map[string]*ChaosKind {
100 return allScheduleItem.clone()
101 }
102
103
104 var allScheduleItem = &chaosKindMap{
105 kinds: make(map[string]*ChaosKind),
106 }
107