forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting_rule.sk.go
169 lines (143 loc) · 4.2 KB
/
routing_rule.sk.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
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
// Code generated by solo-kit. DO NOT EDIT.
package v1
import (
"sort"
"github.com/solo-io/go-utils/hashutils"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd"
"github.com/solo-io/solo-kit/pkg/api/v1/resources"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/solo-io/solo-kit/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func NewRoutingRule(namespace, name string) *RoutingRule {
routingrule := &RoutingRule{}
routingrule.SetMetadata(core.Metadata{
Name: name,
Namespace: namespace,
})
return routingrule
}
func (r *RoutingRule) SetMetadata(meta core.Metadata) {
r.Metadata = meta
}
func (r *RoutingRule) SetStatus(status core.Status) {
r.Status = status
}
func (r *RoutingRule) Hash() uint64 {
metaCopy := r.GetMetadata()
metaCopy.ResourceVersion = ""
return hashutils.HashAll(
metaCopy,
r.TargetMesh,
r.SourceSelector,
r.DestinationSelector,
r.RequestMatchers,
r.Spec,
)
}
type RoutingRuleList []*RoutingRule
type RoutingrulesByNamespace map[string]RoutingRuleList
// namespace is optional, if left empty, names can collide if the list contains more than one with the same name
func (list RoutingRuleList) Find(namespace, name string) (*RoutingRule, error) {
for _, routingRule := range list {
if routingRule.GetMetadata().Name == name {
if namespace == "" || routingRule.GetMetadata().Namespace == namespace {
return routingRule, nil
}
}
}
return nil, errors.Errorf("list did not find routingRule %v.%v", namespace, name)
}
func (list RoutingRuleList) AsResources() resources.ResourceList {
var ress resources.ResourceList
for _, routingRule := range list {
ress = append(ress, routingRule)
}
return ress
}
func (list RoutingRuleList) AsInputResources() resources.InputResourceList {
var ress resources.InputResourceList
for _, routingRule := range list {
ress = append(ress, routingRule)
}
return ress
}
func (list RoutingRuleList) Names() []string {
var names []string
for _, routingRule := range list {
names = append(names, routingRule.GetMetadata().Name)
}
return names
}
func (list RoutingRuleList) NamespacesDotNames() []string {
var names []string
for _, routingRule := range list {
names = append(names, routingRule.GetMetadata().Namespace+"."+routingRule.GetMetadata().Name)
}
return names
}
func (list RoutingRuleList) Sort() RoutingRuleList {
sort.SliceStable(list, func(i, j int) bool {
return list[i].GetMetadata().Less(list[j].GetMetadata())
})
return list
}
func (list RoutingRuleList) Clone() RoutingRuleList {
var routingRuleList RoutingRuleList
for _, routingRule := range list {
routingRuleList = append(routingRuleList, resources.Clone(routingRule).(*RoutingRule))
}
return routingRuleList
}
func (list RoutingRuleList) Each(f func(element *RoutingRule)) {
for _, routingRule := range list {
f(routingRule)
}
}
func (list RoutingRuleList) AsInterfaces() []interface{} {
var asInterfaces []interface{}
list.Each(func(element *RoutingRule) {
asInterfaces = append(asInterfaces, element)
})
return asInterfaces
}
func (byNamespace RoutingrulesByNamespace) Add(routingRule ...*RoutingRule) {
for _, item := range routingRule {
byNamespace[item.GetMetadata().Namespace] = append(byNamespace[item.GetMetadata().Namespace], item)
}
}
func (byNamespace RoutingrulesByNamespace) Clear(namespace string) {
delete(byNamespace, namespace)
}
func (byNamespace RoutingrulesByNamespace) List() RoutingRuleList {
var list RoutingRuleList
for _, routingRuleList := range byNamespace {
list = append(list, routingRuleList...)
}
return list.Sort()
}
func (byNamespace RoutingrulesByNamespace) Clone() RoutingrulesByNamespace {
cloned := make(RoutingrulesByNamespace)
for ns, list := range byNamespace {
cloned[ns] = list.Clone()
}
return cloned
}
var _ resources.Resource = &RoutingRule{}
// Kubernetes Adapter for RoutingRule
func (o *RoutingRule) GetObjectKind() schema.ObjectKind {
t := RoutingRuleCrd.TypeMeta()
return &t
}
func (o *RoutingRule) DeepCopyObject() runtime.Object {
return resources.Clone(o).(*RoutingRule)
}
var RoutingRuleCrd = crd.NewCrd("supergloo.solo.io",
"routingrules",
"supergloo.solo.io",
"v1",
"RoutingRule",
"rr",
false,
&RoutingRule{})