Skip to content

Commit 1efdf41

Browse files
authored
feat(pihole): add optional support for v6 (#5226)
* Pi hole V6 impl * Code Review Part One * Fix Go Lint * Regenerate Flags file * Increase code coverage 1/2 * Increase code coverage 2/2 * Fix merge conflict => Provider init move from main.go to execute.go
1 parent f9725a1 commit 1efdf41

File tree

11 files changed

+1826
-8
lines changed

11 files changed

+1826
-8
lines changed

controller/execute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func Execute() {
301301
TLSInsecureSkipVerify: cfg.PiholeTLSInsecureSkipVerify,
302302
DomainFilter: domainFilter,
303303
DryRun: cfg.DryRun,
304+
APIVersion: cfg.PiholeApiVersion,
304305
},
305306
)
306307
case "ibmcloud":

docs/flags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
| `--pihole-server=""` | When using the Pihole provider, the base URL of the Pihole web server (required when --provider=pihole) |
154154
| `--pihole-password=""` | When using the Pihole provider, the password to the server if it is protected |
155155
| `--[no-]pihole-tls-skip-verify` | When using the Pihole provider, disable verification of any TLS certificates |
156+
| `--pihole-api-version="5"` | When using the Pihole provider, specify the pihole API version (default: 5, options: 5, 6) |
156157
| `--plural-cluster=""` | When using the plural provider, specify the cluster name you're running with |
157158
| `--plural-provider=""` | When using the plural provider, specify the provider name you're running with |
158159
| `--policy=sync` | Modify how DNS records are synchronized between sources and providers (default: sync, options: sync, upsert-only, create-only) |

docs/tutorials/pihole.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ There is a pseudo-API exposed that ExternalDNS is able to use to manage these re
66

77
__NOTE:__ Your Pi-hole must be running [version 5.9 or newer](https://pi-hole.net/blog/2022/02/12/pi-hole-ftl-v5-14-web-v5-11-and-core-v5-9-released).
88

9+
__NOTE:__ Provider for Pi-hole version prior to 6.0 is now deprecated and will be removed in future release.
10+
11+
__NOTE:__ Since Pi-hole version 6, you should use the flag *--pihole-api-version=6*
12+
913
## Deploy ExternalDNS
1014

1115
You can skip to the [manifest](#externaldns-manifest) if authentication is disabled on your Pi-hole instance or you don't want to use secrets.
1216

1317
If your Pi-hole server's admin dashboard is protected by a password, you'll likely want to create a secret first containing its value.
14-
This is optional since you _do_ retain the option to pass it as a flag with `--pihole-password`.
18+
This is optional since you *do* retain the option to pass it as a flag with `--pihole-password`.
1519

1620
You can create the secret with:
1721

@@ -98,6 +102,8 @@ spec:
98102
# the policy to upsert-only so they do not get deleted.
99103
- --policy=upsert-only
100104
- --provider=pihole
105+
# Switch to pihole V6 API
106+
- --pihole-api-version=6
101107
# Change this to the actual address of your Pi-hole web server
102108
- --pihole-server=http://pihole-web.pihole.svc.cluster.local
103109
securityContext:
@@ -109,6 +115,7 @@ spec:
109115
- `--pihole-server (env: EXTERNAL_DNS_PIHOLE_SERVER)` - The address of the Pi-hole web server
110116
- `--pihole-password (env: EXTERNAL_DNS_PIHOLE_PASSWORD)` - The password to the Pi-hole web server (if enabled)
111117
- `--pihole-tls-skip-verify (env: EXTERNAL_DNS_PIHOLE_TLS_SKIP_VERIFY)` - Skip verification of any TLS certificates served by the Pi-hole web server.
118+
- `--pihole-api-version (env: EXTERNAL_DNS_PIHOLE_API_VERSION)` - Specify the pihole API version (default is 5. Eligible values are 5 or 6).
112119

113120
## Verify ExternalDNS Works
114121

@@ -181,7 +188,7 @@ spec:
181188

182189
You can then query your Pi-hole to see if the record was created.
183190

184-
_Change `@192.168.100.2` to the actual address of your DNS server_
191+
Change *@192.168.100.2* to the actual address of your DNS server
185192

186193
```bash
187194
$ dig +short @192.168.100.2 nginx.external-dns-test.homelab.com

pkg/apis/externaldns/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ type Config struct {
203203
PiholeServer string
204204
PiholePassword string `secure:"yes"`
205205
PiholeTLSInsecureSkipVerify bool
206+
PiholeApiVersion string
206207
PluralCluster string
207208
PluralProvider string
208209
WebhookProviderURL string
@@ -365,6 +366,7 @@ var defaultConfig = &Config{
365366
PiholeServer: "",
366367
PiholePassword: "",
367368
PiholeTLSInsecureSkipVerify: false,
369+
PiholeApiVersion: "5",
368370
PluralCluster: "",
369371
PluralProvider: "",
370372
WebhookProviderURL: "http://localhost:8888",
@@ -600,6 +602,7 @@ func App(cfg *Config) *kingpin.Application {
600602
app.Flag("pihole-server", "When using the Pihole provider, the base URL of the Pihole web server (required when --provider=pihole)").Default(defaultConfig.PiholeServer).StringVar(&cfg.PiholeServer)
601603
app.Flag("pihole-password", "When using the Pihole provider, the password to the server if it is protected").Default(defaultConfig.PiholePassword).StringVar(&cfg.PiholePassword)
602604
app.Flag("pihole-tls-skip-verify", "When using the Pihole provider, disable verification of any TLS certificates").BoolVar(&cfg.PiholeTLSInsecureSkipVerify)
605+
app.Flag("pihole-api-version", "When using the Pihole provider, specify the pihole API version (default: 5, options: 5, 6)").Default(defaultConfig.PiholeApiVersion).StringVar(&cfg.PiholeApiVersion)
603606

604607
// Flags related to the Plural provider
605608
app.Flag("plural-cluster", "When using the plural provider, specify the cluster name you're running with").Default(defaultConfig.PluralCluster).StringVar(&cfg.PluralCluster)

pkg/apis/externaldns/types_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var (
128128
IBMCloudConfigFile: "/etc/kubernetes/ibmcloud.json",
129129
TencentCloudConfigFile: "/etc/kubernetes/tencent-cloud.json",
130130
TencentCloudZoneType: "",
131+
PiholeApiVersion: "5",
131132
WebhookProviderURL: "http://localhost:8888",
132133
WebhookProviderReadTimeout: 5 * time.Second,
133134
WebhookProviderWriteTimeout: 10 * time.Second,
@@ -242,6 +243,7 @@ var (
242243
IBMCloudConfigFile: "ibmcloud.json",
243244
TencentCloudConfigFile: "tencent-cloud.json",
244245
TencentCloudZoneType: "private",
246+
PiholeApiVersion: "6",
245247
WebhookProviderURL: "http://localhost:8888",
246248
WebhookProviderReadTimeout: 5 * time.Second,
247249
WebhookProviderWriteTimeout: 10 * time.Second,
@@ -352,6 +354,7 @@ func TestParseFlags(t *testing.T) {
352354
"--aws-sd-create-tag=key1=value1",
353355
"--aws-sd-create-tag=key2=value2",
354356
"--no-aws-evaluate-target-health",
357+
"--pihole-api-version=6",
355358
"--policy=upsert-only",
356359
"--registry=noop",
357360
"--txt-owner-id=owner-1",
@@ -474,6 +477,7 @@ func TestParseFlags(t *testing.T) {
474477
"EXTERNAL_DNS_AWS_SD_SERVICE_CLEANUP": "true",
475478
"EXTERNAL_DNS_AWS_SD_CREATE_TAG": "key1=value1\nkey2=value2",
476479
"EXTERNAL_DNS_DYNAMODB_TABLE": "custom-table",
480+
"EXTERNAL_DNS_PIHOLE_API_VERSION": "6",
477481
"EXTERNAL_DNS_POLICY": "upsert-only",
478482
"EXTERNAL_DNS_REGISTRY": "noop",
479483
"EXTERNAL_DNS_TXT_OWNER_ID": "owner-1",

provider/pihole/client.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ func newPiholeClient(cfg PiholeConfig) (piholeAPI, error) {
6060
}
6161

6262
// Setup a persistent cookiejar for storing PHP session information
63-
jar, err := cookiejar.New(&cookiejar.Options{})
64-
if err != nil {
65-
return nil, err
66-
}
63+
// This call will never return an error
64+
jar, _ := cookiejar.New(&cookiejar.Options{})
6765
// Setup an HTTP client using the cookiejar
6866
httpClient := &http.Client{
6967
Jar: jar,

0 commit comments

Comments
 (0)