Skip to content

Commit 3c5ee4c

Browse files
Restored functionality with new build system (#22)
* Restored previous functionality * Adding modified files
1 parent e6142b3 commit 3c5ee4c

File tree

5 files changed

+95
-1667
lines changed

5 files changed

+95
-1667
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ provider: webhook
5959

6060
extraArgs:
6161
webhook-provider-url: http://localhost:8888
62-
txt-prefix: reg-
62+
txt-prefix: "reg-%{record_type}-"
6363

6464
sidecars:
6565
- name: hetzner-webhook
@@ -136,7 +136,7 @@ provider:
136136
timeoutSeconds: 5
137137

138138
extraArgs:
139-
- --txt-prefix=reg-
139+
- "--txt-prefix=reg-%{record_type}-"
140140
```
141141
142142
And then:

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/google/go-licenses v1.6.0
1212
github.com/sirupsen/logrus v1.9.3
1313
github.com/stretchr/testify v1.9.0
14+
gotest.tools v2.2.0+incompatible
1415
gotest.tools/gotestsum v1.10.0
1516
)
1617

@@ -47,6 +48,7 @@ require (
4748
github.com/modern-go/reflect2 v1.0.2 // indirect
4849
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4950
github.com/otiai10/copy v1.14.0 // indirect
51+
github.com/pkg/errors v0.9.1 // indirect
5052
github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect
5153
github.com/rivo/uniseg v0.4.4 // indirect
5254
github.com/sagikazarmark/locafero v0.3.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
12431243
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12441244
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12451245
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1246+
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
1247+
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
12461248
gotest.tools/gotestsum v1.10.0 h1:lVO4uQJoxdsJb7jgmr1fg8QW7zGQ/tuqvsq5fHKyoHQ=
12471249
gotest.tools/gotestsum v1.10.0/go.mod h1:6JHCiN6TEjA7Kaz23q1bH0e2Dc3YJjDUZ0DmctFZf+w=
12481250
gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo=

internal/hetzner/provider.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (p *HetznerProvider) fetchZones(ctx context.Context) ([]hdns.Zone, error) {
276276
}
277277

278278
// ensureZoneIDMappingPresent prepares the zoneIDNameMapper, that associates
279-
// each ZoneID with the zone name.
279+
// each ZoneID woth the zone name.
280280
func (p *HetznerProvider) ensureZoneIDMappingPresent(zones []hdns.Zone) {
281281
zoneIDNameMapper := provider.ZoneIDName{}
282282
for _, z := range zones {
@@ -330,18 +330,13 @@ func makeEndpointName(domain, entryName, epType string) string {
330330
// - A-Records should respect ignored networks and should only contain IPv4
331331
// entries.
332332
func (p HetznerProvider) makeEndpointTarget(domain, entryTarget, recordType string) (string, bool) {
333-
if recordType != "CNAME" {
333+
if domain == "" {
334334
return entryTarget, true
335335
}
336336

337-
adjustedTarget := entryTarget
338-
if !strings.HasSuffix(entryTarget, ".") {
339-
adjustedTarget = entryTarget + "."
340-
}
341-
342-
if strings.HasSuffix(adjustedTarget, "."+domain+".") {
343-
adjustedTarget = strings.TrimSuffix(adjustedTarget, "."+domain+".")
344-
}
337+
// Trim the trailing dot
338+
adjustedTarget := strings.TrimSuffix(entryTarget, ".")
339+
adjustedTarget = strings.TrimSuffix(adjustedTarget, "."+domain)
345340

346341
return adjustedTarget, true
347342
}
@@ -480,7 +475,7 @@ func processCreateActions(
480475
continue
481476
}
482477

483-
records := recordsByZoneID[zoneID]
478+
records := recordsByZoneID[zoneName]
484479

485480
for _, ep := range endpoints {
486481
// Warn if there are existing records since we expect to create only new records.
@@ -500,6 +495,9 @@ func processCreateActions(
500495
}
501496

502497
for _, target := range ep.Targets {
498+
if ep.RecordType == "CNAME" && !strings.HasSuffix(target, ".") {
499+
target += "."
500+
}
503501
log.WithFields(log.Fields{
504502
"zoneName": zoneName,
505503
"dnsName": ep.DNSName,
@@ -585,6 +583,9 @@ func processUpdateActions(
585583

586584
// Generate create and delete actions based on existence of a record for each target.
587585
for _, target := range ep.Targets {
586+
if ep.RecordType == "CNAME" && !strings.HasSuffix(target, ".") {
587+
target += "."
588+
}
588589
if record, ok := matchingRecordsByTarget[target]; ok {
589590
log.WithFields(log.Fields{
590591
"zoneName": zoneName,

0 commit comments

Comments
 (0)