-
Notifications
You must be signed in to change notification settings - Fork 67
/
utils_entry.go
162 lines (131 loc) · 3.67 KB
/
utils_entry.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"reflect"
"time"
"github.com/gardener/controller-manager-library/pkg/resources"
"github.com/gardener/external-dns-management/pkg/dns"
api "github.com/gardener/external-dns-management/pkg/apis/dns/v1alpha1"
)
var _ DNSSpecification = (*DNSEntryObject)(nil)
var DNSEntryType = (*api.DNSEntry)(nil)
type DNSEntryObject struct {
resources.Object
}
func (this *DNSEntryObject) DNSEntry() *api.DNSEntry {
return this.Data().(*api.DNSEntry)
}
func DNSEntry(o resources.Object) *DNSEntryObject {
if o.IsA(DNSEntryType) {
return &DNSEntryObject{o}
}
return nil
}
func (this *DNSEntryObject) Spec() *api.DNSEntrySpec {
return &this.DNSEntry().Spec
}
func (this *DNSEntryObject) StatusField() interface{} {
return this.Status()
}
func (this *DNSEntryObject) Status() *api.DNSEntryStatus {
return &this.DNSEntry().Status
}
func (this *DNSEntryObject) BaseStatus() *api.DNSBaseStatus {
return &this.DNSEntry().Status.DNSBaseStatus
}
func GetDNSName(entry *api.DNSEntry) string {
return dns.NormalizeHostname(entry.Spec.DNSName)
}
func (this *DNSEntryObject) GetDNSName() string {
return GetDNSName(this.DNSEntry())
}
func (this *DNSEntryObject) GetSetIdentifier() string {
if policy := this.DNSEntry().Spec.RoutingPolicy; policy != nil {
return policy.SetIdentifier
}
return ""
}
func (this *DNSEntryObject) GetTargets() []string {
return this.DNSEntry().Spec.Targets
}
func (this *DNSEntryObject) GetText() []string {
return this.DNSEntry().Spec.Text
}
func (this *DNSEntryObject) GetOwnerId() *string {
return this.DNSEntry().Spec.OwnerId
}
func (this *DNSEntryObject) GetTTL() *int64 {
return this.DNSEntry().Spec.TTL
}
func (this *DNSEntryObject) GetCNameLookupInterval() *int64 {
return this.DNSEntry().Spec.CNameLookupInterval
}
func (this *DNSEntryObject) GetReference() *api.EntryReference {
return this.DNSEntry().Spec.Reference
}
func (this *DNSEntryObject) GetRoutingPolicy() *dns.RoutingPolicy {
if policy := this.DNSEntry().Spec.RoutingPolicy; policy != nil {
return &dns.RoutingPolicy{
Type: policy.Type,
Parameters: policy.Parameters,
}
}
return nil
}
func (this *DNSEntryObject) RefreshTime() time.Time {
return time.Time{}
}
func (this *DNSEntryObject) ValidateSpecial() error {
return nil
}
func (this *DNSEntryObject) AcknowledgeTargets(targets []string) bool {
s := this.Status()
if !reflect.DeepEqual(s.Targets, targets) {
s.Targets = targets
return true
}
return false
}
func (this *DNSEntryObject) AcknowledgeRoutingPolicy(policy *dns.RoutingPolicy) bool {
s := this.Status()
if s.RoutingPolicy == nil && policy == nil {
return false
}
if policy == nil {
s.RoutingPolicy = nil
return true
}
statusPolicy := &api.RoutingPolicy{
Type: policy.Type,
SetIdentifier: this.GetSetIdentifier(),
Parameters: policy.Parameters,
}
if !reflect.DeepEqual(s.RoutingPolicy, statusPolicy) {
s.RoutingPolicy = statusPolicy
return true
}
return false
}
func (this *DNSEntryObject) GetTargetSpec(p TargetProvider) TargetSpec {
return BaseTargetSpec(this, p)
}
func DNSSetName(entry *api.DNSEntry) dns.DNSSetName {
setIdentifier := ""
if policy := entry.Spec.RoutingPolicy; policy != nil {
setIdentifier = policy.SetIdentifier
}
return dns.DNSSetName{
DNSName: GetDNSName(entry),
SetIdentifier: setIdentifier,
}
}
func (this *DNSEntryObject) DNSSetName() dns.DNSSetName {
return DNSSetName(this.DNSEntry())
}
func DNSSetNameMatcher(name dns.DNSSetName) resources.ObjectMatcher {
return func(o resources.Object) bool {
return DNSEntry(o).DNSSetName() == name
}
}