Skip to content

Commit

Permalink
feat(config): make server timeouts configurable (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrieg-ionos authored Sep 12, 2023
1 parent 60fea84 commit 64b1607
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ EOF
helm install external-dns-ionos bitnami/external-dns -f external-dns-ionos-values.yaml
```

See [here](./cmd/webhook/init/configuration/configuration.go) for all available configuration options of webhook sidecar.

## Verify the image resource integrity

All official webhooks provided by IONOS are signed using [Cosign](https://docs.sigstore.dev/cosign/overview/).
Expand Down
17 changes: 10 additions & 7 deletions cmd/webhook/init/configuration/configuration.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package configuration

import (
"time"

"github.com/caarlos0/env/v8"
log "github.com/sirupsen/logrus"
)

// Config struct for configuration environmental variables
type Config struct {
ServerHost string `env:"SERVER_HOST" envDefault:"localhost"`
ServerPort int `env:"SERVER_PORT" envDefault:"8888"`

DomainFilter []string `env:"DOMAIN_FILTER" envDefault:""`
ExcludeDomains []string `env:"EXCLUDE_DOMAIN_FILTER" envDefault:""`
RegexDomainFilter string `env:"REGEXP_DOMAIN_FILTER" envDefault:""`
RegexDomainExclusion string `env:"REGEXP_DOMAIN_FILTER_EXCLUSION" envDefault:""`
ServerHost string `env:"SERVER_HOST" envDefault:"localhost"`
ServerPort int `env:"SERVER_PORT" envDefault:"8888"`
ServerReadTimeout time.Duration `env:"SERVER_READ_TIMEOUT"`
ServerWriteTimeout time.Duration `env:"SERVER_WRITE_TIMEOUT"`
DomainFilter []string `env:"DOMAIN_FILTER" envDefault:""`
ExcludeDomains []string `env:"EXCLUDE_DOMAIN_FILTER" envDefault:""`
RegexDomainFilter string `env:"REGEXP_DOMAIN_FILTER" envDefault:""`
RegexDomainExclusion string `env:"REGEXP_DOMAIN_FILTER_EXCLUSION" envDefault:""`
}

// Init sets up configuration by reading set environmental variables
Expand Down
14 changes: 6 additions & 8 deletions cmd/webhook/init/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Init(config configuration.Config, p *webhook.Webhook) *http.Server {
r.Post("/records", p.ApplyChanges)
r.Post("/adjustendpoints", p.AdjustEndpoints)

srv := createHTTPServer(fmt.Sprintf("%s:%d", config.ServerHost, config.ServerPort), r)
srv := createHTTPServer(fmt.Sprintf("%s:%d", config.ServerHost, config.ServerPort), r, config.ServerReadTimeout, config.ServerWriteTimeout)
go func() {
log.Infof("starting server on addr: '%s' ", srv.Addr)
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
Expand All @@ -43,14 +43,12 @@ func Init(config configuration.Config, p *webhook.Webhook) *http.Server {
return srv
}

func createHTTPServer(addr string, hand http.Handler) *http.Server {
func createHTTPServer(addr string, hand http.Handler, readTimeout, writeTimeout time.Duration) *http.Server {
return &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
ReadHeaderTimeout: 5 * time.Second,
Addr: addr,
Handler: hand,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
Addr: addr,
Handler: hand,
}
}

Expand Down

0 comments on commit 64b1607

Please sign in to comment.