kubernetes ingress rewrite-target implementation

* Adding support for `ingress.kubernetes.io/rewrite-target`

We create a rule using the `PathPrefixStrip` to trim out the bit in the rewrite rule.
This commit is contained in:
Michael Laccetti 2017-07-07 15:27:54 -04:00 committed by Ludovic Fernandez
parent dbf6161fa1
commit 41dd124a4b
2 changed files with 83 additions and 13 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/containous/traefik/types"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
"k8s.io/client-go/pkg/util/intstr"
@ -1555,6 +1556,33 @@ func TestIngressAnnotations(t *testing.T) {
},
},
},
}, {
ObjectMeta: v1.ObjectMeta{
Namespace: "testing",
Annotations: map[string]string{
"ingress.kubernetes.io/rewrite-target": "/",
},
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{
Host: "rewrite",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
{
Path: "/api",
Backend: v1beta1.IngressBackend{
ServiceName: "service1",
ServicePort: intstr.FromInt(80),
},
},
},
},
},
},
},
},
},
}
services := []*v1.Service{
@ -1659,6 +1687,19 @@ func TestIngressAnnotations(t *testing.T) {
Method: "wrr",
},
},
"rewrite/api": {
Servers: map[string]types.Server{
"http://example.com": {
URL: "http://example.com",
Weight: 1,
},
},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{
Sticky: false,
Method: "wrr",
},
},
},
Frontends: map[string]*types.Frontend{
"foo/bar": {
@ -1718,15 +1759,23 @@ func TestIngressAnnotations(t *testing.T) {
},
},
},
"rewrite/api": {
Backend: "rewrite/api",
PassHostHeader: true,
Routes: map[string]types.Route{
"/api": {
Rule: "ReplacePath:/",
},
"rewrite": {
Rule: "Host:rewrite",
},
},
Priority: len("/api"),
},
},
}
actualJSON, _ := json.Marshal(actual)
expectedJSON, _ := json.Marshal(expected)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
}
assert.Equal(t, expected, actual)
}
func TestInvalidPassHostHeaderValue(t *testing.T) {