2017-04-17 10:50:02 +00:00
|
|
|
package kubernetes
|
2016-04-20 11:26:51 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-17 15:34:34 +00:00
|
|
|
"errors"
|
2017-02-06 23:04:30 +00:00
|
|
|
"fmt"
|
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/types"
|
2017-07-07 19:27:54 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-04-07 10:49:53 +00:00
|
|
|
"k8s.io/client-go/pkg/api/v1"
|
|
|
|
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
|
|
|
|
"k8s.io/client-go/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
|
|
|
},
|
|
|
|
},
|
2017-02-10 01:25:38 +00:00
|
|
|
{
|
|
|
|
Path: "/namedthing",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service4",
|
|
|
|
ServicePort: intstr.FromString("https"),
|
|
|
|
},
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-02-10 01:25:38 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service4",
|
|
|
|
UID: "4",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.4",
|
|
|
|
Type: "ExternalName",
|
|
|
|
ExternalName: "example.com",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "https",
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2016-04-20 11:26:51 +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{
|
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{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-20 11:26:51 +00:00
|
|
|
},
|
2017-02-10 01:25:38 +00:00
|
|
|
"foo/namedthing": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"https://example.com": {
|
|
|
|
URL: "https://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2016-04-20 11:26:51 +00:00
|
|
|
"bar": {
|
|
|
|
Servers: map[string]types.Server{
|
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{
|
|
|
|
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-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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-02-10 01:25:38 +00:00
|
|
|
"foo/namedthing": {
|
|
|
|
Backend: "foo/namedthing",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/namedthing": {
|
|
|
|
Rule: "PathPrefix:/namedthing",
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-20 11:26:51 +00:00
|
|
|
"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
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 10:50:06 +00:00
|
|
|
func TestRuleType(t *testing.T) {
|
2017-02-06 23:04:30 +00:00
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
ingressRuleType string
|
|
|
|
frontendRuleType string
|
|
|
|
}{
|
2016-05-17 10:50:06 +00:00
|
|
|
{
|
2017-05-18 21:27:10 +00:00
|
|
|
desc: "rule type annotation missing",
|
2017-02-06 23:04:30 +00:00
|
|
|
ingressRuleType: "",
|
|
|
|
frontendRuleType: ruleTypePathPrefix,
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-19 09:50:36 +00:00
|
|
|
desc: "Path rule type annotation set",
|
2017-05-18 21:27:10 +00:00
|
|
|
ingressRuleType: "Path",
|
|
|
|
frontendRuleType: "Path",
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
2017-05-19 09:50:36 +00:00
|
|
|
{
|
|
|
|
desc: "PathStrip rule type annotation set",
|
|
|
|
ingressRuleType: "PathStrip",
|
|
|
|
frontendRuleType: "PathStrip",
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-19 09:50:36 +00:00
|
|
|
desc: "PathStripPrefix rule type annotation set",
|
|
|
|
ingressRuleType: "PathStripPrefix",
|
|
|
|
frontendRuleType: "PathStripPrefix",
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
2017-02-06 23:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
ingress := &v1beta1.Ingress{
|
2017-04-11 15:10:46 +00:00
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
2017-02-06 23:04:30 +00:00
|
|
|
Host: "host",
|
2017-04-11 15:10:46 +00:00
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
2017-02-06 23:04:30 +00:00
|
|
|
Path: "/path",
|
2017-04-11 15:10:46 +00:00
|
|
|
Backend: v1beta1.IngressBackend{
|
2017-02-06 23:04:30 +00:00
|
|
|
ServiceName: "service",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
|
|
|
},
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-11 15:10:46 +00:00
|
|
|
}
|
2017-02-06 23:04:30 +00:00
|
|
|
|
|
|
|
if test.ingressRuleType != "" {
|
|
|
|
ingress.ObjectMeta.Annotations = map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendRuleType: test.ingressRuleType,
|
2017-02-06 23:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
service := &v1.Service{
|
2017-04-11 15:10:46 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
2017-02-06 23:04:30 +00:00
|
|
|
Name: "service",
|
2017-04-11 15:10:46 +00:00
|
|
|
UID: "1",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 801,
|
|
|
|
},
|
2016-05-17 10:50:06 +00:00
|
|
|
},
|
|
|
|
},
|
2017-04-11 15:10:46 +00:00
|
|
|
}
|
2016-05-15 09:16:27 +00:00
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
2017-02-06 23:04:30 +00:00
|
|
|
ingresses: []*v1beta1.Ingress{ingress},
|
|
|
|
services: []*v1.Service{service},
|
2017-04-11 15:10:46 +00:00
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{DisablePassHostHeaders: true}
|
2017-04-11 15:10:46 +00:00
|
|
|
actualConfig, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
2017-02-06 23:04:30 +00:00
|
|
|
t.Fatalf("error loading ingresses: %+v", err)
|
2017-04-11 15:10:46 +00:00
|
|
|
}
|
2017-02-06 23:04:30 +00:00
|
|
|
|
|
|
|
actual := actualConfig.Frontends
|
2017-04-11 15:10:46 +00:00
|
|
|
expected := map[string]*types.Frontend{
|
2017-02-06 23:04:30 +00:00
|
|
|
"host/path": {
|
2017-08-18 14:14:03 +00:00
|
|
|
Backend: "host/path",
|
2017-04-11 15:10:46 +00:00
|
|
|
Routes: map[string]types.Route{
|
2017-02-06 23:04:30 +00:00
|
|
|
"/path": {
|
|
|
|
Rule: fmt.Sprintf("%s:/path", test.frontendRuleType),
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
2017-02-06 23:04:30 +00:00
|
|
|
"host": {
|
|
|
|
Rule: "Host:host",
|
2017-04-11 15:10:46 +00:00
|
|
|
},
|
|
|
|
},
|
2016-05-15 09:16:27 +00:00
|
|
|
},
|
2017-04-11 15:10:46 +00:00
|
|
|
}
|
2016-05-15 09:16:27 +00:00
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2017-02-06 23:04:30 +00:00
|
|
|
})
|
2016-05-15 09:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{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": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-05-10 11:43:24 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-05-10 11:43:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
2017-08-18 14:14:03 +00:00
|
|
|
Backend: "foo/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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-05-10 11:43:24 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2016-05-18 15:46:19 +00:00
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"foo": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-05-18 15:46:19 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-05-18 15:46:19 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{
|
2016-04-28 00:23:55 +00:00
|
|
|
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": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-04-28 00:23:55 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-04-28 00:23:55 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
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-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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-04-28 00:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{
|
2016-04-28 00:23:55 +00:00
|
|
|
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": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-04-28 00:23:55 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"bar": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-04-28 00:23:55 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-04-28 00:23:55 +00:00
|
|
|
},
|
|
|
|
"awesome/quix": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-04-28 00:23:55 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
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-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-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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-05-25 12:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{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": {
|
2017-04-13 22:00:25 +00:00
|
|
|
Servers: map[string]types.Server{},
|
2016-05-25 12:16:19 +00:00
|
|
|
CircuitBreaker: nil,
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
2016-05-25 12:16:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"/bar": {
|
2017-08-18 14:14:03 +00:00
|
|
|
Backend: "/bar",
|
2016-05-25 12:16:19 +00:00
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2016-04-28 00:23:55 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:47:48 +00:00
|
|
|
func TestServiceAnnotations(t *testing.T) {
|
2017-01-25 13:11:00 +00:00
|
|
|
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{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTraefikBackendCircuitbreaker: "NetworkErrorRatio() > 0.5",
|
|
|
|
types.LabelBackendLoadbalancerMethod: "drr",
|
2017-01-25 13:11:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelTraefikBackendCircuitbreaker: "",
|
|
|
|
types.LabelBackendLoadbalancerSticky: "true",
|
2017-01-25 13:11:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2017-01-25 13:11:00 +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{
|
|
|
|
"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,
|
|
|
|
},
|
|
|
|
},
|
2017-02-03 16:47:48 +00:00
|
|
|
CircuitBreaker: &types.CircuitBreaker{
|
|
|
|
Expression: "NetworkErrorRatio() > 0.5",
|
|
|
|
},
|
2017-01-25 13:11:00 +00:00
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "drr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"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",
|
2017-10-16 15:38:03 +00:00
|
|
|
Sticky: true,
|
2017-01-25 13:11:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-10-16 15:38:03 +00:00
|
|
|
assert.EqualValues(t, expected, actual)
|
2017-01-25 13:11:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 11:27:30 +00:00
|
|
|
func TestIngressAnnotations(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendPassHostHeader: "false",
|
2017-02-10 11:27:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
2017-03-03 19:30:22 +00:00
|
|
|
"kubernetes.io/ingress.class": "traefik",
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendPassHostHeader: "true",
|
2017-02-10 11:27:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "other",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/stuff",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-23 14:17:20 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"ingress.kubernetes.io/auth-type": "basic",
|
|
|
|
"ingress.kubernetes.io/auth-secret": "mySecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "basic",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/auth",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-03 19:30:22 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"kubernetes.io/ingress.class": "somethingOtherThanTraefik",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "herp",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/derp",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service2",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-30 09:22:07 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"kubernetes.io/ingress.class": "traefik",
|
|
|
|
"ingress.kubernetes.io/whitelist-source-range": "1.1.1.1/24, 1234:abcd::42/32",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "test",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/whitelist-source-range",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-07 19:27:54 +00:00
|
|
|
}, {
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-30 09:22:07 +00:00
|
|
|
},
|
2017-10-12 13:48:03 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"ingress.kubernetes.io/auth-realm": "customized",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "auth-realm-customized",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/auth-realm-customized",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-02-10 11:27:30 +00:00
|
|
|
}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Type: "ExternalName",
|
|
|
|
ExternalName: "example.com",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-04-23 14:17:20 +00:00
|
|
|
secrets := []*v1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "mySecret",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"auth": []byte("myUser:myEncodedPW"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-02-10 11:27:30 +00:00
|
|
|
|
|
|
|
endpoints := []*v1.Endpoints{}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
2017-04-23 14:17:20 +00:00
|
|
|
secrets: secrets,
|
2017-02-10 11:27:30 +00:00
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2017-02-10 11:27:30 +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{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"other/stuff": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-04-23 14:17:20 +00:00
|
|
|
"basic/auth": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-04-30 09:22:07 +00:00
|
|
|
"test/whitelist-source-range": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-07-07 19:27:54 +00:00
|
|
|
"rewrite/api": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-02-10 11:27:30 +00:00
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: false,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"other/stuff": {
|
|
|
|
Backend: "other/stuff",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/stuff": {
|
|
|
|
Rule: "PathPrefix:/stuff",
|
|
|
|
},
|
|
|
|
"other": {
|
|
|
|
Rule: "Host:other",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-23 14:17:20 +00:00
|
|
|
"basic/auth": {
|
|
|
|
Backend: "basic/auth",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/auth": {
|
|
|
|
Rule: "PathPrefix:/auth",
|
|
|
|
},
|
|
|
|
"basic": {
|
|
|
|
Rule: "Host:basic",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BasicAuth: []string{"myUser:myEncodedPW"},
|
|
|
|
},
|
2017-04-30 09:22:07 +00:00
|
|
|
"test/whitelist-source-range": {
|
|
|
|
Backend: "test/whitelist-source-range",
|
|
|
|
PassHostHeader: true,
|
|
|
|
WhitelistSourceRange: []string{
|
|
|
|
"1.1.1.1/24",
|
|
|
|
"1234:abcd::42/32",
|
|
|
|
},
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/whitelist-source-range": {
|
|
|
|
Rule: "PathPrefix:/whitelist-source-range",
|
|
|
|
},
|
|
|
|
"test": {
|
|
|
|
Rule: "Host:test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-07-07 19:27:54 +00:00
|
|
|
"rewrite/api": {
|
|
|
|
Backend: "rewrite/api",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/api": {
|
2017-11-27 10:22:03 +00:00
|
|
|
Rule: "PathPrefix:/api;ReplacePath:/",
|
2017-07-07 19:27:54 +00:00
|
|
|
},
|
|
|
|
"rewrite": {
|
|
|
|
Rule: "Host:rewrite",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-02-10 11:27:30 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-07-07 19:27:54 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2017-02-10 11:27:30 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 16:35:23 +00:00
|
|
|
func TestPriorityHeaderValue(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
types.LabelFrontendPriority: "1337",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Type: "ExternalName",
|
|
|
|
ExternalName: "example.com",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoints := []*v1.Endpoints{}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Provider{}
|
|
|
|
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://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Priority: 1337,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|
|
|
|
|
2017-02-14 19:54:27 +00:00
|
|
|
func TestInvalidPassHostHeaderValue(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
2017-07-10 14:58:12 +00:00
|
|
|
types.LabelFrontendPassHostHeader: "herpderp",
|
2017-02-14 19:54:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Type: "ExternalName",
|
|
|
|
ExternalName: "example.com",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoints := []*v1.Endpoints{}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2017-02-14 19:54:27 +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{
|
|
|
|
"http://example.com": {
|
|
|
|
URL: "http://example.com",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"foo/bar": {
|
|
|
|
Backend: "foo/bar",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"/bar": {
|
|
|
|
Rule: "PathPrefix:/bar",
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
Rule: "Host:foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2017-02-14 19:54:27 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 15:34:34 +00:00
|
|
|
func TestKubeAPIErrors(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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
services := []*v1.Service{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
endpoints := []*v1.Endpoints{}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
apiErr := errors.New("failed kube api call")
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
apiServiceErr error
|
|
|
|
apiEndpointsErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "failed service call",
|
|
|
|
apiServiceErr: apiErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "failed endpoints call",
|
|
|
|
apiEndpointsErr: apiErr,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
apiServiceError: tc.apiServiceErr,
|
|
|
|
apiEndpointsError: tc.apiEndpointsErr,
|
|
|
|
}
|
|
|
|
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2017-03-17 15:34:34 +00:00
|
|
|
if _, err := provider.loadIngresses(client); err != apiErr {
|
|
|
|
t.Errorf("Got error %v, wanted error %v", err, apiErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMissingResources(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "fully_working",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "fully_working_service",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "missing_service",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "missing_service_service",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Host: "missing_endpoints",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "missing_endpoints_service",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-05-15 21:16:35 +00:00
|
|
|
{
|
|
|
|
Host: "missing_endpoint_subsets",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "missing_endpoint_subsets_service",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-17 15:34:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "fully_working_service",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "missing_endpoints_service",
|
|
|
|
UID: "3",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.3",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-05-15 21:16:35 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "missing_endpoint_subsets_service",
|
|
|
|
UID: "4",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.4",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-17 15:34:34 +00:00
|
|
|
}
|
|
|
|
endpoints := []*v1.Endpoints{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "fully_working_service",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
|
|
|
{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{
|
|
|
|
IP: "10.10.0.1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
|
|
|
{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-05-15 21:16:35 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "missing_endpoint_subsets_service",
|
|
|
|
UID: "4",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
},
|
2017-03-17 15:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
2017-04-13 22:00:25 +00:00
|
|
|
|
2017-04-17 10:50:02 +00:00
|
|
|
provider := Provider{}
|
2017-03-17 15:34:34 +00:00
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &types.Configuration{
|
|
|
|
Backends: map[string]*types.Backend{
|
|
|
|
"fully_working": {
|
|
|
|
Servers: map[string]types.Server{
|
|
|
|
"http://10.10.0.1:8080": {
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
Weight: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"missing_service": {
|
|
|
|
Servers: map[string]types.Server{},
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"missing_endpoints": {
|
|
|
|
Servers: map[string]types.Server{},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-05-15 21:16:35 +00:00
|
|
|
"missing_endpoint_subsets": {
|
|
|
|
Servers: map[string]types.Server{},
|
|
|
|
CircuitBreaker: nil,
|
|
|
|
LoadBalancer: &types.LoadBalancer{
|
|
|
|
Method: "wrr",
|
|
|
|
},
|
|
|
|
},
|
2017-03-17 15:34:34 +00:00
|
|
|
},
|
|
|
|
Frontends: map[string]*types.Frontend{
|
|
|
|
"fully_working": {
|
|
|
|
Backend: "fully_working",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"fully_working": {
|
|
|
|
Rule: "Host:fully_working",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"missing_endpoints": {
|
|
|
|
Backend: "missing_endpoints",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"missing_endpoints": {
|
|
|
|
Rule: "Host:missing_endpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-05-15 21:16:35 +00:00
|
|
|
"missing_endpoint_subsets": {
|
|
|
|
Backend: "missing_endpoint_subsets",
|
|
|
|
PassHostHeader: true,
|
|
|
|
Routes: map[string]types.Route{
|
|
|
|
"missing_endpoint_subsets": {
|
|
|
|
Rule: "Host:missing_endpoint_subsets",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-17 15:34:34 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-18 14:14:03 +00:00
|
|
|
assert.Equal(t, expected, actual)
|
2017-03-17 15:34:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-23 14:17:20 +00:00
|
|
|
func TestBasicAuthInTemplate(t *testing.T) {
|
|
|
|
ingresses := []*v1beta1.Ingress{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Namespace: "testing",
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"ingress.kubernetes.io/auth-type": "basic",
|
|
|
|
"ingress.kubernetes.io/auth-secret": "mySecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: v1beta1.IngressSpec{
|
|
|
|
Rules: []v1beta1.IngressRule{
|
|
|
|
{
|
|
|
|
Host: "basic",
|
|
|
|
IngressRuleValue: v1beta1.IngressRuleValue{
|
|
|
|
HTTP: &v1beta1.HTTPIngressRuleValue{
|
|
|
|
Paths: []v1beta1.HTTPIngressPath{
|
|
|
|
{
|
|
|
|
Path: "/auth",
|
|
|
|
Backend: v1beta1.IngressBackend{
|
|
|
|
ServiceName: "service1",
|
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
services := []*v1.Service{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "service1",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
ClusterIP: "10.0.0.1",
|
|
|
|
Type: "ExternalName",
|
|
|
|
ExternalName: "example.com",
|
|
|
|
Ports: []v1.ServicePort{
|
|
|
|
{
|
|
|
|
Name: "http",
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
secrets := []*v1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: "mySecret",
|
|
|
|
UID: "1",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"auth": []byte("myUser:myEncodedPW"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoints := []*v1.Endpoints{}
|
|
|
|
watchChan := make(chan interface{})
|
|
|
|
client := clientMock{
|
|
|
|
ingresses: ingresses,
|
|
|
|
services: services,
|
|
|
|
secrets: secrets,
|
|
|
|
endpoints: endpoints,
|
|
|
|
watchChan: watchChan,
|
|
|
|
}
|
|
|
|
provider := Provider{}
|
|
|
|
actual, err := provider.loadIngresses(client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual = provider.loadConfig(*actual)
|
|
|
|
got := actual.Frontends["basic/auth"].BasicAuth
|
|
|
|
if !reflect.DeepEqual(got, []string{"myUser:myEncodedPW"}) {
|
|
|
|
t.Fatalf("unexpected credentials: %+v", got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2017-04-23 14:17:20 +00:00
|
|
|
secrets []*v1.Secret
|
2016-11-11 22:50:20 +00:00
|
|
|
endpoints []*v1.Endpoints
|
2016-04-20 11:26:51 +00:00
|
|
|
watchChan chan interface{}
|
2017-03-17 15:34:34 +00:00
|
|
|
|
|
|
|
apiServiceError error
|
2017-04-23 14:17:20 +00:00
|
|
|
apiSecretError error
|
2017-03-17 15:34:34 +00:00
|
|
|
apiEndpointsError error
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 10:50:02 +00:00
|
|
|
func (c clientMock) GetIngresses(namespaces Namespaces) []*v1beta1.Ingress {
|
2016-11-11 22:50:20 +00:00
|
|
|
result := make([]*v1beta1.Ingress, 0, len(c.ingresses))
|
|
|
|
|
2016-04-28 00:23:55 +00:00
|
|
|
for _, ingress := range c.ingresses {
|
2017-04-17 10:50:02 +00:00
|
|
|
if HasNamespace(ingress, namespaces) {
|
2016-11-11 22:50:20 +00:00
|
|
|
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) {
|
2017-03-17 15:34:34 +00:00
|
|
|
if c.apiServiceError != nil {
|
2017-03-22 17:56:14 +00:00
|
|
|
return nil, false, c.apiServiceError
|
2017-03-17 15:34:34 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-03-22 17:56:14 +00:00
|
|
|
return nil, false, nil
|
2016-04-20 11:26:51 +00:00
|
|
|
}
|
2016-05-20 16:34:57 +00:00
|
|
|
|
2017-04-23 14:17:20 +00:00
|
|
|
func (c clientMock) GetSecret(namespace, name string) (*v1.Secret, bool, error) {
|
|
|
|
if c.apiSecretError != nil {
|
|
|
|
return nil, false, c.apiSecretError
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, secret := range c.secrets {
|
|
|
|
if secret.Namespace == namespace && secret.Name == name {
|
|
|
|
return secret, true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false, nil
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:50:20 +00:00
|
|
|
func (c clientMock) GetEndpoints(namespace, name string) (*v1.Endpoints, bool, error) {
|
2017-03-17 15:34:34 +00:00
|
|
|
if c.apiEndpointsError != nil {
|
2017-03-22 17:56:14 +00:00
|
|
|
return nil, false, c.apiEndpointsError
|
2017-03-17 15:34:34 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-03-17 15:34:34 +00:00
|
|
|
|
2017-04-13 22:00:25 +00:00
|
|
|
return &v1.Endpoints{}, false, 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
|
|
|
}
|