Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --webhook-server flag for running as a webhook server #3957

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions docs/tutorials/webhook-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ The server needs to respond to those requests by reading the `Accept` header and

To simplify the discovery of providers, we will accept pull requests that will add links to providers in the [README](../../README.md) file. This list will only serve the purpose of simplifying finding providers and will not constitute an official endorsement of any of the externally implemented providers unless otherwise stated.

## Run the AWS provider with the webhook provider.
## Run an ExternalDNS in-tree provider as a webhook.

To test the Webhook provider and provide a reference implementation, we added the functionality to run the AWS provider as a webhook. To run the AWS provider as a webhook, you need the following flags:
To test the Webhook provider and provide a reference implementation, we added the functionality to run ExternalDNS as a webhook. To run the AWS provider as a webhook, you need the following flags:

```yaml
- --provider=webhook
- --run-aws-provider-as-webhook
- --webhook-server
- --provider=aws
- --source=ingress
```

What will happen behind the scenes is that the AWS provider will be be started as an HTTP server exposed only on localhost and the webhook provider will be configured to talk to it. This is the same setup that we recommend for other providers and a good way to test the Webhook provider.
The value of the `--source` flag is ignored in this mode.

This will start the AWS provider as an HTTP server exposed only on localhost.
In a separate process/container, run ExternalDNS with `--provider=webhook`.
This is the same setup that we recommend for other providers and a good way to test the Webhook provider.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ func main() {
log.Fatal(err)
}

if cfg.WebhookServer {
webhook.StartHTTPApi(p, nil, cfg.WebhookProviderReadTimeout, cfg.WebhookProviderWriteTimeout, "127.0.0.1:8888")
os.Exit(0)
}

var r registry.Registry
switch cfg.Registry {
case "dynamodb":
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ type Config struct {
RunAWSProviderAsWebhook bool
WebhookProviderReadTimeout time.Duration
WebhookProviderWriteTimeout time.Duration
WebhookServer bool
}

var defaultConfig = &Config{
Expand Down Expand Up @@ -364,6 +365,7 @@ var defaultConfig = &Config{
WebhookProviderURL: "http://localhost:8888",
WebhookProviderReadTimeout: 5 * time.Second,
WebhookProviderWriteTimeout: 10 * time.Second,
WebhookServer: false,
}

// NewConfig returns new Config object
Expand Down Expand Up @@ -615,6 +617,8 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("webhook-provider-read-timeout", "[EXPERIMENTAL] The read timeout for the webhook provider in duration format (default: 5s)").Default(defaultConfig.WebhookProviderReadTimeout.String()).DurationVar(&cfg.WebhookProviderReadTimeout)
app.Flag("webhook-provider-write-timeout", "[EXPERIMENTAL] The write timeout for the webhook provider in duration format (default: 10s)").Default(defaultConfig.WebhookProviderWriteTimeout.String()).DurationVar(&cfg.WebhookProviderWriteTimeout)

app.Flag("webhook-server", "[EXPERIMENTAL] When enabled, runs as a webhook server instead of a controller. (default: false).").BoolVar(&cfg.WebhookServer)

_, err := app.Parse(args)
if err != nil {
return err
Expand Down
Loading