forked from gardener/external-dns-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
277 lines (231 loc) · 7.59 KB
/
interface.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"context"
"fmt"
"time"
"github.com/gardener/controller-manager-library/pkg/config"
"github.com/gardener/controller-manager-library/pkg/controllermanager/controller"
"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/gardener/controller-manager-library/pkg/resources"
"github.com/gardener/controller-manager-library/pkg/utils"
"github.com/gardener/external-dns-management/pkg/dns"
dnsutils "github.com/gardener/external-dns-management/pkg/dns/utils"
"github.com/gardener/external-dns-management/pkg/server/remote/embed"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/util/flowcontrol"
)
type Config struct {
TTL int64
CacheTTL time.Duration
RescheduleDelay time.Duration
StatusCheckPeriod time.Duration
Ident string
Dryrun bool
ZoneStateCaching bool
DisableDNSNameValidation bool
Delay time.Duration
Enabled utils.StringSet
Options *FactoryOptions
Factory DNSHandlerFactory
RemoteAccessConfig *embed.RemoteAccessServerConfig
}
func NewConfigForController(c controller.Interface, factory DNSHandlerFactory) (*Config, error) {
ident, err := c.GetStringOption(OPT_IDENTIFIER)
if err != nil {
ident = "identifier-not-configured"
}
ttl, err := c.GetIntOption(OPT_TTL)
if err != nil {
ttl = 300
}
cttl, err := c.GetIntOption(OPT_CACHE_TTL)
if err != nil {
cttl = 60
}
dryrun, _ := c.GetBoolOption(OPT_DRYRUN)
delay, err := c.GetDurationOption(OPT_DNSDELAY)
if err != nil {
delay = 10 * time.Second
}
rescheduleDelay, err := c.GetDurationOption(OPT_RESCHEDULEDELAY)
if err != nil {
rescheduleDelay = 120 * time.Second
}
statuscheckperiod, err := c.GetDurationOption(OPT_LOCKSTATUSCHECKPERIOD)
if err != nil {
statuscheckperiod = 120 * time.Second
}
RemoteAccessClientID, err = c.GetStringOption(OPT_REMOTE_ACCESS_CLIENT_ID)
if err != nil {
return nil, err
}
remoteAccessConfig, err := createRemoteAccessConfig(c)
if err != nil {
return nil, err
}
disableZoneStateCaching, _ := c.GetBoolOption(OPT_DISABLE_ZONE_STATE_CACHING)
disableDNSNameValidation, _ := c.GetBoolOption(OPT_DISABLE_DNSNAME_VALIDATION)
enabled := utils.StringSet{}
types, err := c.GetStringOption(OPT_PROVIDERTYPES)
if err != nil || types == "" {
enabled.AddSet(factory.TypeCodes())
} else {
enabled.AddAllSplitted(types)
if enabled.Contains("all") {
enabled.Remove("all")
set := factory.TypeCodes()
set.Remove("mock-inmemory" /* mock.TYPE_CODE */)
enabled.AddSet(set)
}
_, del := enabled.DiffFrom(factory.TypeCodes())
if len(del) != 0 {
return nil, fmt.Errorf("unknown providers types %s", del)
}
}
osrc, _ := c.GetOptionSource(FACTORY_OPTIONS)
fopts := GetFactoryOptions(osrc)
return &Config{
Ident: ident,
TTL: int64(ttl),
CacheTTL: time.Duration(cttl) * time.Second,
RescheduleDelay: rescheduleDelay,
StatusCheckPeriod: statuscheckperiod,
Dryrun: dryrun,
ZoneStateCaching: !disableZoneStateCaching,
DisableDNSNameValidation: disableDNSNameValidation,
Delay: delay,
Enabled: enabled,
Options: fopts,
Factory: factory,
RemoteAccessConfig: remoteAccessConfig,
}, nil
}
type DNSHostedZone interface {
Key() string
Id() dns.ZoneID
Domain() string
ForwardedDomains() []string
Match(dnsname string) int
IsPrivate() bool
}
type DNSHostedZones []DNSHostedZone
func (this DNSHostedZones) EquivalentTo(infos DNSHostedZones) bool {
if len(this) != len(infos) {
return false
}
outer:
for _, i := range infos {
for _, t := range this {
if i.Key() == t.Key() && i.Domain() == t.Domain() {
continue outer
}
}
return false
}
return true
}
type DNSHandlerConfig struct {
Logger logger.LogContext
Properties utils.Properties
Config *runtime.RawExtension
DryRun bool
Context context.Context
ZoneCacheFactory ZoneCacheFactory
Options *FactoryOptions
Metrics Metrics
RateLimiter flowcontrol.RateLimiter
}
type DNSZoneState interface {
GetDNSSets() dns.DNSSets
}
const (
M_LISTZONES = "list_zones"
M_PLISTZONES = "list_zones_pages"
M_LISTRECORDS = "list_records"
M_PLISTRECORDS = "list_records_pages"
M_UPDATERECORDS = "update_records"
M_PUPDATEREORDS = "update_records_pages"
M_CREATERECORDS = "create_records"
M_DELETERECORDS = "delete_records"
M_CACHED_GETZONES = "cached_getzones"
M_CACHED_GETZONESTATE = "cached_getzonestate"
)
type Metrics interface {
AddGenericRequests(requestType string, n int)
AddZoneRequests(zoneID, requestType string, n int)
}
type Finalizers interface {
Finalizers() utils.StringSet
}
type DNSHandler interface {
ProviderType() string
GetZones() (DNSHostedZones, error)
GetZoneState(DNSHostedZone) (DNSZoneState, error)
ReportZoneStateConflict(zone DNSHostedZone, err error) bool
ExecuteRequests(logger logger.LogContext, zone DNSHostedZone, state DNSZoneState, reqs []*ChangeRequest) error
MapTargets(dnsName string, targets []Target) []Target
Release()
}
type DefaultDNSHandler struct {
providerType string
}
func NewDefaultDNSHandler(providerType string) DefaultDNSHandler {
return DefaultDNSHandler{providerType}
}
func (this *DefaultDNSHandler) ProviderType() string {
return this.providerType
}
func (this *DefaultDNSHandler) MapTargets(_ string, targets []Target) []Target {
return targets
}
////////////////////////////////////////////////////////////////////////////////
type DNSHandlerOptionSource interface {
CreateOptionSource() (local config.OptionSource, defaults *GenericFactoryOptions)
}
type DNSHandlerFactory interface {
Name() string
TypeCodes() utils.StringSet
Create(typecode string, config *DNSHandlerConfig) (DNSHandler, error)
IsResponsibleFor(object *dnsutils.DNSProviderObject) bool
SupportZoneStateCache(typecode string) (bool, error)
}
type DNSProviders map[resources.ObjectName]DNSProvider
type DNSProvider interface {
ObjectName() resources.ObjectName
Object() resources.Object
TypeCode() string
DefaultTTL() int64
GetZones() DNSHostedZones
IncludesZone(zoneID dns.ZoneID) bool
HasEquivalentZone(zoneID dns.ZoneID) bool
GetZoneState(zone DNSHostedZone) (DNSZoneState, error)
ExecuteRequests(logger logger.LogContext, zone DNSHostedZone, state DNSZoneState, requests []*ChangeRequest) error
GetDedicatedDNSAccess() DedicatedDNSAccess
Match(dns string) int
MatchZone(dns string) int
IsValid() bool
AccountHash() string
MapTargets(dnsName string, targets []Target) []Target
// ReportZoneStateConflict is used to report a conflict because of stale data.
// It returns true if zone data will be updated and a retry may resolve the conflict
ReportZoneStateConflict(zone DNSHostedZone, err error) bool
}
type DoneHandler interface {
SetInvalid(err error)
Failed(err error)
Throttled()
Succeeded()
}
type ProviderEventListener interface {
ProviderUpdatedEvent(logger logger.LogContext, name resources.ObjectName, annotations map[string]string, handler LightDNSHandler)
ProviderRemovedEvent(logger logger.LogContext, name resources.ObjectName)
}
type LightDNSHandler interface {
ProviderType() string
GetZones() (DNSHostedZones, error)
GetZoneState(DNSHostedZone) (DNSZoneState, error)
ExecuteRequests(logger logger.LogContext, zone DNSHostedZone, state DNSZoneState, reqs []*ChangeRequest) error
}