Skip to content

Commit

Permalink
Merge necessary changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
horkhe committed Apr 25, 2024
1 parent 876ef07 commit ad2b6f1
Show file tree
Hide file tree
Showing 26 changed files with 956 additions and 1,472 deletions.
6 changes: 3 additions & 3 deletions pkg/config/dynamic/fixtures/sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@
scheme = "foobar"
path = "foobar"
port = 42
interval = "foobar"
timeout = "foobar"
interval = "1s"
timeout = "1s"
hostname = "foobar"
[http.services.Service0.loadBalancer.healthCheck.headers]
name0 = "foobar"
name1 = "foobar"
[http.services.Service0.loadBalancer.responseForwarding]
flushInterval = "foobar"
flushInterval = "100ms"

[tcp]
[tcp.routers]
Expand Down
31 changes: 22 additions & 9 deletions pkg/config/dynamic/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import (
"github.com/traefik/traefik/v2/pkg/types"
)

const (
// DefaultHealthCheckInterval is the default value for the ServerHealthCheck interval.
DefaultHealthCheckInterval = ptypes.Duration(30 * time.Second)
// DefaultHealthCheckTimeout is the default value for the ServerHealthCheck timeout.
DefaultHealthCheckTimeout = ptypes.Duration(5 * time.Second)

// DefaultPassHostHeader is the default value for the ServersLoadBalancer passHostHeader.
DefaultPassHostHeader = true

// DefaultFlushInterval is the default value for the ResponseForwarding flush interval.
DefaultFlushInterval = ptypes.Duration(100 * time.Millisecond)
)

// +k8s:deepcopy-gen=true

// HTTPConfiguration contains all the HTTP configuration parameters.
Expand Down Expand Up @@ -192,7 +205,7 @@ type ResponseForwarding struct {
// This configuration is ignored when ReverseProxy recognizes a response as a streaming response;
// for such responses, writes are flushed to the client immediately.
// Default: 100ms
FlushInterval string `json:"flushInterval,omitempty" toml:"flushInterval,omitempty" yaml:"flushInterval,omitempty" export:"true"`
FlushInterval ptypes.Duration `json:"flushInterval,omitempty" toml:"flushInterval,omitempty" yaml:"flushInterval,omitempty" export:"true"`
}

