forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery_snapshot.sk.go
108 lines (87 loc) · 2.93 KB
/
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
// 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 DiscoverySnapshot struct {
Pods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList
Upstreams gloo_solo_io.UpstreamList
Tlssecrets TlsSecretList
Deployments github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.DeploymentList
}
func (s DiscoverySnapshot) Clone() DiscoverySnapshot {
return DiscoverySnapshot{
Pods: s.Pods.Clone(),
Upstreams: s.Upstreams.Clone(),
Tlssecrets: s.Tlssecrets.Clone(),
Deployments: s.Deployments.Clone(),
}
}
func (s DiscoverySnapshot) Hash() uint64 {
return hashutils.HashAll(
s.hashPods(),
s.hashUpstreams(),
s.hashTlssecrets(),
s.hashDeployments(),
)
}
func (s DiscoverySnapshot) hashPods() uint64 {
return hashutils.HashAll(s.Pods.AsInterfaces()...)
}
func (s DiscoverySnapshot) hashUpstreams() uint64 {
return hashutils.HashAll(s.Upstreams.AsInterfaces()...)
}
func (s DiscoverySnapshot) hashTlssecrets() uint64 {
return hashutils.HashAll(s.Tlssecrets.AsInterfaces()...)
}
func (s DiscoverySnapshot) hashDeployments() uint64 {
return hashutils.HashAll(s.Deployments.AsInterfaces()...)
}
func (s DiscoverySnapshot) HashFields() []zap.Field {
var fields []zap.Field
fields = append(fields, zap.Uint64("pods", s.hashPods()))
fields = append(fields, zap.Uint64("upstreams", s.hashUpstreams()))
fields = append(fields, zap.Uint64("tlssecrets", s.hashTlssecrets()))
fields = append(fields, zap.Uint64("deployments", s.hashDeployments()))
return append(fields, zap.Uint64("snapshotHash", s.Hash()))
}
type DiscoverySnapshotStringer struct {
Version uint64
Pods []string
Upstreams []string
Tlssecrets []string
Deployments []string
}
func (ss DiscoverySnapshotStringer) String() string {
s := fmt.Sprintf("DiscoverySnapshot %v\n", ss.Version)
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(" Tlssecrets %v\n", len(ss.Tlssecrets))
for _, name := range ss.Tlssecrets {
s += fmt.Sprintf(" %v\n", name)
}
s += fmt.Sprintf(" Deployments %v\n", len(ss.Deployments))
for _, name := range ss.Deployments {
s += fmt.Sprintf(" %v\n", name)
}
return s
}
func (s DiscoverySnapshot) Stringer() DiscoverySnapshotStringer {
return DiscoverySnapshotStringer{
Version: s.Hash(),
Pods: s.Pods.NamespacesDotNames(),
Upstreams: s.Upstreams.NamespacesDotNames(),
Tlssecrets: s.Tlssecrets.NamespacesDotNames(),
Deployments: s.Deployments.NamespacesDotNames(),
}
}