Fix default value of Healthcheck for ExternalName services
This commit is contained in:
parent
7fc56454ea
commit
b452f37e08
10 changed files with 628 additions and 211 deletions
|
@ -305,7 +305,36 @@ func (c configBuilder) buildServersLB(namespace string, svc traefikv1alpha1.Load
|
|||
lb := &dynamic.ServersLoadBalancer{}
|
||||
lb.SetDefaults()
|
||||
lb.Servers = servers
|
||||
lb.HealthCheck = svc.HealthCheck
|
||||
|
||||
if svc.HealthCheck != nil {
|
||||
lb.HealthCheck = &dynamic.ServerHealthCheck{
|
||||
Scheme: svc.HealthCheck.Scheme,
|
||||
Path: svc.HealthCheck.Path,
|
||||
Method: svc.HealthCheck.Method,
|
||||
Status: svc.HealthCheck.Status,
|
||||
Port: svc.HealthCheck.Port,
|
||||
Hostname: svc.HealthCheck.Hostname,
|
||||
Headers: svc.HealthCheck.Headers,
|
||||
}
|
||||
lb.HealthCheck.SetDefaults()
|
||||
|
||||
if svc.HealthCheck.FollowRedirects != nil {
|
||||
lb.HealthCheck.FollowRedirects = svc.HealthCheck.FollowRedirects
|
||||
}
|
||||
if svc.HealthCheck.Mode != "http" {
|
||||
lb.HealthCheck.Mode = svc.HealthCheck.Mode
|
||||
}
|
||||
if svc.HealthCheck.Interval != nil {
|
||||
if err := lb.HealthCheck.Interval.Set(svc.HealthCheck.Interval.String()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if svc.HealthCheck.Timeout != nil {
|
||||
if err := lb.HealthCheck.Timeout.Set(svc.HealthCheck.Timeout.String()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conf := svc
|
||||
lb.PassHostHeader = conf.PassHostHeader
|
||||
|
|
|
@ -2469,8 +2469,10 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Path: "/health",
|
||||
Interval: 15000000000,
|
||||
Path: "/health",
|
||||
Timeout: 5000000000,
|
||||
Interval: 15000000000,
|
||||
FollowRedirects: Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -2531,8 +2533,10 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Path: "/health1",
|
||||
Interval: 15000000000,
|
||||
Path: "/health1",
|
||||
Timeout: 5000000000,
|
||||
Interval: 15000000000,
|
||||
FollowRedirects: Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -2548,8 +2552,10 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Path: "/health2",
|
||||
Interval: 20000000000,
|
||||
Path: "/health2",
|
||||
Timeout: 5000000000,
|
||||
Interval: 20000000000,
|
||||
FollowRedirects: Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -2589,8 +2595,10 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
},
|
||||
HealthCheck: &dynamic.ServerHealthCheck{
|
||||
Path: "/health1",
|
||||
Interval: 15000000000,
|
||||
Path: "/health1",
|
||||
Timeout: 5000000000,
|
||||
Interval: 15000000000,
|
||||
FollowRedirects: Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -131,8 +131,8 @@ type LoadBalancerSpec struct {
|
|||
// It allows services to be reachable when Traefik runs externally from the Kubernetes cluster but within the same network of the nodes.
|
||||
// By default, NodePortLB is false.
|
||||
NodePortLB bool `json:"nodePortLB,omitempty"`
|
||||
// Healthcheck defines health checks for the service.
|
||||
HealthCheck *dynamic.ServerHealthCheck `json:"healthCheck,omitempty"`
|
||||
// Healthcheck defines health checks for ExternalName services.
|
||||
HealthCheck *ServerHealthCheck `json:"healthCheck,omitempty"`
|
||||
}
|
||||
|
||||
type ResponseForwarding struct {
|
||||
|
@ -144,6 +144,36 @@ type ResponseForwarding struct {
|
|||
FlushInterval string `json:"flushInterval,omitempty"`
|
||||
}
|
||||
|
||||
type ServerHealthCheck struct {
|
||||
// Scheme replaces the server URL scheme for the health check endpoint.
|
||||
Scheme string `json:"scheme,omitempty"`
|
||||
// Mode defines the health check mode.
|
||||
// If defined to grpc, will use the gRPC health check protocol to probe the server.
|
||||
// Default: http
|
||||
Mode string `json:"mode,omitempty"`
|
||||
// Path defines the server URL path for the health check endpoint.
|
||||
Path string `json:"path,omitempty"`
|
||||
// Method defines the healthcheck method.
|
||||
Method string `json:"method,omitempty"`
|
||||
// Status defines the expected HTTP status code of the response to the health check request.
|
||||
Status int `json:"status,omitempty"`
|
||||
// Port defines the server URL port for the health check endpoint.
|
||||
Port int `json:"port,omitempty"`
|
||||
// Interval defines the frequency of the health check calls.
|
||||
// Default: 30s
|
||||
Interval *intstr.IntOrString `json:"interval,omitempty"`
|
||||
// Timeout defines the maximum duration Traefik will wait for a health check request before considering the server unhealthy.
|
||||
// Default: 5s
|
||||
Timeout *intstr.IntOrString `json:"timeout,omitempty"`
|
||||
// Hostname defines the value of hostname in the Host header of the health check request.
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
// FollowRedirects defines whether redirects should be followed during the health check calls.
|
||||
// Default: true
|
||||
FollowRedirects *bool `json:"followRedirects,omitempty"`
|
||||
// Headers defines custom headers to be sent to the health check endpoint.
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
}
|
||||
|
||||
// Service defines an upstream HTTP service to proxy traffic to.
|
||||
type Service struct {
|
||||
LoadBalancerSpec `json:",inline"`
|
||||
|
|
|
@ -584,7 +584,7 @@ func (in *LoadBalancerSpec) DeepCopyInto(out *LoadBalancerSpec) {
|
|||
}
|
||||
if in.HealthCheck != nil {
|
||||
in, out := &in.HealthCheck, &out.HealthCheck
|
||||
*out = new(dynamic.ServerHealthCheck)
|
||||
*out = new(ServerHealthCheck)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
return
|
||||
|
@ -1115,6 +1115,44 @@ func (in *RouteUDP) DeepCopy() *RouteUDP {
|
|||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ServerHealthCheck) DeepCopyInto(out *ServerHealthCheck) {
|
||||
*out = *in
|
||||
if in.Interval != nil {
|
||||
in, out := &in.Interval, &out.Interval
|
||||
*out = new(intstr.IntOrString)
|
||||
**out = **in
|
||||
}
|
||||
if in.Timeout != nil {
|
||||
in, out := &in.Timeout, &out.Timeout
|
||||
*out = new(intstr.IntOrString)
|
||||
**out = **in
|
||||
}
|
||||
if in.FollowRedirects != nil {
|
||||
in, out := &in.FollowRedirects, &out.FollowRedirects
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
if in.Headers != nil {
|
||||
in, out := &in.Headers, &out.Headers
|
||||
*out = make(map[string]string, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerHealthCheck.
|
||||
func (in *ServerHealthCheck) DeepCopy() *ServerHealthCheck {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ServerHealthCheck)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ServersTransport) DeepCopyInto(out *ServersTransport) {
|
||||
*out = *in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue