Skip to content

Commit 12d969e

Browse files
author
dougbw
committed
2 parents 530e4e5 + 603a01b commit 12d969e

File tree

14 files changed

+157
-90
lines changed

14 files changed

+157
-90
lines changed

Corefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
username {$OMADA_USERNAME}
77
password {$OMADA_PASSWORD}
88
refresh_minutes 1
9+
ignore_startup_errors {$OMADA_IGNORE_STARTUP_ERRORS}
910
}
1011
forward . {$UPSTREAM_DNS}
1112
}

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
4242
COPY --from=builder /coredns/coredns /coredns
4343
COPY Corefile /Corefile
4444
EXPOSE 53 53/udp
45+
ENV OMADA_IGNORE_STARTUP_ERRORS=FALSE
4546
ENTRYPOINT ["/coredns"]

config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type config struct {
2020
resolve_devices bool // resolve 'device' addresses
2121
resolve_dhcp_reservations bool // resolve static 'dhcp reservations'
2222
stale_record_duration time.Duration // duration to keep serving stale records for clients no longer present in the controller)
23+
ignore_startup_errors bool // ignore any errors during the initial zone refresh
2324
}
2425

2526
func parse(c *caddy.Controller) (config config, err error) {
@@ -31,6 +32,7 @@ func parse(c *caddy.Controller) (config config, err error) {
3132
config.resolve_devices = true
3233
config.resolve_dhcp_reservations = true
3334
config.stale_record_duration, _ = time.ParseDuration("10m")
35+
config.ignore_startup_errors = false
3436

3537
for c.Next() {
3638

@@ -115,6 +117,15 @@ func parse(c *caddy.Controller) (config config, err error) {
115117
return config, c.ArgErr()
116118
}
117119

120+
case "ignore_startup_errors":
121+
if !c.NextArg() {
122+
return config, c.ArgErr()
123+
}
124+
config.ignore_startup_errors, err = strconv.ParseBool(c.Val())
125+
if err != nil {
126+
return config, c.ArgErr()
127+
}
128+
118129
default:
119130
return config, c.Errf("unknown property: %q", c.Val())
120131
}

config_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ func TestConfig(t *testing.T) {
114114
site .*
115115
stale_record_duration error
116116
}`, true},
117+
118+
// invalid value: ignore_startup_errors
119+
{`omada {
120+
controller_url https://10.0.0.1
121+
username test
122+
password test
123+
site .*
124+
ignore_startup_errors zzz
125+
}`, true},
117126
}
118127

119128
for i, test := range tests {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. {
2+
health :8080
3+
omada {
4+
controller_url https://10.0.0.2
5+
site Home
6+
username coredns-omada
7+
password coredns-omada
8+
refresh_minutes 1
9+
ignore_startup_errors true
10+
}
11+
forward . 10.0.0.1
12+
}

docs/configuration.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ Example corefiles are located [here](../corefile-examples)
1515
| password || string | Omada controller password |
1616
| refresh_minutes || int | How often to refresh the zones (default 1 minute) |
1717
| refresh_login_hours || int | How often to refresh the login token (default 24 hours) |
18-
| resolve_clients || bool | Whether to resolve client (default true) addresses |
19-
| resolve_devices || bool | Whether to resolve device (default true)addresses |
20-
| resolve_dhcp_reservations || bool | Whether to resolve device (default true)addresses |
18+
| resolve_clients || bool | Whether to resolve client addresses (default true) |
19+
| resolve_devices || bool | Whether to resolve device addresses (default true) |
20+
| resolve_dhcp_reservations || bool | Whether to resolve device addresses (default true) |
2121
| stale_record_duration || duration | How long to keep serving stale records for clients/devices which are no longer present in the Omada controller. Specified in Go time [duration](https://pkg.go.dev/time#ParseDuration) format |
22+
| ignore_startup_errors || bool | ignore connection/configuration errors to the omada controller on startup. Set this to true if you want coredns to startup even if unable to connect to omada (default false) |
23+
2224

2325
## Credentials
2426

docs/getting-started.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
CoreDNS plugins need to be compiled into CoreDNS, you can follow the [build](build.md) instructions to build the binaries or use the provided docker images.
44

55
1. Create Omada user
6-
2. Run CoreDNS with omada plugin
7-
3. Setup network
6+
2. Setup network
7+
3. Run CoreDNS with omada plugin
88

99
## 1 - Create Omada user
1010

@@ -25,7 +25,7 @@ CoreDNS plugins need to be compiled into CoreDNS, you can follow the [build](bui
2525

2626
## 3 - Run CoreDNS with omada plugin
2727

28-
This guide provides three alternatives on how to run CoreDNS:
28+
This guide provides three options on how to run CoreDNS:
2929

3030
- [CoreDNS binary](#coredns-binary)
3131
- [Docker container](#docker)
@@ -63,6 +63,7 @@ docker run \
6363
--env OMADA_SITE="<OMADA_SITE>" \
6464
--env OMADA_USERNAME="<OMADA_USERNAME>" \
6565
--env OMADA_PASSWORD="<OMADA_PASSWORD>" \
66+
--env OMADA_IGNORE_STARTUP_ERRORS="false" \
6667
--env OMADA_DISABLE_HTTPS_VERIFICATION="false" \
6768
--env UPSTREAM_DNS="8.8.8.8" \
6869
ghcr.io/dougbw/coredns_omada:latest
@@ -80,7 +81,7 @@ ghcr.io/dougbw/coredns_omada:latest
8081
```
8182

8283
### Kubernetes
83-
Some example manifest files to get started are in the [k8s](k8s) directory. Make sure you replace the following values:
84+
Example manifest files to get started are in the [k8s](k8s) directory. Make sure you replace the following values:
8485

8586
* configmap.yaml
8687
* `omada-url`

omada.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ type Omada struct {
2727
func NewOmada(ctx context.Context, url string, u string, p string) (*Omada, error) {
2828

2929
omada := omada.New(url)
30-
err := omada.GetControllerInfo()
31-
if err != nil {
32-
return nil, plugin.Error("omada", err)
33-
}
3430

3531
zones := make(map[string]*file.Zone)
3632
records := make(map[string]DnsRecords)

ptr.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ func getPtrZoneFromIp(ip string) string {
1717
return fmt.Sprintf("%s.%s", reverse, ptrZone)
1818
}
1919

20-
// takes PTR record and returns parent ptr zone:
21-
// 1.0.0.10.in-addr.arpa -> 0.0.10.in-addr.arpa
22-
func getPtrParent(ptr string) string {
23-
parts := strings.Split(ptr, ".")
24-
zone := strings.Join(parts[1:], ".")
25-
return zone
26-
}
27-
2820
func reverseSlice(s []string) []string {
2921
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
3022
s[i], s[j] = s[j], s[i]

ptr_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,3 @@ func TestGetPtrZoneFromIp(t *testing.T) {
2828
}
2929

3030
}
31-
32-
func TestGetPtrParent(t *testing.T) {
33-
34-
tests := []struct {
35-
ip string
36-
expected string
37-
}{
38-
{
39-
"1.0.0.10.in-addr.arpa",
40-
"0.0.10.in-addr.arpa",
41-
},
42-
{
43-
"1.0.0.10.in-addr.arpa",
44-
"0.0.10.in-addr.arpa",
45-
},
46-
}
47-
48-
for _, test := range tests {
49-
result := getPtrParent(test.ip)
50-
assert.Equal(t, test.expected, result)
51-
}
52-
53-
}

0 commit comments

Comments
 (0)