Skip to content

Commit

Permalink
Use the External DNS webhook server implementation
Browse files Browse the repository at this point in the history
This enables us to drop our own server implementation.
  • Loading branch information
hatrx committed Sep 24, 2024
1 parent b761848 commit d4b95aa
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 190 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The application arguments are as follows:
- `tidydns-endpoint` Tidy DNS server addr
- `zone-update-interval` The time-duration between updating the zone information
- `log-level` Application logging level (debug, info, warn, error)
- `read-timeout` Read timeout in duration format (default: 5s)
- `write-timeout` Write timeout in duration format (default: 10s)

This application is strictly meant to run in a container as a sidecar to
External-DNS inside a Kubernetes environment. Refer to the External-DNS
Expand Down
12 changes: 4 additions & 8 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/sdk/metric"
"sigs.k8s.io/external-dns/provider/webhook/api"
)

func main() {
tidyEndpoint := flag.String("tidydns-endpoint", "", "DNS server address")
logLevel := flag.String("log-level", "", "logging level (debug, info, warn, err)")
readTimeout := flag.Duration("read-timeout", (5 * time.Second), "Read timeout in duration format (default: 5s)")
writeTimeout := flag.Duration("write-timeout", (10 * time.Second), "Write timeout in duration format (default: 10s)")

zoneArgDescription := "The intercval at which to update zone information format 00h00m00s e.g. 1h32m"
zoneUpdateIntervalArg := flag.String("zone-update-interval", "10m", zoneArgDescription)
Expand Down Expand Up @@ -96,15 +99,8 @@ func main() {
panic(err.Error())
}

// Use the provider to make a webhook containing all the callable endpoints
webhook := newWebhook(provider)

// Start webserver to service requests from External-DNS
go func() {
if err = serveWebhook(webhook, "127.0.0.1:8888"); err != nil {
panic(err.Error())
}
}()
go api.StartHTTPApi(provider, nil, *readTimeout, *writeTimeout, "127.0.0.1:8888")

metricsHandler := promhttp.Handler()

Expand Down
2 changes: 1 addition & 1 deletion cmd/webhook/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newProvider(tidy tidydns.TidyDNSClient, zoneProvider ZoneProvider) (*tidyPr
}

// Get list of zones from Tidy and return a domain filter based on them.
func (p *tidyProvider) GetDomainFilter() endpoint.DomainFilter {
func (p *tidyProvider) GetDomainFilter() endpoint.DomainFilterInterface {
// Make list of all zone names
zoneNames := []string{}
for _, zone := range p.zoneProvider.getZones() {
Expand Down
16 changes: 0 additions & 16 deletions cmd/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ import (

type Samples []metrics.Sample

func serveWebhook(wh webhook, addr string) error {
slog.Debug("start webhook server on " + addr)
mux := http.NewServeMux()
mux.HandleFunc("GET /", wh.negociate)
mux.HandleFunc("GET /records", wh.getRecords)
mux.HandleFunc("POST /adjustendpoints", wh.adjustEndpoints)
mux.HandleFunc("POST /records", wh.applyChanges)

server := http.Server{
Addr: addr,
Handler: mux,
}

return server.ListenAndServe()
}

func serveExposed(addr string, metricsHandler http.Handler) error {
slog.Debug("start webhook server on " + addr)
mux := http.NewServeMux()
Expand Down
165 changes: 0 additions & 165 deletions cmd/webhook/webhook.go

This file was deleted.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ k8s.io/utils/strings/slices
sigs.k8s.io/external-dns/endpoint
sigs.k8s.io/external-dns/plan
sigs.k8s.io/external-dns/provider
sigs.k8s.io/external-dns/provider/webhook/api
# sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
## explicit; go 1.18
sigs.k8s.io/json
Expand Down
146 changes: 146 additions & 0 deletions vendor/sigs.k8s.io/external-dns/provider/webhook/api/httpapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4b95aa

Please sign in to comment.