forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_snapshot.sk.go
168 lines (139 loc) · 4.96 KB
/
config_snapshot.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
// Code generated by solo-kit. DO NOT EDIT.
package v1
import (
"fmt"
gloo_solo_io "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes"
"github.com/solo-io/go-utils/hashutils"
"go.uber.org/zap"
)
type ConfigSnapshot struct {
Meshes MeshesByNamespace
Meshingresses MeshingressesByNamespace
Meshgroups MeshgroupsByNamespace
Routingrules RoutingrulesByNamespace
Securityrules SecurityrulesByNamespace
Tlssecrets TlssecretsByNamespace
Upstreams gloo_solo_io.UpstreamsByNamespace
Pods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodsByNamespace
}
func (s ConfigSnapshot) Clone() ConfigSnapshot {
return ConfigSnapshot{
Meshes: s.Meshes.Clone(),
Meshingresses: s.Meshingresses.Clone(),
Meshgroups: s.Meshgroups.Clone(),
Routingrules: s.Routingrules.Clone(),
Securityrules: s.Securityrules.Clone(),
Tlssecrets: s.Tlssecrets.Clone(),
Upstreams: s.Upstreams.Clone(),
Pods: s.Pods.Clone(),
}
}
func (s ConfigSnapshot) Hash() uint64 {
return hashutils.HashAll(
s.hashMeshes(),
s.hashMeshingresses(),
s.hashMeshgroups(),
s.hashRoutingrules(),
s.hashSecurityrules(),
s.hashTlssecrets(),
s.hashUpstreams(),
s.hashPods(),
)
}
func (s ConfigSnapshot) hashMeshes() uint64 {
return hashutils.HashAll(s.Meshes.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashMeshingresses() uint64 {
return hashutils.HashAll(s.Meshingresses.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashMeshgroups() uint64 {
return hashutils.HashAll(s.Meshgroups.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashRoutingrules() uint64 {
return hashutils.HashAll(s.Routingrules.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashSecurityrules() uint64 {
return hashutils.HashAll(s.Securityrules.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashTlssecrets() uint64 {
return hashutils.HashAll(s.Tlssecrets.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashUpstreams() uint64 {
return hashutils.HashAll(s.Upstreams.List().AsInterfaces()...)
}
func (s ConfigSnapshot) hashPods() uint64 {
return hashutils.HashAll(s.Pods.List().AsInterfaces()...)
}
func (s ConfigSnapshot) HashFields() []zap.Field {
var fields []zap.Field
fields = append(fields, zap.Uint64("meshes", s.hashMeshes()))
fields = append(fields, zap.Uint64("meshingresses", s.hashMeshingresses()))
fields = append(fields, zap.Uint64("meshgroups", s.hashMeshgroups()))
fields = append(fields, zap.Uint64("routingrules", s.hashRoutingrules()))
fields = append(fields, zap.Uint64("securityrules", s.hashSecurityrules()))
fields = append(fields, zap.Uint64("tlssecrets", s.hashTlssecrets()))
fields = append(fields, zap.Uint64("upstreams", s.hashUpstreams()))
fields = append(fields, zap.Uint64("pods", s.hashPods()))
return append(fields, zap.Uint64("snapshotHash", s.Hash()))
}
type ConfigSnapshotStringer struct {
Version uint64
Meshes []string
Meshingresses []string
Meshgroups []string
Routingrules []string
Securityrules []string
Tlssecrets []string
Upstreams []string
Pods []string
}
func (ss ConfigSnapshotStringer) String() string {
s := fmt.Sprintf("ConfigSnapshot %v\n", ss.Version)
s += fmt.Sprintf(" Meshes %v\n", len(ss.Meshes))
for _, name := range ss.Meshes {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Meshingresses %v\n", len(ss.Meshingresses))
for _, name := range ss.Meshingresses {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Meshgroups %v\n", len(ss.Meshgroups))
for _, name := range ss.Meshgroups {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Routingrules %v\n", len(ss.Routingrules))
for _, name := range ss.Routingrules {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Securityrules %v\n", len(ss.Securityrules))
for _, name := range ss.Securityrules {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Tlssecrets %v\n", len(ss.Tlssecrets))
for _, name := range ss.Tlssecrets {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Upstreams %v\n", len(ss.Upstreams))
for _, name := range ss.Upstreams {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Pods %v\n", len(ss.Pods))
for _, name := range ss.Pods {
s += fmt.Sprintf(" %v\n", name)
}
return s
}
func (s ConfigSnapshot) Stringer() ConfigSnapshotStringer {
return ConfigSnapshotStringer{
Version: s.Hash(),
Meshes: s.Meshes.List().NamespacesDotNames(),
Meshingresses: s.Meshingresses.List().NamespacesDotNames(),
Meshgroups: s.Meshgroups.List().NamespacesDotNames(),
Routingrules: s.Routingrules.List().NamespacesDotNames(),
Securityrules: s.Securityrules.List().NamespacesDotNames(),
Tlssecrets: s.Tlssecrets.List().NamespacesDotNames(),
Upstreams: s.Upstreams.List().NamespacesDotNames(),
Pods: s.Pods.List().NamespacesDotNames(),
}
}