Fix namespace, fix PathPrefixStrip
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
9e14619a0b
commit
cac9927395
3 changed files with 7 additions and 8 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
const (
|
const (
|
||||||
// APIEndpoint defines the base path for kubernetes API resources.
|
// APIEndpoint defines the base path for kubernetes API resources.
|
||||||
APIEndpoint = "/api/v1"
|
APIEndpoint = "/api/v1"
|
||||||
defaultService = "/namespaces/default/services"
|
|
||||||
extentionsEndpoint = "/apis/extensions/v1beta1"
|
extentionsEndpoint = "/apis/extensions/v1beta1"
|
||||||
defaultIngress = "/ingresses"
|
defaultIngress = "/ingresses"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +23,7 @@ const (
|
||||||
type Client interface {
|
type Client interface {
|
||||||
GetIngresses(predicate func(Ingress) bool) ([]Ingress, error)
|
GetIngresses(predicate func(Ingress) bool) ([]Ingress, error)
|
||||||
WatchIngresses(predicate func(Ingress) bool, stopCh <-chan bool) (chan interface{}, chan error, error)
|
WatchIngresses(predicate func(Ingress) bool, stopCh <-chan bool) (chan interface{}, chan error, error)
|
||||||
GetServices(predicate func(Service) bool) ([]Service, error)
|
GetServices(namespace string, predicate func(Service) bool) ([]Service, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientImpl struct {
|
type clientImpl struct {
|
||||||
|
@ -136,8 +135,8 @@ func (c *clientImpl) WatchIngresses(predicate func(Ingress) bool, stopCh <-chan
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServices returns all services in the cluster
|
// GetServices returns all services in the cluster
|
||||||
func (c *clientImpl) GetServices(predicate func(Service) bool) ([]Service, error) {
|
func (c *clientImpl) GetServices(namespace string, predicate func(Service) bool) ([]Service, error) {
|
||||||
getURL := c.endpointURL + APIEndpoint + defaultService
|
getURL := c.endpointURL + APIEndpoint + "/namespaces/" + namespace + "/services"
|
||||||
|
|
||||||
// Make request to Kubernetes API
|
// Make request to Kubernetes API
|
||||||
request := gorequest.New().Get(getURL)
|
request := gorequest.New().Get(getURL)
|
||||||
|
|
|
@ -136,10 +136,10 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
|
||||||
}
|
}
|
||||||
if len(pa.Path) > 0 {
|
if len(pa.Path) > 0 {
|
||||||
templateObjects.Frontends[r.Host+pa.Path].Routes[pa.Path] = types.Route{
|
templateObjects.Frontends[r.Host+pa.Path].Routes[pa.Path] = types.Route{
|
||||||
Rule: "PathStrip:" + pa.Path,
|
Rule: "PathPrefixStrip:" + pa.Path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
services, err := k8sClient.GetServices(func(service k8s.Service) bool {
|
services, err := k8sClient.GetServices(i.Namespace, func(service k8s.Service) bool {
|
||||||
return service.Name == pa.Backend.ServiceName
|
return service.Name == pa.Backend.ServiceName
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -142,7 +142,7 @@ func TestLoadIngresses(t *testing.T) {
|
||||||
Backend: "foo/bar",
|
Backend: "foo/bar",
|
||||||
Routes: map[string]types.Route{
|
Routes: map[string]types.Route{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathStrip:/bar",
|
Rule: "PathPrefixStrip:/bar",
|
||||||
},
|
},
|
||||||
"foo": {
|
"foo": {
|
||||||
Rule: "Host:foo",
|
Rule: "Host:foo",
|
||||||
|
@ -179,6 +179,6 @@ func (c clientMock) GetIngresses(predicate func(k8s.Ingress) bool) ([]k8s.Ingres
|
||||||
func (c clientMock) WatchIngresses(predicate func(k8s.Ingress) bool, stopCh <-chan bool) (chan interface{}, chan error, error) {
|
func (c clientMock) WatchIngresses(predicate func(k8s.Ingress) bool, stopCh <-chan bool) (chan interface{}, chan error, error) {
|
||||||
return c.watchChan, make(chan error), nil
|
return c.watchChan, make(chan error), nil
|
||||||
}
|
}
|
||||||
func (c clientMock) GetServices(predicate func(k8s.Service) bool) ([]k8s.Service, error) {
|
func (c clientMock) GetServices(namespace string, predicate func(k8s.Service) bool) ([]k8s.Service, error) {
|
||||||
return c.services, nil
|
return c.services, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue