forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathistio_discovery_snapshot.sk.go
124 lines (101 loc) · 3.6 KB
/
istio_discovery_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
// 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"
istio_authentication_v1alpha1 "github.com/solo-io/supergloo/pkg/api/external/istio/authorization/v1alpha1"
"github.com/solo-io/go-utils/hashutils"
"go.uber.org/zap"
)
type IstioDiscoverySnapshot struct {
Meshes MeshesByNamespace
Installs InstallsByNamespace
Pods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodsByNamespace
Upstreams gloo_solo_io.UpstreamsByNamespace
Meshpolicies istio_authentication_v1alpha1.MeshPolicyList
}
func (s IstioDiscoverySnapshot) Clone() IstioDiscoverySnapshot {
return IstioDiscoverySnapshot{
Meshes: s.Meshes.Clone(),
Installs: s.Installs.Clone(),
Pods: s.Pods.Clone(),
Upstreams: s.Upstreams.Clone(),
Meshpolicies: s.Meshpolicies.Clone(),
}
}
func (s IstioDiscoverySnapshot) Hash() uint64 {
return hashutils.HashAll(
s.hashMeshes(),
s.hashInstalls(),
s.hashPods(),
s.hashUpstreams(),
s.hashMeshpolicies(),
)
}
func (s IstioDiscoverySnapshot) hashMeshes() uint64 {
return hashutils.HashAll(s.Meshes.List().AsInterfaces()...)
}
func (s IstioDiscoverySnapshot) hashInstalls() uint64 {
return hashutils.HashAll(s.Installs.List().AsInterfaces()...)
}
func (s IstioDiscoverySnapshot) hashPods() uint64 {
return hashutils.HashAll(s.Pods.List().AsInterfaces()...)
}
func (s IstioDiscoverySnapshot) hashUpstreams() uint64 {
return hashutils.HashAll(s.Upstreams.List().AsInterfaces()...)
}
func (s IstioDiscoverySnapshot) hashMeshpolicies() uint64 {
return hashutils.HashAll(s.Meshpolicies.AsInterfaces()...)
}
func (s IstioDiscoverySnapshot) HashFields() []zap.Field {
var fields []zap.Field
fields = append(fields, zap.Uint64("meshes", s.hashMeshes()))
fields = append(fields, zap.Uint64("installs", s.hashInstalls()))
fields = append(fields, zap.Uint64("pods", s.hashPods()))
fields = append(fields, zap.Uint64("upstreams", s.hashUpstreams()))
fields = append(fields, zap.Uint64("meshpolicies", s.hashMeshpolicies()))
return append(fields, zap.Uint64("snapshotHash", s.Hash()))
}
type IstioDiscoverySnapshotStringer struct {
Version uint64
Meshes []string
Installs []string
Pods []string
Upstreams []string
Meshpolicies []string
}
func (ss IstioDiscoverySnapshotStringer) String() string {
s := fmt.Sprintf("IstioDiscoverySnapshot %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(" Installs %v\n", len(ss.Installs))
for _, name := range ss.Installs {
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)
}
s += fmt.Sprintf(" Upstreams %v\n", len(ss.Upstreams))
for _, name := range ss.Upstreams {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Meshpolicies %v\n", len(ss.Meshpolicies))
for _, name := range ss.Meshpolicies {
s += fmt.Sprintf(" %v\n", name)
}
return s
}
func (s IstioDiscoverySnapshot) Stringer() IstioDiscoverySnapshotStringer {
return IstioDiscoverySnapshotStringer{
Version: s.Hash(),
Meshes: s.Meshes.List().NamespacesDotNames(),
Installs: s.Installs.List().NamespacesDotNames(),
Pods: s.Pods.List().NamespacesDotNames(),
Upstreams: s.Upstreams.List().NamespacesDotNames(),
Meshpolicies: s.Meshpolicies.Names(),
}
}