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

* Add --webhook-server flag for running as a webhook server

* Address review comment
This commit is contained in:
John Gardiner Myers 2023-09-27 07:40:09 -07:00 committed by GitHub
parent f0b6260012
commit 859892fc72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -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.

View File

@ -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":

View File

@ -213,6 +213,7 @@ type Config struct {
RunAWSProviderAsWebhook bool
WebhookProviderReadTimeout time.Duration
WebhookProviderWriteTimeout time.Duration
WebhookServer bool
}
var defaultConfig = &Config{
@ -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
@ -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