Add HTTP Provider

* feat: add HTTP provider implementation

* refactor: add SetDefaults and struct tag for the new file parser

* feat: add TLS configuration property

* refactor: rework HTTP provider implementation

* feat: provide config only once if fetched config is unchanged

* style: lint

* ui: add HTTP provider icon

* tests: simplify and fix integration test

* docs: add reference config for file

* docs: move http reference config for file

Co-authored-by: Daniel Tomcej <daniel.tomcej@gmail.com>
This commit is contained in:
Kevin Pollet 2020-07-15 16:56:03 +02:00 committed by GitHub
parent 285ded6e49
commit 1ef93fead7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 816 additions and 1 deletions

View file

@ -0,0 +1,20 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":8000"
[entryPoints.traefik]
address = ":9090"
[api]
insecure = true
[providers]
[providers.http]
endpoint = "http://127.0.0.1:9000"
pollInterval = "100ms"

87
integration/http_test.go Normal file
View file

@ -0,0 +1,87 @@
package integration
import (
"encoding/json"
"net"
"net/http"
"net/http/httptest"
"time"
"github.com/containous/traefik/v2/integration/try"
"github.com/containous/traefik/v2/pkg/config/dynamic"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)
type HTTPSuite struct{ BaseSuite }
func (s *HTTPSuite) TestSimpleConfiguration(c *check.C) {
cmd, display := s.traefikCmd(withConfigFile("fixtures/http/simple.toml"))
defer display(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
// Expect a 404 as we configured nothing.
err = try.GetRequest("http://127.0.0.1:8000/", time.Second, try.StatusCodeIs(http.StatusNotFound))
c.Assert(err, checker.IsNil)
// Provide a configuration, fetched by Traefik provider.
configuration := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"routerHTTP": {
EntryPoints: []string{"web"},
Middlewares: []string{},
Service: "serviceHTTP",
Rule: "PathPrefix(`/`)",
},
},
Services: map[string]*dynamic.Service{
"serviceHTTP": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: boolRef(true),
Servers: []dynamic.Server{
{
URL: "http://bacon:80",
},
},
},
},
},
},
}
configData, err := json.Marshal(configuration)
c.Assert(err, checker.IsNil)
server := startTestServerWithResponse(configData)
defer server.Close()
// Expect configuration to be applied.
err = try.GetRequest("http://127.0.0.1:9090/api/rawdata", 3*time.Second, try.BodyContains("routerHTTP@http", "serviceHTTP@http", "http://bacon:80"))
c.Assert(err, checker.IsNil)
}
func startTestServerWithResponse(response []byte) (ts *httptest.Server) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(response)
})
listener, err := net.Listen("tcp", "127.0.0.1:9000")
if err != nil {
panic(err)
}
ts = &httptest.Server{
Listener: listener,
Config: &http.Server{Handler: handler},
}
ts.Start()
return ts
}
func boolRef(b bool) *bool {
return &b
}

View file

@ -49,6 +49,7 @@ func Test(t *testing.T) {
check.Suite(&HealthCheckSuite{})
check.Suite(&HeadersSuite{})
check.Suite(&HostResolverSuite{})
check.Suite(&HTTPSuite{})
check.Suite(&HTTPSSuite{})
check.Suite(&KeepAliveSuite{})
check.Suite(&LogRotationSuite{})