generated from dogmatiq/template-go
/
discover.go
142 lines (129 loc) 路 3.91 KB
/
discover.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
package crd
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
// ConditionTypeDiscoverable is a condition that indicates whether or not the
// service instance is discoverable via the DNS system.
const ConditionTypeDiscoverable = "Discoverable"
// Discovered records an event indicating that the service instance was
// discovered via DNS-SD.
func Discovered(m manager.Manager, res *DNSSDServiceInstance) {
m.
GetEventRecorderFor("proclaim-dnssd").
Event(
res,
"Normal",
"Discovered",
"instance discovered",
)
}
// DiscoveredCondition returns a condition indicating that the DNS-SD
// discovery results match the advertised DNS records.
func DiscoveredCondition() metav1.Condition {
return metav1.Condition{
Type: ConditionTypeDiscoverable,
Status: metav1.ConditionTrue,
Reason: "Discovered",
Message: "DNS-SD browse and lookup results match the advertised DNS records",
}
}
// NegativeBrowseResult records an event indicating that the service instance
// was not discoverable via DNS-SD.
func NegativeBrowseResult(m manager.Manager, res *DNSSDServiceInstance) {
m.
GetEventRecorderFor("proclaim-dnssd").
Event(
res,
"Warning",
"NegativeBrowseResult",
"instance not discovered",
)
}
// NegativeBrowseResultCondition returns a condition indicating that the
// instance was not present in the result of a DNS-SD browse operation.
func NegativeBrowseResultCondition() metav1.Condition {
return metav1.Condition{
Type: ConditionTypeDiscoverable,
Status: metav1.ConditionFalse,
Reason: "NegativeBrowseResult",
Message: "DNS-SD browse could not find this instance",
}
}
// NegativeLookupResult records an event indicating that the service instance
// was not discoverable via DNS-SD.
func NegativeLookupResult(m manager.Manager, res *DNSSDServiceInstance) {
m.
GetEventRecorderFor("proclaim-dnssd").
Event(
res,
"Warning",
"NegativeLookupResult",
"instance not discovered",
)
}
// NegativeLookupResultCondition returns a condition indicating that the
// instance could not be found by a DNS-SD lookup operation.
func NegativeLookupResultCondition() metav1.Condition {
return metav1.Condition{
Type: ConditionTypeDiscoverable,
Status: metav1.ConditionFalse,
Reason: "NegativeLookupResult",
Message: "DNS-SD lookup could not find this instance",
}
}
// LookupResultOutOfSync records an event indicating that the service instance
// was discovered via DNS-SD, but the result did not match the advertised DNS
// records.
func LookupResultOutOfSync(m manager.Manager, res *DNSSDServiceInstance, diff string) {
m.
GetEventRecorderFor("proclaim-dnssd").
Event(
res,
"Warning",
"LookupResultOutOfSync",
"instance discovered with incorrect (potentially cached) values: "+diff,
)
}
// LookupResultOutOfSyncCondition returns a condition indicating that the
// instance was found by a DNS-SD lookup operation, but the result did not match
// the advertised DNS records.
func LookupResultOutOfSyncCondition(diff string) metav1.Condition {
return metav1.Condition{
Type: ConditionTypeDiscoverable,
Status: metav1.ConditionFalse,
Reason: "LookupResultOutOfSync",
Message: fmt.Sprintf(
"DNS-SD lookup result does not match the advertised DNS records: %s",
diff,
),
}
}
// DiscoveryError records an event indicating that an error occurred while
// performing DNS-SD discovery.
func DiscoveryError(
m manager.Manager,
res *DNSSDServiceInstance,
err error,
) {
m.
GetEventRecorderFor("proclaim-dnssd").
Eventf(
res,
"Warning",
"DiscoveryError",
"%s",
err.Error(),
)
}
// DiscoveryErrorCondition returns a condition indicating that the DNS-SD
// discovery failed with the given error.
func DiscoveryErrorCondition(err error) metav1.Condition {
return metav1.Condition{
Type: ConditionTypeDiscoverable,
Status: metav1.ConditionFalse,
Reason: "Error",
Message: err.Error(),
}
}