forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh_group.sk.go
144 lines (121 loc) · 3.36 KB
/
mesh_group.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
// 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 NewMeshGroup(namespace, name string) *MeshGroup {
meshgroup := &MeshGroup{}
meshgroup.SetMetadata(core.Metadata{
Name: name,
Namespace: namespace,
})
return meshgroup
}
func (r *MeshGroup) SetMetadata(meta core.Metadata) {
r.Metadata = meta
}
func (r *MeshGroup) SetStatus(status core.Status) {
r.Status = status
}
func (r *MeshGroup) Hash() uint64 {
metaCopy := r.GetMetadata()
metaCopy.ResourceVersion = ""
return hashutils.HashAll(
metaCopy,
r.Meshes,
)
}
type MeshGroupList []*MeshGroup
// namespace is optional, if left empty, names can collide if the list contains more than one with the same name
func (list MeshGroupList) Find(namespace, name string) (*MeshGroup, error) {
for _, meshGroup := range list {
if meshGroup.GetMetadata().Name == name {
if namespace == "" || meshGroup.GetMetadata().Namespace == namespace {
return meshGroup, nil
}
}
}
return nil, errors.Errorf("list did not find meshGroup %v.%v", namespace, name)
}
func (list MeshGroupList) AsResources() resources.ResourceList {
var ress resources.ResourceList
for _, meshGroup := range list {
ress = append(ress, meshGroup)
}
return ress
}
func (list MeshGroupList) AsInputResources() resources.InputResourceList {
var ress resources.InputResourceList
for _, meshGroup := range list {
ress = append(ress, meshGroup)
}
return ress
}
func (list MeshGroupList) Names() []string {
var names []string
for _, meshGroup := range list {
names = append(names, meshGroup.GetMetadata().Name)
}
return names
}
func (list MeshGroupList) NamespacesDotNames() []string {
var names []string
for _, meshGroup := range list {
names = append(names, meshGroup.GetMetadata().Namespace+"."+meshGroup.GetMetadata().Name)
}
return names
}
func (list MeshGroupList) Sort() MeshGroupList {
sort.SliceStable(list, func(i, j int) bool {
return list[i].GetMetadata().Less(list[j].GetMetadata())
})
return list
}
func (list MeshGroupList) Clone() MeshGroupList {
var meshGroupList MeshGroupList
for _, meshGroup := range list {
meshGroupList = append(meshGroupList, resources.Clone(meshGroup).(*MeshGroup))
}
return meshGroupList
}
func (list MeshGroupList) Each(f func(element *MeshGroup)) {
for _, meshGroup := range list {
f(meshGroup)
}
}
func (list MeshGroupList) EachResource(f func(element resources.Resource)) {
for _, meshGroup := range list {
f(meshGroup)
}
}
func (list MeshGroupList) AsInterfaces() []interface{} {
var asInterfaces []interface{}
list.Each(func(element *MeshGroup) {
asInterfaces = append(asInterfaces, element)
})
return asInterfaces
}
var _ resources.Resource = &MeshGroup{}
// Kubernetes Adapter for MeshGroup
func (o *MeshGroup) GetObjectKind() schema.ObjectKind {
t := MeshGroupCrd.TypeMeta()
return &t
}
func (o *MeshGroup) DeepCopyObject() runtime.Object {
return resources.Clone(o).(*MeshGroup)
}
var MeshGroupCrd = crd.NewCrd("supergloo.solo.io",
"meshgroups",
"supergloo.solo.io",
"v1",
"MeshGroup",
"mg",
false,
&MeshGroup{})