Skip to content

Commit 52b569a

Browse files
committed
Moved predicate helpers to predicates package
Signed-off-by: Peter Klijn <[email protected]>
1 parent de5a13a commit 52b569a

35 files changed

+385
-423
lines changed

_test_plugins/multitype_noop.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"github.com/zalando/skipper/predicates"
45
"net/http"
56

67
"github.com/zalando/skipper/filters"
@@ -11,8 +12,8 @@ type multiSpec struct {
1112
Type string
1213
}
1314

14-
func InitPlugin(opts []string) ([]filters.Spec, []routing.PredicateSpec, []routing.DataClient, error) {
15-
return []filters.Spec{multiSpec{"noop"}}, []routing.PredicateSpec{multiSpec{"None"}}, nil, nil
15+
func InitPlugin(opts []string) ([]filters.Spec, []predicates.PredicateSpec, []routing.DataClient, error) {
16+
return []filters.Spec{multiSpec{"noop"}}, []predicates.PredicateSpec{multiSpec{"None"}}, nil, nil
1617
}
1718

1819
func (s multiSpec) Name() string {
@@ -23,7 +24,7 @@ func (s multiSpec) CreateFilter(config []interface{}) (filters.Filter, error) {
2324
return noop{}, nil
2425
}
2526

26-
func (s multiSpec) Create(config []interface{}) (routing.Predicate, error) {
27+
func (s multiSpec) Create(config []interface{}) (predicates.Predicate, error) {
2728
return noop{}, nil
2829
}
2930

_test_plugins/predicate_match_none.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package main
22

33
import (
4+
"github.com/zalando/skipper/predicates"
45
"net/http"
5-
6-
"github.com/zalando/skipper/routing"
76
)
87

98
type noneSpec struct{}
109

11-
func InitPredicate(opts []string) (routing.PredicateSpec, error) {
10+
func InitPredicate(opts []string) (predicates.PredicateSpec, error) {
1211
return noneSpec{}, nil
1312
}
1413

1514
func (s noneSpec) Name() string {
1615
return "None"
1716
}
18-
func (s noneSpec) Create(config []interface{}) (routing.Predicate, error) {
17+
func (s noneSpec) Create(config []interface{}) (predicates.Predicate, error) {
1918
return nonePredicate{}, nil
2019
}
2120

_test_plugins_fail/fail.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package main
22

33
import (
4+
"github.com/zalando/skipper/predicates"
45
"net/http"
56

67
"github.com/zalando/skipper/filters"
7-
"github.com/zalando/skipper/routing"
88
)
99

1010
// this fails to load, because it implements multiple Init* functions
@@ -13,7 +13,7 @@ func InitFilter(opts []string) (filters.Spec, error) {
1313
return noopSpec{}, nil
1414
}
1515

16-
func InitPredicate(opts []string) (routing.PredicateSpec, error) {
16+
func InitPredicate(opts []string) (predicates.PredicateSpec, error) {
1717
return noneSpec{}, nil
1818
}
1919

@@ -36,7 +36,7 @@ type noneSpec struct{}
3636
func (s noneSpec) Name() string {
3737
return "None"
3838
}
39-
func (s noneSpec) Create(config []interface{}) (routing.Predicate, error) {
39+
func (s noneSpec) Create(config []interface{}) (predicates.Predicate, error) {
4040
return nonePredicate{}, nil
4141
}
4242

dataclients/kubernetes/ingress.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package kubernetes
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/zalando/skipper/predicates"
67
"regexp"
78
"strconv"
89
"strings"
910

1011
log "github.com/sirupsen/logrus"
1112
"github.com/zalando/skipper/dataclients/kubernetes/definitions"
1213
"github.com/zalando/skipper/eskip"
13-
"github.com/zalando/skipper/predicates/primitive"
14-
"github.com/zalando/skipper/predicates/traffic"
1514
)
1615

1716
const (
@@ -228,14 +227,14 @@ func setTraffic(r *eskip.Route, svcName string, weight float64, noopCount int) {
228227
// add traffic predicate if traffic weight is between 0.0 and 1.0
229228
if 0.0 < weight && weight < 1.0 {
230229
r.Predicates = append([]*eskip.Predicate{{
231-
Name: traffic.TrafficName,
230+
Name: predicates.TrafficName,
232231
Args: []interface{}{weight},
233232
}}, r.Predicates...)
234233
log.Debugf("Traffic weight %.2f for backend '%s'", weight, svcName)
235234
}
236235
for i := 0; i < noopCount; i++ {
237236
r.Predicates = append([]*eskip.Predicate{{
238-
Name: primitive.TrueName,
237+
Name: predicates.TrueName,
239238
Args: []interface{}{},
240239
}}, r.Predicates...)
241240
}

dataclients/kubernetes/kube.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kubernetes
22

33
import (
44
"fmt"
5+
"github.com/zalando/skipper/predicates"
56
"net"
67
"net/http"
78
"os"
@@ -15,7 +16,6 @@ import (
1516
"github.com/zalando/skipper/eskip"
1617
"github.com/zalando/skipper/filters/accesslog"
1718
"github.com/zalando/skipper/filters/builtin"
18-
"github.com/zalando/skipper/predicates/source"
1919
)
2020

2121
const (
@@ -367,12 +367,12 @@ func healthcheckRoute(healthy, reverseSourcePredicate bool) *eskip.Route {
367367
var p []*eskip.Predicate
368368
if reverseSourcePredicate {
369369
p = []*eskip.Predicate{{
370-
Name: source.SourceFromLastName,
370+
Name: predicates.SourceFromLastName,
371371
Args: internalIPs,
372372
}}
373373
} else {
374374
p = []*eskip.Predicate{{
375-
Name: source.SourceName,
375+
Name: predicates.SourceName,
376376
Args: internalIPs,
377377
}}
378378
}

dataclients/kubernetes/kube_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"encoding/pem"
1111
"fmt"
12+
"github.com/zalando/skipper/predicates"
1213
"io"
1314
"io/ioutil"
1415
"math/big"
@@ -34,7 +35,6 @@ import (
3435
"github.com/zalando/skipper/dataclients/kubernetes/definitions"
3536
"github.com/zalando/skipper/eskip"
3637
"github.com/zalando/skipper/filters/builtin"
37-
"github.com/zalando/skipper/predicates/source"
3838
)
3939

4040
type testAPI struct {
@@ -367,10 +367,10 @@ func checkHealthcheck(t *testing.T, got []*eskip.Route, expected, healthy, rever
367367

368368
var found bool
369369
for _, p := range r.Predicates {
370-
if reversed && p.Name != source.SourceFromLastName {
370+
if reversed && p.Name != predicates.SourceFromLastName {
371371
continue
372372
}
373-
if !reversed && p.Name != source.SourceName {
373+
if !reversed && p.Name != predicates.SourceName {
374374
continue
375375
}
376376

dataclients/kubernetes/redirect.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package kubernetes
22

33
import (
44
"fmt"
5+
"github.com/zalando/skipper/predicates"
56
"net/http"
67
"strconv"
78

89
log "github.com/sirupsen/logrus"
910
"github.com/zalando/skipper/dataclients/kubernetes/definitions"
1011
"github.com/zalando/skipper/eskip"
11-
"github.com/zalando/skipper/routing"
1212
)
1313

1414
const (
@@ -91,7 +91,7 @@ func initRedirectRoute(r *eskip.Route, code int) {
9191

9292
// Give this route a higher weight so that it will get precedence over existing routes
9393
r.Predicates = append([]*eskip.Predicate{{
94-
Name: routing.WeightName,
94+
Name: predicates.WeightName,
9595
Args: []interface{}{float64(1000)},
9696
}}, r.Predicates...)
9797

@@ -112,7 +112,7 @@ func initDisableRedirectRoute(r *eskip.Route) {
112112

113113
// Give this route a higher weight so that it will get precedence over existing routes
114114
r.Predicates = append([]*eskip.Predicate{{
115-
Name: routing.WeightName,
115+
Name: predicates.WeightName,
116116
Args: []interface{}{float64(1000)},
117117
}}, r.Predicates...)
118118
}

filters/tee/teeloopback_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/zalando/skipper/eskip"
66
"github.com/zalando/skipper/filters"
7+
"github.com/zalando/skipper/predicates"
78
teePredicate "github.com/zalando/skipper/predicates/tee"
89
"github.com/zalando/skipper/predicates/traffic"
910
"github.com/zalando/skipper/proxy/backendtest"
@@ -45,7 +46,7 @@ func TestLoopbackAndMatchPredicate(t *testing.T) {
4546
registry := make(filters.Registry)
4647
registry.Register(NewTeeLoopback())
4748
p := proxytest.WithRoutingOptions(registry, routing.Options{
48-
Predicates: []routing.PredicateSpec{
49+
Predicates: []predicates.PredicateSpec{
4950
teePredicate.New(),
5051
traffic.New(),
5152
},
@@ -78,7 +79,7 @@ func TestOriginalBackendServeEvenWhenShadowDoesNotReply(t *testing.T) {
7879
registry := make(filters.Registry)
7980
registry.Register(NewTeeLoopback())
8081
p := proxytest.WithRoutingOptions(registry, routing.Options{
81-
Predicates: []routing.PredicateSpec{
82+
Predicates: []predicates.PredicateSpec{
8283
teePredicate.New(),
8384
traffic.New(),
8485
},
@@ -109,7 +110,7 @@ func TestOriginalBackendServeEvenWhenShadowIsDown(t *testing.T) {
109110
registry := make(filters.Registry)
110111
registry.Register(NewTeeLoopback())
111112
p := proxytest.WithRoutingOptions(registry, routing.Options{
112-
Predicates: []routing.PredicateSpec{
113+
Predicates: []predicates.PredicateSpec{
113114
teePredicate.New(),
114115
traffic.New(),
115116
},
@@ -137,7 +138,7 @@ func TestInfiniteLoopback(t *testing.T) {
137138
registry := make(filters.Registry)
138139
registry.Register(NewTeeLoopback())
139140
p := proxytest.WithRoutingOptions(registry, routing.Options{
140-
Predicates: []routing.PredicateSpec{
141+
Predicates: []predicates.PredicateSpec{
141142
teePredicate.New(),
142143
},
143144
}, routes...)

helpers/predicates/predicates_test.go

-128
This file was deleted.

0 commit comments

Comments
 (0)