Allow setting circuitbreaker expression via Kubernetes annotation (#1056)
This commit is contained in:
parent
b22dc213e8
commit
225dbcce0a
5 changed files with 30 additions and 5 deletions
|
@ -175,12 +175,18 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
|
|||
continue
|
||||
}
|
||||
|
||||
if expression := service.Annotations["traefik.backend.circuitbreaker"]; expression != "" {
|
||||
templateObjects.Backends[r.Host+pa.Path].CircuitBreaker = &types.CircuitBreaker{
|
||||
Expression: expression,
|
||||
}
|
||||
}
|
||||
if service.Annotations["traefik.backend.loadbalancer.method"] == "drr" {
|
||||
templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Method = "drr"
|
||||
}
|
||||
if service.Annotations["traefik.backend.loadbalancer.sticky"] == "true" {
|
||||
templateObjects.Backends[r.Host+pa.Path].LoadBalancer.Sticky = true
|
||||
}
|
||||
|
||||
protocol := "http"
|
||||
for _, port := range service.Spec.Ports {
|
||||
if equalPorts(port, pa.Backend.ServicePort) {
|
||||
|
|
|
@ -1288,7 +1288,7 @@ func TestHostlessIngress(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoadBalancerAnnotation(t *testing.T) {
|
||||
func TestServiceAnnotations(t *testing.T) {
|
||||
ingresses := []*v1beta1.Ingress{{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Namespace: "testing",
|
||||
|
@ -1336,6 +1336,7 @@ func TestLoadBalancerAnnotation(t *testing.T) {
|
|||
UID: "1",
|
||||
Namespace: "testing",
|
||||
Annotations: map[string]string{
|
||||
"traefik.backend.circuitbreaker": "NetworkErrorRatio() > 0.5",
|
||||
"traefik.backend.loadbalancer.method": "drr",
|
||||
},
|
||||
},
|
||||
|
@ -1354,6 +1355,7 @@ func TestLoadBalancerAnnotation(t *testing.T) {
|
|||
UID: "2",
|
||||
Namespace: "testing",
|
||||
Annotations: map[string]string{
|
||||
"traefik.backend.circuitbreaker": "",
|
||||
"traefik.backend.loadbalancer.sticky": "true",
|
||||
},
|
||||
},
|
||||
|
@ -1463,7 +1465,9 @@ func TestLoadBalancerAnnotation(t *testing.T) {
|
|||
Weight: 1,
|
||||
},
|
||||
},
|
||||
CircuitBreaker: nil,
|
||||
CircuitBreaker: &types.CircuitBreaker{
|
||||
Expression: "NetworkErrorRatio() > 0.5",
|
||||
},
|
||||
LoadBalancer: &types.LoadBalancer{
|
||||
Method: "drr",
|
||||
Sticky: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue