Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fee5e6a

Browse files
committedMar 10, 2025
coredns(plugin): Small fixes
* Update example Corefie and remove file directive * Move the db-generator under plugin so the demo db can more easily be built and embedded in the coredns image. * Add make target to generate demo db `make coredns-generate-demo-geo-db`. * Fix imports and code formatting. Signed-off-by: Michael Nairn <[email protected]>
1 parent e760b92 commit fee5e6a

12 files changed

+46
-23
lines changed
 

‎Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ lint: golangci-lint ## Run golangci-lint against code.
155155
.PHONY: imports
156156
imports: openshift-goimports ## Run openshift goimports against code.
157157
$(OPENSHIFT_GOIMPORTS) -m github.com/kuadrant/dns-operator -i github.com/kuadrant
158+
$(OPENSHIFT_GOIMPORTS) -p coredns/plugin -m github.com/kuadrant/coredns-kuadrant -i github.com/kuadrant
158159

159160
.PHONY: test
160161
test: test-unit test-integration ## Run tests.

‎coredns/examples/Corefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ k.example.com {
44
log
55
geoip GeoLite2-City-demo.mmdb
66
metadata
7-
kuadrant {
8-
kubeconfig /home/mnairn/.kube/config kind-kuadrant-dns-local-1
9-
}
10-
}
11-
f.example.com {
12-
file db.f.example.com
7+
kuadrant
138
}
149
. {
1510
forward . /etc/resolv.conf

‎coredns/examples/db.f.example.com

-9
This file was deleted.

‎coredns/plugin/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM alpine:3.21.0
22
COPY coredns /
3-
COPY GeoLite2-City-demo.mmdb /
3+
COPY geoip/GeoLite2-City-demo.mmdb /
44
EXPOSE 53 53/udp
55
ENTRYPOINT ["/coredns"]
-1.72 KB
Binary file not shown.

‎coredns/examples/db-generator.go ‎coredns/plugin/geoip/db-generator.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package main
22

3-
/*
43
import (
54
"log"
65
"net"
@@ -110,4 +109,3 @@ func createCityDB(dbName, dbType string) {
110109
log.Fatal(err)
111110
}
112111
}
113-
*/

‎coredns/plugin/geoip/go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module geoip
2+
3+
go 1.23.4
4+
5+
require github.com/maxmind/mmdbwriter v1.0.0
6+
7+
require (
8+
github.com/oschwald/maxminddb-golang v1.13.1 // indirect
9+
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
10+
golang.org/x/sys v0.31.0 // indirect
11+
)

‎coredns/plugin/geoip/go.sum

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/maxmind/mmdbwriter v1.0.0 h1:bieL4P6yaYaHvbtLSwnKtEvScUKKD6jcKaLiTM3WSMw=
4+
github.com/maxmind/mmdbwriter v1.0.0/go.mod h1:noBMCUtyN5PUQ4H8ikkOvGSHhzhLok51fON2hcrpKj8=
5+
github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
6+
github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
7+
github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE=
8+
github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
12+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
13+
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d h1:ggxwEf5eu0l8v+87VhX1czFh8zJul3hK16Gmruxn7hw=
14+
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc=
15+
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
16+
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
17+
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
18+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
20+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
21+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
22+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

‎coredns/plugin/k8s.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
"k8s.io/client-go/tools/cache"
1818
"k8s.io/client-go/tools/clientcmd"
1919

20-
"github.com/kuadrant/coredns-kuadrant/dnsop"
2120
"github.com/kuadrant/dns-operator/api/v1alpha1"
21+
22+
"github.com/kuadrant/coredns-kuadrant/dnsop"
2223
)
2324

2425
const (

‎coredns/plugin/zone.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"strconv"
77
"strings"
88

9-
"sigs.k8s.io/external-dns/endpoint"
10-
119
"github.com/coredns/coredns/plugin/file"
1210
"github.com/coredns/coredns/plugin/metadata"
1311
"github.com/coredns/coredns/plugin/pkg/dnsutil"
1412
"github.com/coredns/coredns/request"
1513
"github.com/miekg/dns"
1614

15+
"sigs.k8s.io/external-dns/endpoint"
16+
1717
"github.com/kuadrant/dns-operator/api/v1alpha1"
1818
)
1919

@@ -112,7 +112,7 @@ func (z *Zone) InsertEndpoint(ep *endpoint.Endpoint) error {
112112
rrs = append(rrs, cname)
113113
}
114114

115-
for i, _ := range rrs {
115+
for i := range rrs {
116116
rrd := rrData{}
117117
if wProp, wExists := ep.GetProviderSpecificProperty(v1alpha1.ProviderSpecificWeight); wExists {
118118
weight, err := strconv.ParseInt(wProp, 10, 64)

‎make/coredns.mk

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ coredns-run: ## Run coredns from your host.
2222
cd ${COREDNS_PLUGIN_DIR} && go run --race ./cmd/coredns.go -dns.port ${DNS_PORT}
2323

2424
.PHONY: coredns-docker-build
25-
coredns-docker-build: coredns-build ## Build docker image.
25+
coredns-docker-build: coredns-build coredns-generate-demo-geo-db ## Build docker image.
2626
cd ${COREDNS_PLUGIN_DIR} && $(CONTAINER_TOOL) build . -t ${COREDNS_IMG}
2727

2828
.PHONY: coredns-docker-push
@@ -33,3 +33,7 @@ coredns-docker-push: ## Push docker image.
3333
coredns-docker-run: DNS_PORT=1053
3434
coredns-docker-run: coredns-docker-build ## Build docker image and run coredns in a container.
3535
cd ${COREDNS_PLUGIN_DIR} && $(CONTAINER_TOOL) run --rm -it -p ${DNS_PORT}:53/udp ${COREDNS_IMG}
36+
37+
.PHONY: coredns-generate-demo-geo-db
38+
coredns-generate-demo-geo-db: ## Generate demo geo db embedded in coredns image.
39+
cd ${COREDNS_PLUGIN_DIR}/geoip && go run db-generator.go

0 commit comments

Comments
 (0)
Please sign in to comment.