-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E.g. it could be used to let skipper instance know in which zone it is deployed: ```yaml containers: - env: - name: TOPOLOGY_ZONE valueFrom: fieldRef: fieldPath: metadata.annotations['topology.kubernetes.io/zone'] args: - skipper - -config-predicate-values=zone=$(TOPOLOGY_ZONE) - ... ``` such that it only enables specific route for that zone: ``` za: Path("/foo") && Config("zone", "a") -> "http://backend.zone-a.test"; zb: Path("/foo") && Config("zone", "b") -> "http://backend.zone-b.test"; zc: Path("/foo") && Config("zone", "c") -> "http://backend.zone-c.test"; ``` Signed-off-by: Alexander Yastrebov <[email protected]>
- Loading branch information
1 parent
1817eda
commit 8dee3c7
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package primitive | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/zalando/skipper/predicates" | ||
"github.com/zalando/skipper/routing" | ||
) | ||
|
||
type ( | ||
configSpec struct { | ||
values map[string]string | ||
} | ||
) | ||
|
||
// NewConfig provides a predicate spec to create predicates | ||
// that evaluate to true if config value matches regular expression | ||
func NewConfig(values map[string]string) routing.PredicateSpec { | ||
return &configSpec{values} | ||
} | ||
|
||
func (*configSpec) Name() string { return predicates.ConfigName } | ||
|
||
func (s *configSpec) Create(args []interface{}) (routing.Predicate, error) { | ||
if len(args) != 2 { | ||
return nil, predicates.ErrInvalidPredicateParameters | ||
} | ||
|
||
name, ok := args[0].(string) | ||
if !ok { | ||
return nil, predicates.ErrInvalidPredicateParameters | ||
} | ||
|
||
value, ok := args[1].(string) | ||
if !ok { | ||
return nil, predicates.ErrInvalidPredicateParameters | ||
} | ||
|
||
re, err := regexp.Compile(value) | ||
if err != nil { | ||
return nil, predicates.ErrInvalidPredicateParameters | ||
} | ||
|
||
if re.MatchString(s.values[name]) { | ||
return &truePredicate{}, nil | ||
} else { | ||
return &falsePredicate{}, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters