Add Marathon TLS client config
Signed-off-by: emile <emile@vauge.com>
This commit is contained in:
parent
c7d34b54aa
commit
9a9c8e5709
6 changed files with 887 additions and 32 deletions
|
@ -7,10 +7,12 @@ import (
|
|||
"strings"
|
||||
"text/template"
|
||||
|
||||
"crypto/tls"
|
||||
"github.com/BurntSushi/ty/fun"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/emilevauge/traefik/types"
|
||||
"github.com/gambol99/go-marathon"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Marathon holds configuration of the Marathon provider.
|
||||
|
@ -20,7 +22,8 @@ type Marathon struct {
|
|||
Domain string
|
||||
NetworkInterface string
|
||||
Basic *MarathonBasic
|
||||
marathonClient lightMarathonClient
|
||||
TLS *tls.Config
|
||||
marathonClient marathon.Marathon
|
||||
}
|
||||
|
||||
// MarathonBasic holds basic authentication specific configurations
|
||||
|
@ -44,6 +47,11 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage)
|
|||
config.HTTPBasicAuthUser = provider.Basic.HTTPBasicAuthUser
|
||||
config.HTTPBasicPassword = provider.Basic.HTTPBasicPassword
|
||||
}
|
||||
config.HTTPClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: provider.TLS,
|
||||
},
|
||||
}
|
||||
client, err := marathon.NewClient(config)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to create a client for marathon, error: %s", err)
|
||||
|
@ -100,7 +108,7 @@ func (provider *Marathon) loadMarathonConfig() *types.Configuration {
|
|||
return nil
|
||||
}
|
||||
|
||||
tasks, err := provider.marathonClient.AllTasks((url.Values{"status": []string{"running"}}))
|
||||
tasks, err := provider.marathonClient.AllTasks(&marathon.AllTasksOpts{Status: "running"})
|
||||
if err != nil {
|
||||
log.Errorf("Failed to create a client for marathon, error: %s", err)
|
||||
return nil
|
||||
|
@ -190,7 +198,7 @@ func taskFilter(task marathon.Task, applications *marathon.Applications) bool {
|
|||
//filter healthchecks
|
||||
if application.HasHealthChecks() {
|
||||
if task.HasHealthCheckResults() {
|
||||
for _, healthcheck := range task.HealthCheckResult {
|
||||
for _, healthcheck := range task.HealthCheckResults {
|
||||
// found one bad healthcheck, return false
|
||||
if !healthcheck.Alive {
|
||||
log.Debugf("Filtering marathon task %s with bad healthcheck", task.AppID)
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
package provider
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"errors"
|
||||
"github.com/emilevauge/traefik/mocks"
|
||||
"github.com/emilevauge/traefik/types"
|
||||
"github.com/gambol99/go-marathon"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type fakeClient struct {
|
||||
applicationsError bool
|
||||
applications *marathon.Applications
|
||||
tasksError bool
|
||||
tasks *marathon.Tasks
|
||||
mocks.Marathon
|
||||
}
|
||||
|
||||
func (c *fakeClient) Applications(url.Values) (*marathon.Applications, error) {
|
||||
if c.applicationsError {
|
||||
return nil, errors.New("error")
|
||||
func newFakeClient(applicationsError bool, applications *marathon.Applications, tasksError bool, tasks *marathon.Tasks) *fakeClient {
|
||||
// create an instance of our test object
|
||||
fakeClient := new(fakeClient)
|
||||
if applicationsError {
|
||||
fakeClient.On("Applications", mock.AnythingOfType("url.Values")).Return(nil, errors.New("error"))
|
||||
}
|
||||
return c.applications, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) AllTasks(v url.Values) (*marathon.Tasks, error) {
|
||||
if c.tasksError {
|
||||
return nil, errors.New("error")
|
||||
fakeClient.On("Applications", mock.AnythingOfType("url.Values")).Return(applications, nil)
|
||||
if tasksError {
|
||||
fakeClient.On("AllTasks", mock.AnythingOfType("*marathon.AllTasksOpts")).Return(nil, errors.New("error"))
|
||||
}
|
||||
return c.tasks, nil
|
||||
fakeClient.On("AllTasks", mock.AnythingOfType("*marathon.AllTasksOpts")).Return(tasks, nil)
|
||||
return fakeClient
|
||||
}
|
||||
|
||||
func TestMarathonLoadConfig(t *testing.T) {
|
||||
|
@ -110,14 +108,10 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, c := range cases {
|
||||
fakeClient := newFakeClient(c.applicationsError, c.applications, c.tasksError, c.tasks)
|
||||
provider := &Marathon{
|
||||
Domain: "docker.localhost",
|
||||
marathonClient: &fakeClient{
|
||||
applicationsError: c.applicationsError,
|
||||
applications: c.applications,
|
||||
tasksError: c.tasksError,
|
||||
tasks: c.tasks,
|
||||
},
|
||||
Domain: "docker.localhost",
|
||||
marathonClient: fakeClient,
|
||||
}
|
||||
actualConfig := provider.loadMarathonConfig()
|
||||
if c.expectedNil {
|
||||
|
@ -315,7 +309,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
|||
task: marathon.Task{
|
||||
AppID: "foo",
|
||||
Ports: []int{80},
|
||||
HealthCheckResult: []*marathon.HealthCheckResult{
|
||||
HealthCheckResults: []*marathon.HealthCheckResult{
|
||||
{
|
||||
Alive: false,
|
||||
},
|
||||
|
@ -338,7 +332,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
|||
task: marathon.Task{
|
||||
AppID: "foo",
|
||||
Ports: []int{80},
|
||||
HealthCheckResult: []*marathon.HealthCheckResult{
|
||||
HealthCheckResults: []*marathon.HealthCheckResult{
|
||||
{
|
||||
Alive: true,
|
||||
},
|
||||
|
@ -379,7 +373,7 @@ func TestMarathonTaskFilter(t *testing.T) {
|
|||
task: marathon.Task{
|
||||
AppID: "foo",
|
||||
Ports: []int{80},
|
||||
HealthCheckResult: []*marathon.HealthCheckResult{
|
||||
HealthCheckResults: []*marathon.HealthCheckResult{
|
||||
{
|
||||
Alive: true,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue