1
0
mirror of https://github.com/containous/traefik.git synced 2024-12-22 13:34:03 +03:00

Minor changes

This commit is contained in:
Ludovic Fernandez 2018-07-03 10:02:03 +02:00 committed by Traefiker Bot
parent bb14ec70bd
commit 17ad5153b8
38 changed files with 93 additions and 182 deletions

View File

@ -152,7 +152,7 @@ func (d *Datastore) Begin() (Transaction, Object, error) {
operation := func() error {
meta := d.get()
if meta.Lock != id {
return fmt.Errorf("Object lock value: expected %s, got %s", id, meta.Lock)
return fmt.Errorf("object lock value: expected %s, got %s", id, meta.Lock)
}
return nil
}
@ -167,7 +167,7 @@ func (d *Datastore) Begin() (Transaction, Object, error) {
ebo.MaxElapsedTime = 60 * time.Second
err = backoff.RetryNotify(safe.OperationWithRecover(operation), ebo, notify)
if err != nil {
return nil, nil, fmt.Errorf("Datastore cannot sync: %v", err)
return nil, nil, fmt.Errorf("datastore cannot sync: %v", err)
}
// we synced with KV store, we can now return Setter
@ -224,12 +224,12 @@ func (s *datastoreTransaction) Commit(object Object) error {
s.localLock.Lock()
defer s.localLock.Unlock()
if s.dirty {
return fmt.Errorf("Transaction already used, please begin a new one")
return fmt.Errorf("transaction already used, please begin a new one")
}
s.Datastore.meta.object = object
err := s.Datastore.meta.Marshall()
if err != nil {
return fmt.Errorf("Marshall error: %s", err)
return fmt.Errorf("marshall error: %s", err)
}
err = s.kv.StoreConfig(s.Datastore.meta)
if err != nil {
@ -238,7 +238,7 @@ func (s *datastoreTransaction) Commit(object Object) error {
err = s.remoteLock.Unlock()
if err != nil {
return fmt.Errorf("Unlock error: %s", err)
return fmt.Errorf("unlock error: %s", err)
}
s.dirty = true

View File

@ -288,7 +288,7 @@ func TestWithMiddleware(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/test", nil)
internalMuxRouter.ServeHTTP(recorder, request)
obtained := string(recorder.Body.Bytes())
obtained := recorder.Body.String()
assert.Equal(t, "before middleware1|before middleware2|router|after middleware2|after middleware1", obtained)
}

View File

@ -81,7 +81,7 @@ Træfik can be configured with a file.
trustForwardHeader = true
authResponseHeaders = ["X-Auth-User"]
[frontends.frontend1.auth.forward.tls]
ca = [ "path/to/local.crt"]
ca = "path/to/local.crt"
caOptional = true
cert = "path/to/foo.cert"
key = "path/to/foo.key"

View File

@ -56,7 +56,7 @@
trustForwardHeader = true
authResponseHeaders = ["X-Auth-User"]
[entryPoints.http.auth.forward.tls]
ca = [ "path/to/local.crt"]
ca = "path/to/local.crt"
caOptional = true
cert = "path/to/foo.cert"
key = "path/to/foo.key"
@ -347,7 +347,7 @@ Otherwise, the response from the authentication server is returned.
# Optional
#
[entryPoints.http.auth.forward.tls]
ca = [ "path/to/local.crt"]
ca = "path/to/local.crt"
caOptional = true
cert = "path/to/foo.cert"
key = "path/to/foo.key"

View File

@ -45,7 +45,6 @@ func init() {
// to provide an http.Server.
type Server struct {
*http.Server
originalHandler http.Handler
}
// Serve Put a middleware around the original handler to handle h2c
@ -101,6 +100,9 @@ func initH2CWithPriorKnowledge(w http.ResponseWriter) (net.Conn, error) {
buf := make([]byte, len(expectedBody))
n, err := io.ReadFull(rw, buf)
if err != nil {
return nil, fmt.Errorf("fail to read body: %v", err)
}
if bytes.Equal(buf[0:n], []byte(expectedBody)) {
c := &rwConn{
@ -132,7 +134,7 @@ func drainClientPreface(r io.Reader) error {
return err
}
if n != prefaceLen || buf.String() != http2.ClientPreface {
return fmt.Errorf("Client never sent: %s", http2.ClientPreface)
return fmt.Errorf("client never sent: %s", http2.ClientPreface)
}
return nil
}
@ -363,7 +365,7 @@ func getH2Settings(h http.Header) ([]http2.Setting, error) {
}
settings, err := decodeSettings(vals[0])
if err != nil {
return nil, fmt.Errorf("Invalid HTTP2-Settings: %q", vals[0])
return nil, fmt.Errorf("invalid HTTP2-Settings: %q", vals[0])
}
return settings, nil
}

View File

@ -28,7 +28,7 @@ func (s *SimpleSuite) TestInvalidConfigShouldFail(c *check.C) {
actual := output.String()
if !strings.Contains(actual, expected) {
return fmt.Errorf("Got %s, wanted %s", actual, expected)
return fmt.Errorf("got %s, wanted %s", actual, expected)
}
return nil
@ -72,7 +72,7 @@ func (s *SimpleSuite) TestDefaultEntryPoints(c *check.C) {
actual := output.String()
if !strings.Contains(actual, expected) {
return fmt.Errorf("Got %s, wanted %s", actual, expected)
return fmt.Errorf("got %s, wanted %s", actual, expected)
}
return nil
@ -93,10 +93,10 @@ func (s *SimpleSuite) TestPrintHelp(c *check.C) {
actual := output.String()
if strings.Contains(actual, notExpected) {
return fmt.Errorf("Got %s", actual)
return fmt.Errorf("got %s", actual)
}
if !strings.Contains(actual, expected) {
return fmt.Errorf("Got %s, wanted %s", actual, expected)
return fmt.Errorf("got %s, wanted %s", actual, expected)
}
return nil

View File

@ -469,7 +469,7 @@ func datastoreContains(datastore *cluster.Datastore, expectedValue string) func(
return func() error {
kvStruct := datastore.Get().(*TestStruct)
if kvStruct.String != expectedValue {
return fmt.Errorf("Got %s, wanted %s", kvStruct.String, expectedValue)
return fmt.Errorf("got %s, wanted %s", kvStruct.String, expectedValue)
}
return nil
}

View File

@ -41,7 +41,7 @@ func (s *DockerComposeSuite) TestComposeScale(c *check.C) {
s.composeProject.Scale(c, composeService, serviceCount)
file := s.adaptFileForHost(c, "fixtures/docker/simple.toml")
file := s.adaptFileForHost(c, "fixtures/docker/minimal.toml")
defer os.Remove(file)
cmd, display := s.traefikCmd(withConfigFile(file))

View File

@ -0,0 +1,14 @@
defaultEntryPoints = ["http"]
logLevel = "DEBUG"
[entryPoints]
[entryPoints.http]
address = ":8000"
[api]
[docker]
endpoint = "{{.DockerHost}}"
domain = "docker.localhost"
exposedByDefault = false

View File

@ -9,9 +9,6 @@ logLevel = "DEBUG"
[api]
[docker]
# It's dynamagic !
endpoint = "{{.DockerHost}}"
domain = "docker.localhost"
exposedByDefault = true

View File

@ -8,7 +8,7 @@ import (
"github.com/containous/traefik/integration/try"
"github.com/containous/traefik/provider/label"
marathon "github.com/gambol99/go-marathon"
"github.com/gambol99/go-marathon"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)

View File

@ -2,3 +2,4 @@ whoami1:
image: emilevauge/whoami
labels:
- traefik.frontend.rule=PathPrefix:/whoami
- traefik.enable=true

View File

@ -82,7 +82,7 @@ func HasBody() ResponseCondition {
}
if len(body) == 0 {
return errors.New("Response doesn't have body content")
return errors.New("response doesn't have body content")
}
return nil
}

View File

@ -154,17 +154,16 @@ func (w *influxDBWriter) Write(bp influxdb.BatchPoints) error {
return nil
}
func (w *influxDBWriter) initWriteClient() (c influxdb.Client, err error) {
func (w *influxDBWriter) initWriteClient() (influxdb.Client, error) {
if w.config.Protocol == "http" {
c, err = influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: w.config.Address,
})
} else {
c, err = influxdb.NewUDPClient(influxdb.UDPConfig{
return influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: w.config.Address,
})
}
return
return influxdb.NewUDPClient(influxdb.UDPConfig{
Addr: w.config.Address,
})
}
func (w *influxDBWriter) handleWriteError(c influxdb.Client, writeErr error) error {

View File

@ -9,6 +9,7 @@ import (
type Registry interface {
// IsEnabled shows whether metrics instrumentation is enabled.
IsEnabled() bool
// server metrics
ConfigReloadsCounter() metrics.Counter
ConfigReloadsFailureCounter() metrics.Counter
@ -38,18 +39,18 @@ func NewVoidRegistry() Registry {
// It handles the case when a registry hasn't registered some metric and returns nil.
// This allows for feature imparity between the different metric implementations.
func NewMultiRegistry(registries []Registry) Registry {
configReloadsCounter := []metrics.Counter{}
configReloadsFailureCounter := []metrics.Counter{}
lastConfigReloadSuccessGauge := []metrics.Gauge{}
lastConfigReloadFailureGauge := []metrics.Gauge{}
entrypointReqsCounter := []metrics.Counter{}
entrypointReqDurationHistogram := []metrics.Histogram{}
entrypointOpenConnsGauge := []metrics.Gauge{}
backendReqsCounter := []metrics.Counter{}
backendReqDurationHistogram := []metrics.Histogram{}
backendOpenConnsGauge := []metrics.Gauge{}
backendRetriesCounter := []metrics.Counter{}
backendServerUpGauge := []metrics.Gauge{}
var configReloadsCounter []metrics.Counter
var configReloadsFailureCounter []metrics.Counter
var lastConfigReloadSuccessGauge []metrics.Gauge
var lastConfigReloadFailureGauge []metrics.Gauge
var entrypointReqsCounter []metrics.Counter
var entrypointReqDurationHistogram []metrics.Histogram
var entrypointOpenConnsGauge []metrics.Gauge
var backendReqsCounter []metrics.Counter
var backendReqDurationHistogram []metrics.Histogram
var backendOpenConnsGauge []metrics.Gauge
var backendRetriesCounter []metrics.Counter
var backendServerUpGauge []metrics.Gauge
for _, r := range registries {
if r.ConfigReloadsCounter() != nil {

View File

@ -49,7 +49,7 @@ func (crw *captureResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
if h, ok := crw.rw.(http.Hijacker); ok {
return h.Hijack()
}
return nil, nil, fmt.Errorf("Not a hijacker: %T", crw.rw)
return nil, nil, fmt.Errorf("not a hijacker: %T", crw.rw)
}
func (crw *captureResponseWriter) CloseNotify() <-chan bool {

View File

@ -72,7 +72,7 @@ func TestBasicAuthFail(t *testing.T) {
Users: []string{"test"},
},
}, &tracing.Tracing{})
assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains")
assert.Contains(t, err.Error(), "error parsing Authenticator user", "should contains")
authMiddleware, err := NewAuthenticator(&types.Auth{
Basic: &types.Basic{
@ -131,7 +131,7 @@ func TestDigestAuthFail(t *testing.T) {
Users: []string{"test"},
},
}, &tracing.Tracing{})
assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains")
assert.Contains(t, err.Error(), "error parsing Authenticator user", "should contains")
authMiddleware, err := NewAuthenticator(&types.Auth{
Digest: &types.Digest{

View File

@ -20,7 +20,7 @@ func parserBasicUsers(basic *types.Basic) (map[string]string, error) {
for _, user := range userStrs {
split := strings.Split(user, ":")
if len(split) != 2 {
return nil, fmt.Errorf("Error parsing Authenticator user: %v", user)
return nil, fmt.Errorf("error parsing Authenticator user: %v", user)
}
userMap[split[0]] = split[1]
}
@ -40,7 +40,7 @@ func parserDigestUsers(digest *types.Digest) (map[string]string, error) {
for _, user := range userStrs {
split := strings.Split(user, ":")
if len(split) != 3 {
return nil, fmt.Errorf("Error parsing Authenticator user: %v", user)
return nil, fmt.Errorf("error parsing Authenticator user: %v", user)
}
userMap[split[0]+":"+split[1]] = split[2]
}

View File

@ -12,7 +12,7 @@ import (
// Compress is a middleware that allows redirection
type Compress struct{}
// ServerHTTP is a function used by Negroni
// ServeHTTP is a function used by Negroni
func (c *Compress) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
contentType := r.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "application/grpc") {

View File

@ -21,8 +21,8 @@ func NewRoutes(router *mux.Router) *Routes {
func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
routeMatch := mux.RouteMatch{}
if router.router.Match(r, &routeMatch) {
json, _ := json.Marshal(routeMatch.Handler)
log.Println("Request match route ", json)
rt, _ := json.Marshal(routeMatch.Handler)
log.Println("Request match route ", rt)
}
next(rw, r)
}

View File

@ -4,7 +4,7 @@ import (
"io"
"github.com/containous/traefik/log"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
)

View File

@ -4,5 +4,5 @@ package docker
const (
// DockerAPIVersion is a constant holding the version of the Provider API traefik will use
DockerAPIVersion string = "1.21"
DockerAPIVersion = "1.21"
)

View File

@ -496,87 +496,6 @@ func TestFilterInstance(t *testing.T) {
}
}
func TestChunkedTaskArns(t *testing.T) {
testVal := "a"
testCases := []struct {
desc string
count int
expectedLengths []int
}{
{
desc: "0 parameter should return nil",
count: 0,
expectedLengths: []int(nil),
},
{
desc: "1 parameter should return 1 array of 1 element",
count: 1,
expectedLengths: []int{1},
},
{
desc: "99 parameters should return 1 array of 99 elements",
count: 99,
expectedLengths: []int{99},
},
{
desc: "100 parameters should return 1 array of 100 elements",
count: 100,
expectedLengths: []int{100},
},
{
desc: "101 parameters should return 1 array of 100 elements and 1 array of 1 element",
count: 101,
expectedLengths: []int{100, 1},
},
{
desc: "199 parameters should return 1 array of 100 elements and 1 array of 99 elements",
count: 199,
expectedLengths: []int{100, 99},
},
{
desc: "200 parameters should return 2 arrays of 100 elements each",
count: 200,
expectedLengths: []int{100, 100},
},
{
desc: "201 parameters should return 2 arrays of 100 elements each and 1 array of 1 element",
count: 201,
expectedLengths: []int{100, 100, 1},
},
{
desc: "555 parameters should return 5 arrays of 100 elements each and 1 array of 55 elements",
count: 555,
expectedLengths: []int{100, 100, 100, 100, 100, 55},
},
{
desc: "1001 parameters should return 10 arrays of 100 elements each and 1 array of 1 element",
count: 1001,
expectedLengths: []int{100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1},
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
var tasks []*string
for v := 0; v < test.count; v++ {
tasks = append(tasks, &testVal)
}
out := chunkedTaskArns(tasks)
var outCount []int
for _, el := range out {
outCount = append(outCount, len(el))
}
assert.Equal(t, test.expectedLengths, outCount, "Chunking %d elements", test.count)
})
}
}
func TestGetHost(t *testing.T) {
testCases := []struct {
desc string

View File

@ -227,7 +227,7 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI
Cluster: &c,
})
if err != nil {
log.Errorf("Unable to describe tasks for %s", page.TaskArns)
log.Errorf("Unable to describe tasks for %v", page.TaskArns)
} else {
for _, t := range resp.Tasks {
tasks[aws.StringValue(t.TaskArn)] = t
@ -396,19 +396,3 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types
return p.buildConfiguration(instances)
}
// Provider expects no more than 100 parameters be passed to a DescribeTask call; thus, pack
// each string into an array capped at 100 elements
func chunkedTaskArns(tasks []*string) [][]*string {
var chunkedTasks [][]*string
for i := 0; i < len(tasks); i += 100 {
var sliceEnd int
if i+100 < len(tasks) {
sliceEnd = i + 100
} else {
sliceEnd = len(tasks)
}
chunkedTasks = append(chunkedTasks, tasks[i:sliceEnd])
}
return chunkedTasks
}

View File

@ -2165,7 +2165,7 @@ func TestTLSSecretLoad(t *testing.T) {
},
},
}
endpoints := []*corev1.Endpoints{}
var endpoints []*corev1.Endpoints
watchChan := make(chan interface{})
client := clientMock{
ingresses: ingresses,

View File

@ -30,15 +30,9 @@ const (
)
var (
// RegexpBaseFrontendErrorPage used to extract error pages from service's label
RegexpBaseFrontendErrorPage = regexp.MustCompile(`^frontend\.errors\.(?P<name>[^ .]+)\.(?P<field>[^ .]+)$`)
// RegexpFrontendErrorPage used to extract error pages from label
RegexpFrontendErrorPage = regexp.MustCompile(`^traefik\.frontend\.errors\.(?P<name>[^ .]+)\.(?P<field>[^ .]+)$`)
// RegexpBaseFrontendRateLimit used to extract rate limits from service's label
RegexpBaseFrontendRateLimit = regexp.MustCompile(`^frontend\.rateLimit\.rateSet\.(?P<name>[^ .]+)\.(?P<field>[^ .]+)$`)
// RegexpFrontendRateLimit used to extract rate limits from label
RegexpFrontendRateLimit = regexp.MustCompile(`^traefik\.frontend\.rateLimit\.rateSet\.(?P<name>[^ .]+)\.(?P<field>[^ .]+)$`)
)

View File

@ -4,7 +4,7 @@ import (
"time"
"github.com/containous/traefik/log"
marathon "github.com/gambol99/go-marathon"
"github.com/gambol99/go-marathon"
)
const (

View File

@ -37,7 +37,7 @@ func TestBuilder(t *testing.T) {
DiscoveryInfo: state.DiscoveryInfo{
Name: "name1",
Labels: struct {
Labels []state.Label "json:\"labels\""
Labels []state.Label `json:"labels"`
}{},
Ports: state.Ports{DiscoveryPorts: []state.DiscoveryPort{
{Protocol: "TCP", Number: 80, Name: "p"},
@ -63,7 +63,7 @@ func aTaskData(id, segment string, ops ...func(*state.Task)) taskData {
}
func segmentedTaskData(segments []string, ts state.Task) []taskData {
td := []taskData{}
var td []taskData
lbls := label.ExtractTraefikLabels(extractLabels(ts))
for _, s := range segments {
if l, ok := lbls[s]; !ok {

View File

@ -154,7 +154,7 @@ func OperationWithRecover(operation backoff.Operation) backoff.Operation {
defer func() {
if res := recover(); res != nil {
defaultRecoverGoroutine(res)
err = fmt.Errorf("Panic in operation: %s", err)
err = fmt.Errorf("panic in operation: %s", err)
}
}()
return operation()