Skip to content

Commit

Permalink
Merge pull request #4 from GDATASoftwareAG/refactor-webhook
Browse files Browse the repository at this point in the history
refactor webhook
  • Loading branch information
farodin91 authored Sep 25, 2023
2 parents c9f9e4d + acd57ad commit 06ca27a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/gdatasoftwareag/external-dns-coredns-plugin
DOCKER_IMAGE=ghcr.io/gdatasoftwareag/external-dns-coredns-webhook
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package main

import (
"os"
"os/signal"
"sigs.k8s.io/external-dns/provider/webhook"
"syscall"
"time"

"github.com/alecthomas/kingpin"
Expand All @@ -36,6 +38,7 @@ type Config struct {
LogLevel string
webhookProviderReadTimeout time.Duration
webhookProviderWriteTimeout time.Duration
webhookProviderPort string
}

// allLogLevelsAsStrings returns all logrus levels as a list of strings
Expand All @@ -62,6 +65,8 @@ func (cfg *Config) ParseFlags(args []string) error {
Default((time.Second * 5).String()).DurationVar(&cfg.webhookProviderReadTimeout)
app.Flag("webhook-provider-write-timeout", "The write timeout for the webhook provider in duration format (default: 5s)").
Default((time.Second * 5).String()).DurationVar(&cfg.webhookProviderWriteTimeout)
app.Flag("webhook-provider-port", "Webhook provider port (default: 0.0.0.0:8888)").
Default("0.0.0.0:8888").StringVar(&cfg.webhookProviderPort)

app.Flag("prefix", "Specify the prefix name").
Default("/skydns/").StringVar(&cfg.coreDNSPrefix)
Expand Down Expand Up @@ -108,8 +113,14 @@ func main() {
if err != nil {
log.Fatalf("listen failed error: %v", err)
}

log.Info("start ExternalDNS coreDNS webhook")
startedChan := make(chan struct{})
go webhook.StartHTTPApi(dnsProvider, startedChan, cfg.webhookProviderReadTimeout, cfg.webhookProviderWriteTimeout, "0.0.0.0:8888")
go webhook.StartHTTPApi(dnsProvider, startedChan, cfg.webhookProviderReadTimeout, cfg.webhookProviderWriteTimeout, cfg.webhookProviderPort)
<-startedChan

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
sig := <-sigCh
log.Infof("shutting down server due to received signal: %v", sig)
}

0 comments on commit 06ca27a

Please sign in to comment.