// +k8s:deepcopy-gen=true
Expand All @@ -213,14 +226,14 @@ func (s *Server) SetDefaults() {

// ServerHealthCheck holds the HealthCheck configuration.
type ServerHealthCheck struct {
Scheme string `json:"scheme,omitempty" toml:"scheme,omitempty" yaml:"scheme,omitempty" export:"true"`
Path string `json:"path,omitempty" toml:"path,omitempty" yaml:"path,omitempty" export:"true"`
Method string `json:"method,omitempty" toml:"method,omitempty" yaml:"method,omitempty" export:"true"`
Port int `json:"port,omitempty" toml:"port,omitempty,omitzero" yaml:"port,omitempty" export:"true"`
// TODO change string to ptypes.Duration
Interval string `json:"interval,omitempty" toml:"interval,omitempty" yaml:"interval,omitempty" export:"true"`
// TODO change string to ptypes.Duration
Timeout string `json:"timeout,omitempty" toml:"timeout,omitempty" yaml:"timeout,omitempty" export:"true"`
Scheme string `json:"scheme,omitempty" toml:"scheme,omitempty" yaml:"scheme,omitempty" export:"true"`
Mode string `json:"mode,omitempty" toml:"mode,omitempty" yaml:"mode,omitempty" export:"true"`
Path string `json:"path,omitempty" toml:"path,omitempty" yaml:"path,omitempty" export:"true"`
Method string `json:"method,omitempty" toml:"method,omitempty" yaml:"method,omitempty" export:"true"`
Status int `json:"status,omitempty" toml:"status,omitempty" yaml:"status,omitempty" export:"true"`
Port int `json:"port,omitempty" toml:"port,omitempty,omitzero" yaml:"port,omitempty" export:"true"`
Interval ptypes.Duration `json:"interval,omitempty" toml:"interval,omitempty" yaml:"interval,omitempty" export:"true"`
Timeout ptypes.Duration `json:"timeout,omitempty" toml:"timeout,omitempty" yaml:"timeout,omitempty" export:"true"`
Hostname string `json:"hostname,omitempty" toml:"hostname,omitempty" yaml:"hostname,omitempty"`
FollowRedirects *bool `json:"followRedirects" toml:"followRedirects" yaml:"followRedirects" export:"true"`
Headers map[string]string `json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty" export:"true"`
Expand Down
50 changes: 26 additions & 24 deletions pkg/config/label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,31 @@ func TestDecodeConfiguration(t *testing.T) {
"traefik.http.services.Service0.loadbalancer.healthcheck.headers.name0": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.headers.name1": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.hostname": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.interval": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.interval": "1s",
"traefik.http.services.Service0.loadbalancer.healthcheck.path": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.method": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.port": "42",
"traefik.http.services.Service0.loadbalancer.healthcheck.scheme": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.timeout": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.timeout": "1s",
"traefik.http.services.Service0.loadbalancer.healthcheck.followredirects": "true",
"traefik.http.services.Service0.loadbalancer.passhostheader": "true",
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "foobar",
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "100ms",
"traefik.http.services.Service0.loadbalancer.server.scheme": "foobar",
"traefik.http.services.Service0.loadbalancer.server.port": "8080",
"traefik.http.services.Service0.loadbalancer.sticky.cookie.name": "foobar",
"traefik.http.services.Service0.loadbalancer.sticky.cookie.secure": "true",
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name0": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name1": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.hostname": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.interval": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.interval": "1s",
"traefik.http.services.Service1.loadbalancer.healthcheck.path": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.method": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.port": "42",
"traefik.http.services.Service1.loadbalancer.healthcheck.scheme": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.timeout": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.timeout": "1s",
"traefik.http.services.Service1.loadbalancer.healthcheck.followredirects": "true",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "foobar",
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "100ms",
"traefik.http.services.Service1.loadbalancer.server.scheme": "foobar",
"traefik.http.services.Service1.loadbalancer.server.port": "8080",
"traefik.http.services.Service1.loadbalancer.sticky": "false",
Expand Down Expand Up @@ -658,8 +658,8 @@ func TestDecodeConfiguration(t *testing.T) {
Path: "foobar",
Method: "foobar",
Port: 42,
Interval: "foobar",
Timeout: "foobar",
Interval: ptypes.Duration(time.Second),
Timeout: ptypes.Duration(time.Second),
Hostname: "foobar",
Headers: map[string]string{
"name0": "foobar",
Expand All @@ -669,7 +669,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
PassHostHeader: func(v bool) *bool { return &v }(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
Expand All @@ -686,8 +686,8 @@ func TestDecodeConfiguration(t *testing.T) {
Path: "foobar",
Method: "foobar",
Port: 42,
Interval: "foobar",
Timeout: "foobar",
Interval: ptypes.Duration(time.Second),
Timeout: ptypes.Duration(time.Second),
Hostname: "foobar",
Headers: map[string]string{
"name0": "foobar",
Expand All @@ -697,7 +697,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
PassHostHeader: func(v bool) *bool { return &v }(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
Expand Down Expand Up @@ -1162,8 +1162,8 @@ func TestEncodeConfiguration(t *testing.T) {
Path: "foobar",
Method: "foobar",
Port: 42,
Interval: "foobar",
Timeout: "foobar",
Interval: ptypes.Duration(time.Second),
Timeout: ptypes.Duration(time.Second),
Hostname: "foobar",
Headers: map[string]string{
"name0": "foobar",
Expand All @@ -1172,7 +1172,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
PassHostHeader: func(v bool) *bool { return &v }(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
Expand All @@ -1189,8 +1189,8 @@ func TestEncodeConfiguration(t *testing.T) {
Path: "foobar",
Method: "foobar",
Port: 42,
Interval: "foobar",
Timeout: "foobar",
Interval: ptypes.Duration(time.Second),
Timeout: ptypes.Duration(time.Second),
Hostname: "foobar",
Headers: map[string]string{
"name0": "foobar",
Expand All @@ -1199,7 +1199,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
PassHostHeader: func(v bool) *bool { return &v }(true),
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
},
},
Expand Down Expand Up @@ -1359,14 +1359,15 @@ func TestEncodeConfiguration(t *testing.T) {

"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name1": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Hostname": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Interval": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Interval": "1000000000",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Path": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Method": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Port": "42",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Status": "0",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "1000000000",
"traefik.HTTP.Services.Service0.LoadBalancer.PassHostHeader": "true",
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "100000000",
"traefik.HTTP.Services.Service0.LoadBalancer.server.Port": "8080",
"traefik.HTTP.Services.Service0.LoadBalancer.server.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.Sticky.Cookie.Name": "foobar",
Expand All @@ -1375,14 +1376,15 @@ func TestEncodeConfiguration(t *testing.T) {
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name0": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name1": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Hostname": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Interval": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Interval": "1000000000",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Path": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Method": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Port": "42",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Scheme": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Status": "0",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "1000000000",
"traefik.HTTP.Services.Service1.LoadBalancer.PassHostHeader": "true",
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "100000000",
"traefik.HTTP.Services.Service1.LoadBalancer.server.Port": "8080",
"traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar",
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const (
StatusWarning = "warning"
)

// Status of the servers.
const (
StatusUp = "UP"
StatusDown = "DOWN"
)

// Configuration holds the information about the currently running traefik instance.
type Configuration struct {
Routers map[string]*RouterInfo `json:"routers,omitempty"`
Expand Down
8 changes: 5 additions & 3 deletions pkg/config/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package runtime_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/config/runtime"
)
Expand Down Expand Up @@ -49,7 +51,7 @@ func TestPopulateUsedBy(t *testing.T) {
{URL: "http://127.0.0.1:8086"},
},
HealthCheck: &dynamic.ServerHealthCheck{
Interval: "500ms",
Interval: ptypes.Duration(500 * time.Millisecond),
Path: "/health",
},
},
Expand Down Expand Up @@ -159,7 +161,7 @@ func TestPopulateUsedBy(t *testing.T) {
},
},
HealthCheck: &dynamic.ServerHealthCheck{
Interval: "500ms",
Interval: ptypes.Duration(500 * time.Millisecond),
Path: "/health",
},
},
Expand All @@ -177,7 +179,7 @@ func TestPopulateUsedBy(t *testing.T) {
},
},
HealthCheck: &dynamic.ServerHealthCheck{
Interval: "500ms",
Interval: ptypes.Duration(500 * time.Millisecond),
Path: "/health",
},
},
Expand Down
Loading

0 comments on commit ad2b6f1

Please sign in to comment.