1
1
package common
2
2
3
3
import (
4
+ "fmt"
5
+ "io"
4
6
"time"
5
7
6
8
"k8s.io/apimachinery/pkg/util/rand"
9
+ externaldnsendpoint "sigs.k8s.io/external-dns/endpoint"
7
10
)
8
11
9
12
// RandomizeValidationDuration randomizes duration for a given variance with a min value of 1 sec
@@ -27,3 +30,34 @@ func RandomizeDuration(variance, duration float64) time.Duration {
27
30
int64 (lowerLimit ),
28
31
int64 (upperLimit )))
29
32
}
33
+
34
+ func WriteEndpoints (s io.Writer , endpoints []* externaldnsendpoint.Endpoint , title string ) {
35
+ fmt .Fprintf (s , "\n ====== %s ======\n " , title )
36
+ for _ , ep := range endpoints {
37
+ fmt .Fprintf (s , " endpoint: %v > %+v with labels: %+v and flags: %+v\n " , ep .DNSName , ep .Targets , ep .Labels , ep .ProviderSpecific )
38
+ }
39
+ fmt .Fprintf (s , "====== %s ======\n \n " , title )
40
+ }
41
+
42
+ func RemoveLabelFromEndpoint (label string , endpoint * externaldnsendpoint.Endpoint ) * externaldnsendpoint.Endpoint {
43
+ if endpoint .Labels == nil {
44
+ return endpoint
45
+ }
46
+
47
+ delete (endpoint .Labels , label )
48
+ return endpoint
49
+ }
50
+
51
+ func RemoveLabelFromEndpoints (label string , endpoints []* externaldnsendpoint.Endpoint ) []* externaldnsendpoint.Endpoint {
52
+ for _ , e := range endpoints {
53
+ RemoveLabelFromEndpoint (label , e )
54
+ }
55
+ return endpoints
56
+ }
57
+ func RemoveLabelsFromEndpoints (labels []string , endpoints []* externaldnsendpoint.Endpoint ) []* externaldnsendpoint.Endpoint {
58
+ for _ , l := range labels {
59
+ RemoveLabelFromEndpoints (l , endpoints )
60
+ }
61
+
62
+ return endpoints
63
+ }
0 commit comments