2016-04-19 17:23:08 +00:00
|
|
|
package provider
|
2016-04-20 11:26:51 +00:00
|
|
|
|
|
|
|
import (
|
2016-04-26 20:26:25 +00:00
|
|
|
"encoding/json"
|
2016-04-20 11:26:51 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
2016-11-11 22:50:20 +00:00
|
|
|
|
2016-12-30 08:21:13 +00:00
|
|
|
"github.com/containous/traefik/provider/k8s"
|
|
|
|
"github.com/containous/traefik/types"
|
2016-11-11 22:50:20 +00:00
|
|
|
"k8s.io/client-go/1.5/pkg/api/v1"
|
|
|
|
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
|
|
|
|
"k8s.io/client-go/1.5/pkg/util/intstr"
|
2016-04-20 11:26:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadIngresses(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-20 16:34:57 +00:00
|
|
|
Namespace: "testing",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
|
|
|
Host: "foo",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
|
|
|
Path: "/bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-20 11:26:51 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(80),
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-20 11:26:51 +00:00
|
|
|
ServiceName: "service3",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromString("https"),
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-20 11:26:51 +00:00
|
|
|
ServiceName: "service2",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(802),
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-20 16:34:57 +00:00
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-20 11:26:51 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
2016-05-20 16:34:57 +00:00
|
|
|
Port: 80,
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-20 16:34:57 +00:00
|
|
|
Name: "service2",
|
|
|
|
UID: "2",
|
|
|
|
Namespace: "testing",
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-20 11:26:51 +00:00
|
|
|
ClusterIP: "10.0.0.2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
|
|
|
Port: 802,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-20 16:34:57 +00:00
|
|
|
Name: "service3",
|
|
|
|
UID: "3",
|
|
|
|
Namespace: "testing",
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-20 11:26:51 +00:00
|
|
|
ClusterIP: "10.0.0.3",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-20 11:26:51 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
2016-05-26 11:09:36 +00:00
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "https",
|
2016-04-26 20:26:25 +00:00
|
|
|
Port: 443,
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
endpoints := []*v1.Endpoints{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-20 16:34:57 +00:00
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Subsets: []v1.EndpointSubset{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
IP: "10.10.0.1",
|
|
|
|
},
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.EndpointPort{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
IP: "10.21.0.1",
|
|
|
|
},
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.EndpointPort{
|
2016-05-20 16:34:57 +00:00
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-26 11:09:36 +00:00
|
|
|
Name: "service3",
|
|
|
|
UID: "3",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Subsets: []v1.EndpointSubset{
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
|
|
|
IP: "10.15.0.1",
|
|
|
|
},
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.EndpointPort{
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "https",
|
|
|
|
Port: 8443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
|
|
|
IP: "10.15.0.2",
|
|
|
|
},
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.EndpointPort{
|
2016-05-26 11:09:36 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 9080,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "https",
|
|
|
|
Port: 9443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-20 16:34:57 +00:00
|
|
|
}
|
2016-04-20 11:26:51 +00:00
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
2016-05-20 16:34:57 +00:00
|
|
|
endpoints: endpoints,
|
2016-04-20 11:26:51 +00:00
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Kubernetes{}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
2016-05-20 16:34:57 +00:00
|
|
|
"http://10.10.0.1:8080": {
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"http://10.21.0.1:8080": {
|
|
|
|
URL: "http://10.21.0.1:8080",
|
2016-04-20 11:26:51 +00:00
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"2": {
|
|
|
|
URL: "http://10.0.0.2:802",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
2016-05-26 11:09:36 +00:00
|
|
|
"https://10.15.0.1:8443": {
|
|
|
|
URL: "https://10.15.0.1:8443",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"https://10.15.0.2:9443": {
|
|
|
|
URL: "https://10.15.0.2:9443",
|
2016-04-20 11:26:51 +00:00
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
2016-08-02 23:48:53 +00:00
|
|
|
Priority: len("/bar"),
|
2016-04-20 11:26:51 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
2016-05-05 17:57:35 +00:00
|
|
|
Rule: "PathPrefix:/bar",
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "bar",
|
|
|
|
PassHostHeader: true,
|
2016-04-20 11:26:51 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"bar": {
|
|
|
|
Rule: "Host:bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-04-26 20:26:25 +00:00
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 10:50:06 +00:00
|
|
|
func TestRuleType(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-17 10:50:06 +00:00
|
|
|
Annotations: map[string]string{"traefik.frontend.rule.type": "PathPrefixStrip"}, //camel case
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Host: "foo1",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Path: "/bar1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-17 10:50:06 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
2016-05-15 09:16:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-17 10:50:06 +00:00
|
|
|
Annotations: map[string]string{"traefik.frontend.rule.type": "path"}, //lower case
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Host: "foo1",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Path: "/bar2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-17 10:50:06 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-17 10:50:06 +00:00
|
|
|
Annotations: map[string]string{"traefik.frontend.rule.type": "PathPrefix"}, //path prefix
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Host: "foo2",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Path: "/bar1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-17 10:50:06 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-17 10:50:06 +00:00
|
|
|
Annotations: map[string]string{"traefik.frontend.rule.type": "PathStrip"}, //path strip
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Host: "foo2",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Path: "/bar2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-17 10:50:06 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-17 10:50:06 +00:00
|
|
|
Annotations: map[string]string{"traefik.frontend.rule.type": "PathXXStrip"}, //wrong rule
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Host: "foo1",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
|
|
|
Path: "/bar3",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-17 10:50:06 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-05-15 09:16:27 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-15 09:16:27 +00:00
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-15 09:16:27 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-15 09:16:27 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2016-05-19 15:44:33 +00:00
|
|
|
provider := Kubernetes{DisablePassHostHeaders: true}
|
2016-05-15 22:24:23 +00:00
|
|
|
actualConfig, err := provider.loadIngresses(client)
|
|
|
|
actual := actualConfig.Frontends
|
2016-05-15 09:16:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := map[string]*types.Frontend{
|
2016-05-17 10:50:06 +00:00
|
|
|
"foo1/bar1": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo1/bar1",
|
|
|
|
Priority: len("/bar1"),
|
2016-05-17 10:50:06 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar1": {
|
|
|
|
Rule: "PathPrefixStrip:/bar1",
|
|
|
|
},
|
|
|
|
"foo1": {
|
|
|
|
Rule: "Host:foo1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foo1/bar2": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo1/bar2",
|
|
|
|
Priority: len("/bar2"),
|
2016-05-17 10:50:06 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar2": {
|
|
|
|
Rule: "Path:/bar2",
|
|
|
|
},
|
|
|
|
"foo1": {
|
|
|
|
Rule: "Host:foo1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foo2/bar1": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo2/bar1",
|
|
|
|
Priority: len("/bar1"),
|
2016-05-17 10:50:06 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar1": {
|
|
|
|
Rule: "PathPrefix:/bar1",
|
|
|
|
},
|
|
|
|
"foo2": {
|
|
|
|
Rule: "Host:foo2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foo2/bar2": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo2/bar2",
|
|
|
|
Priority: len("/bar2"),
|
2016-05-17 10:50:06 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar2": {
|
|
|
|
Rule: "PathStrip:/bar2",
|
|
|
|
},
|
|
|
|
"foo2": {
|
|
|
|
Rule: "Host:foo2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"foo1/bar3": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo1/bar3",
|
|
|
|
Priority: len("/bar3"),
|
2016-05-15 09:16:27 +00:00
|
|
|
Routes: map[string]types.Route{
|
2016-05-17 10:50:06 +00:00
|
|
|
"/bar3": {
|
|
|
|
Rule: "PathPrefix:/bar3",
|
2016-05-15 09:16:27 +00:00
|
|
|
},
|
2016-05-17 10:50:06 +00:00
|
|
|
"foo1": {
|
|
|
|
Rule: "Host:foo1",
|
2016-05-15 09:16:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-05-15 22:24:23 +00:00
|
|
|
actualJSON, _ := json.Marshal(actual)
|
2016-05-15 09:16:27 +00:00
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-10 11:43:24 +00:00
|
|
|
func TestGetPassHostHeader(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-10 11:43:24 +00:00
|
|
|
{
|
|
|
|
Host: "foo",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-10 11:43:24 +00:00
|
|
|
{
|
|
|
|
Path: "/bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-10 11:43:24 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-10 11:43:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-05-10 11:43:24 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service1",
|
|
|
|
Namespace: "awesome",
|
|
|
|
UID: "1",
|
2016-05-10 11:43:24 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-10 11:43:24 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-10 11:43:24 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2016-05-19 15:44:33 +00:00
|
|
|
provider := Kubernetes{DisablePassHostHeaders: true}
|
2016-05-10 11:43:24 +00:00
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"1": {
|
|
|
|
URL: "http://10.0.0.1:801",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-05-10 11:43:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "foo/bar",
|
|
|
|
Priority: len("/bar"),
|
2016-05-10 11:43:24 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
2016-05-05 17:57:35 +00:00
|
|
|
Rule: "PathPrefix:/bar",
|
2016-05-10 11:43:24 +00:00
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 15:46:19 +00:00
|
|
|
func TestOnlyReferencesServicesFromOwnNamespace(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
|
|
|
Host: "foo",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-18 15:46:19 +00:00
|
|
|
ServiceName: "service",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(80),
|
2016-05-18 15:46:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-18 15:46:19 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service",
|
|
|
|
UID: "2",
|
|
|
|
Namespace: "not-awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-18 15:46:19 +00:00
|
|
|
ClusterIP: "10.0.0.2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Kubernetes{}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"1": {
|
|
|
|
URL: "http://10.0.0.1:80",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-05-18 15:46:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo": {
|
|
|
|
Backend: "foo",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 00:23:55 +00:00
|
|
|
func TestLoadNamespacedIngresses(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-04-28 00:23:55 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Host: "foo",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Path: "/bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service3",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(443),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service2",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(802),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-04-28 00:23:55 +00:00
|
|
|
Namespace: "not-awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Host: "baz",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Path: "/baz",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service1",
|
|
|
|
Namespace: "not-awesome",
|
|
|
|
UID: "1",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-18 15:46:19 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service2",
|
|
|
|
Namespace: "awesome",
|
|
|
|
UID: "2",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Port: 802,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service3",
|
|
|
|
Namespace: "awesome",
|
|
|
|
UID: "3",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.3",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Kubernetes{
|
|
|
|
Namespaces: []string{"awesome"},
|
|
|
|
}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"1": {
|
|
|
|
URL: "http://10.0.0.1:801",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"2": {
|
|
|
|
URL: "http://10.0.0.2:802",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"3": {
|
|
|
|
URL: "https://10.0.0.3:443",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
2016-08-02 23:48:53 +00:00
|
|
|
Priority: len("/bar"),
|
2016-04-28 00:23:55 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
2016-05-05 17:57:35 +00:00
|
|
|
Rule: "PathPrefix:/bar",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "bar",
|
|
|
|
PassHostHeader: true,
|
2016-04-28 00:23:55 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"bar": {
|
|
|
|
Rule: "Host:bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadMultipleNamespacedIngresses(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-04-28 00:23:55 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Host: "foo",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Path: "/bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service3",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(443),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service2",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(802),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-04-28 00:23:55 +00:00
|
|
|
Namespace: "somewhat-awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Host: "awesome",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Path: "/quix",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-04-28 00:23:55 +00:00
|
|
|
Namespace: "not-awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Host: "baz",
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Path: "/baz",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-04-28 00:23:55 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Name: "service1",
|
|
|
|
Namespace: "awesome",
|
|
|
|
UID: "1",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "somewhat-awesome",
|
|
|
|
Name: "service1",
|
|
|
|
UID: "17",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-18 15:46:19 +00:00
|
|
|
ClusterIP: "10.0.0.4",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-18 15:46:19 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
Name: "service2",
|
|
|
|
UID: "2",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.2",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Port: 802,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-18 15:46:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
Name: "service3",
|
|
|
|
UID: "3",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-04-28 00:23:55 +00:00
|
|
|
ClusterIP: "10.0.0.3",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-04-28 00:23:55 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Kubernetes{
|
|
|
|
Namespaces: []string{"awesome", "somewhat-awesome"},
|
|
|
|
}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"1": {
|
|
|
|
URL: "http://10.0.0.1:801",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"2": {
|
|
|
|
URL: "http://10.0.0.2:802",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"3": {
|
|
|
|
URL: "https://10.0.0.3:443",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"awesome/quix": {
|
|
|
|
Servers: map[string]types.Server{
|
2016-05-18 15:46:19 +00:00
|
|
|
"17": {
|
|
|
|
URL: "http://10.0.0.4:801",
|
2016-04-28 00:23:55 +00:00
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
2016-08-02 23:48:53 +00:00
|
|
|
Priority: len("/bar"),
|
2016-04-28 00:23:55 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
2016-05-05 17:57:35 +00:00
|
|
|
Rule: "PathPrefix:/bar",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bar": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "bar",
|
|
|
|
PassHostHeader: true,
|
2016-04-28 00:23:55 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"bar": {
|
|
|
|
Rule: "Host:bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"awesome/quix": {
|
2016-05-10 11:43:24 +00:00
|
|
|
Backend: "awesome/quix",
|
|
|
|
PassHostHeader: true,
|
2016-08-02 23:48:53 +00:00
|
|
|
Priority: len("/quix"),
|
2016-04-28 00:23:55 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/quix": {
|
2016-05-05 17:57:35 +00:00
|
|
|
Rule: "PathPrefix:/quix",
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"awesome": {
|
|
|
|
Rule: "Host:awesome",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
2016-05-25 12:16:19 +00:00
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHostlessIngress(t *testing.T) {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses := []*v1beta1.Ingress{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-25 12:16:19 +00:00
|
|
|
Namespace: "awesome",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
2016-05-25 12:16:19 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
2016-05-25 12:16:19 +00:00
|
|
|
{
|
|
|
|
Path: "/bar",
|
2016-11-11 22:50:20 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2016-05-25 12:16:19 +00:00
|
|
|
ServiceName: "service1",
|
2016-11-11 22:50:20 +00:00
|
|
|
ServicePort: intstr.FromInt(801),
|
2016-05-25 12:16:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
2016-11-11 22:50:20 +00:00
|
|
|
services := []*v1.Service{
|
2016-05-25 12:16:19 +00:00
|
|
|
{
|
2016-11-11 22:50:20 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2016-05-25 12:16:19 +00:00
|
|
|
Name: "service1",
|
|
|
|
Namespace: "awesome",
|
|
|
|
UID: "1",
|
|
|
|
},
|
2016-11-11 22:50:20 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
2016-05-25 12:16:19 +00:00
|
|
|
ClusterIP: "10.0.0.1",
|
2016-11-11 22:50:20 +00:00
|
|
|
Ports: []v1.ServicePort{
|
2016-05-25 12:16:19 +00:00
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2016-05-26 13:55:50 +00:00
|
|
|
provider := Kubernetes{DisablePassHostHeaders: true}
|
2016-05-25 12:16:19 +00:00
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"1": {
|
|
|
|
URL: "http://10.0.0.1:801",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Sticky: false,
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-05-25 12:16:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"/bar": {
|
2016-08-02 23:48:53 +00:00
|
|
|
Backend: "/bar",
|
|
|
|
Priority: len("/bar"),
|
2016-05-25 12:16:19 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
2016-04-28 00:23:55 +00:00
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 13:11:00 +00:00
|
|
|
func TestLoadBalancerAnnotation(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "foo",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/bar",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "bar",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service2",
|
|
|
|
ServicePort: intstr.FromInt(802),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"traefik.backend.loadbalancer.method": "drr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service2",
|
|
|
|
UID: "2",
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"traefik.backend.loadbalancer.sticky": "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.2",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 802,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
endpoints := []*v1.Endpoints{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
|
|
|
{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{
|
|
|
|
IP: "10.10.0.1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{
|
|
|
|
IP: "10.21.0.1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service2",
|
|
|
|
UID: "2",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
|
|
|
{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{
|
|
|
|
IP: "10.15.0.1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{
|
|
|
|
IP: "10.15.0.2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Kubernetes{}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo/bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://10.10.0.1:8080": {
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"http://10.21.0.1:8080": {
|
|
|
|
URL: "http://10.21.0.1:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "drr",
|
|
|
|
Sticky: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://10.15.0.1:8080": {
|
|
|
|
URL: "http://10.15.0.1:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
"http://10.15.0.2:8080": {
|
|
|
|
URL: "http://10.15.0.2:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
Sticky: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Priority: len("/bar"),
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
Backend: "bar",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"bar": {
|
|
|
|
Rule: "Host:bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
actualJSON, _ := json.Marshal(actual)
|
|
|
|
expectedJSON, _ := json.Marshal(expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("expected %+v, got %+v", string(expectedJSON), string(actualJSON))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-20 11:26:51 +00:00
|
|
|
type clientMock struct {
|
2016-11-11 22:50:20 +00:00
|
|
|
ingresses []*v1beta1.Ingress
|
|
|
|
services []*v1.Service
|
|
|
|
endpoints []*v1.Endpoints
|
2016-04-20 11:26:51 +00:00
|
|
|
watchChan chan interface{}
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:50:20 +00:00
|
|
|
func (c clientMock) GetIngresses(namespaces k8s.Namespaces) []*v1beta1.Ingress {
|
|
|
|
result := make([]*v1beta1.Ingress, 0, len(c.ingresses))
|
|
|
|
|
2016-04-28 00:23:55 +00:00
|
|
|
for _, ingress := range c.ingresses {
|
2016-11-11 22:50:20 +00:00
|
|
|
if k8s.HasNamespace(ingress, namespaces) {
|
|
|
|
result = append(result, ingress)
|
2016-04-28 00:23:55 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
return result
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
|
|
|
|
func (c clientMock) GetService(namespace, name string) (*v1.Service, bool, error) {
|
2016-05-18 15:46:19 +00:00
|
|
|
for _, service := range c.services {
|
2016-05-25 23:53:51 +00:00
|
|
|
if service.Namespace == namespace && service.Name == name {
|
2016-11-11 22:50:20 +00:00
|
|
|
return service, true, nil
|
2016-05-18 15:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
return &v1.Service{}, true, nil
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
2016-05-20 16:34:57 +00:00
|
|
|
|
2016-11-11 22:50:20 +00:00
|
|
|
func (c clientMock) GetEndpoints(namespace, name string) (*v1.Endpoints, bool, error) {
|
2016-05-20 16:34:57 +00:00
|
|
|
for _, endpoints := range c.endpoints {
|
|
|
|
if endpoints.Namespace == namespace && endpoints.Name == name {
|
2016-11-11 22:50:20 +00:00
|
|
|
return endpoints, true, nil
|
2016-05-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 22:50:20 +00:00
|
|
|
return &v1.Endpoints{}, true, nil
|
2016-05-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 20:20:39 +00:00
|
|
|
func (c clientMock) WatchAll(labelString string, stopCh <-chan struct{}) (<-chan interface{}, error) {
|
2016-11-11 22:50:20 +00:00
|
|
|
return c.watchChan, nil
|
2016-04-25 14:56:06 +00:00
|
|
|
}
|