1
0
Fork 0

Merge branch 'v1.5' into master

This commit is contained in:
Fernandez Ludovic 2018-01-24 11:57:06 +01:00
commit c8446c2dc8
40 changed files with 493 additions and 234 deletions

View file

@ -186,7 +186,7 @@ func loadFileConfigFromDirectory(directory string, configuration *types.Configur
}
}
for _, conf := range c.TLSConfiguration {
for _, conf := range c.TLS {
if _, exists := configTLSMaps[conf]; exists {
log.Warnf("TLS Configuration %v already configured, skipping", conf)
} else {
@ -196,7 +196,7 @@ func loadFileConfigFromDirectory(directory string, configuration *types.Configur
}
for conf := range configTLSMaps {
configuration.TLSConfiguration = append(configuration.TLSConfiguration, conf)
configuration.TLS = append(configuration.TLS, conf)
}
return configuration, nil
}

View file

@ -26,7 +26,7 @@ func TestProvideSingleFileAndWatch(t *testing.T) {
tempDir, "simple.toml",
createFrontendConfiguration(expectedNumFrontends),
createBackendConfiguration(expectedNumBackends),
createTLSConfiguration(expectedNumTLSConf))
createTLS(expectedNumTLSConf))
configurationChan, signal := createConfigurationRoutine(t, &expectedNumFrontends, &expectedNumBackends, &expectedNumTLSConf)
@ -45,7 +45,7 @@ func TestProvideSingleFileAndWatch(t *testing.T) {
tempDir, "simple.toml",
createFrontendConfiguration(expectedNumFrontends),
createBackendConfiguration(expectedNumBackends),
createTLSConfiguration(expectedNumTLSConf))
createTLS(expectedNumTLSConf))
err = waitForSignal(signal, 2*time.Second, "single frontend, backend, TLS configuration")
assert.NoError(t, err)
@ -63,7 +63,7 @@ func TestProvideSingleFileAndNotWatch(t *testing.T) {
tempDir, "simple.toml",
createFrontendConfiguration(expectedNumFrontends),
createBackendConfiguration(expectedNumBackends),
createTLSConfiguration(expectedNumTLSConf))
createTLS(expectedNumTLSConf))
configurationChan, signal := createConfigurationRoutine(t, &expectedNumFrontends, &expectedNumBackends, &expectedNumTLSConf)
@ -82,7 +82,7 @@ func TestProvideSingleFileAndNotWatch(t *testing.T) {
tempDir, "simple.toml",
createFrontendConfiguration(expectedNumFrontends),
createBackendConfiguration(expectedNumBackends),
createTLSConfiguration(expectedNumTLSConf))
createTLS(expectedNumTLSConf))
// Must fail because we don't watch the changes
err = waitForSignal(signal, 2*time.Second, "single frontend, backend and TLS configuration")
@ -99,7 +99,7 @@ func TestProvideDirectoryAndWatch(t *testing.T) {
tempFile1 := createRandomFile(t, tempDir, createFrontendConfiguration(expectedNumFrontends))
tempFile2 := createRandomFile(t, tempDir, createBackendConfiguration(expectedNumBackends))
tempFile3 := createRandomFile(t, tempDir, createTLSConfiguration(expectedNumTLSConf))
tempFile3 := createRandomFile(t, tempDir, createTLS(expectedNumTLSConf))
configurationChan, signal := createConfigurationRoutine(t, &expectedNumFrontends, &expectedNumBackends, &expectedNumTLSConf)
@ -145,7 +145,7 @@ func TestProvideDirectoryAndNotWatch(t *testing.T) {
createRandomFile(t, tempDir, createFrontendConfiguration(expectedNumFrontends))
tempFile2 := createRandomFile(t, tempDir, createBackendConfiguration(expectedNumBackends))
createRandomFile(t, tempTLSDir, createTLSConfiguration(expectedNumTLSConf))
createRandomFile(t, tempTLSDir, createTLS(expectedNumTLSConf))
configurationChan, signal := createConfigurationRoutine(t, &expectedNumFrontends, &expectedNumBackends, &expectedNumTLSConf)
@ -167,7 +167,7 @@ func TestProvideDirectoryAndNotWatch(t *testing.T) {
}
func createConfigurationRoutine(t *testing.T, expectedNumFrontends *int, expectedNumBackends *int, expectedNumTLSConfigurations *int) (chan types.ConfigMessage, chan interface{}) {
func createConfigurationRoutine(t *testing.T, expectedNumFrontends *int, expectedNumBackends *int, expectedNumTLSes *int) (chan types.ConfigMessage, chan interface{}) {
configurationChan := make(chan types.ConfigMessage)
signal := make(chan interface{})
@ -177,7 +177,7 @@ func createConfigurationRoutine(t *testing.T, expectedNumFrontends *int, expecte
assert.Equal(t, "file", data.ProviderName)
assert.Len(t, data.Configuration.Frontends, *expectedNumFrontends)
assert.Len(t, data.Configuration.Backends, *expectedNumBackends)
assert.Len(t, data.Configuration.TLSConfiguration, *expectedNumTLSConfigurations)
assert.Len(t, data.Configuration.TLS, *expectedNumTLSes)
signal <- nil
}
})
@ -297,13 +297,13 @@ func createBackendConfiguration(n int) string {
return conf
}
// createTLSConfiguration Helper
func createTLSConfiguration(n int) string {
// createTLS Helper
func createTLS(n int) string {
var conf string
for i := 1; i <= n; i++ {
conf += fmt.Sprintf(`[[TLSConfiguration]]
conf += fmt.Sprintf(`[[TLS]]
EntryPoints = ["https"]
[TLSConfiguration.Certificate]
[TLS.Certificate]
CertFile = "integration/fixtures/https/snitest%[1]d.com.cert"
KeyFile = "integration/fixtures/https/snitest%[1]d.com.key"
`, i)

View file

@ -202,17 +202,17 @@ func route(name string, rule string) func(*types.Route) string {
}
}
func tlsConfigurations(opts ...func(*tls.Configuration)) func(*types.Configuration) {
func tlsesSection(opts ...func(*tls.Configuration)) func(*types.Configuration) {
return func(c *types.Configuration) {
for _, opt := range opts {
tlsConf := &tls.Configuration{}
opt(tlsConf)
c.TLSConfiguration = append(c.TLSConfiguration, tlsConf)
c.TLS = append(c.TLS, tlsConf)
}
}
}
func tlsConfiguration(opts ...func(*tls.Configuration)) func(*tls.Configuration) {
func tlsSection(opts ...func(*tls.Configuration)) func(*tls.Configuration) {
return func(c *tls.Configuration) {
for _, opt := range opts {
opt(c)
@ -281,8 +281,8 @@ func TestBuildConfiguration(t *testing.T) {
),
),
),
tlsConfigurations(
tlsConfiguration(
tlsesSection(
tlsSection(
tlsEntryPoints("https"),
certificate("certificate", "key"),
),
@ -375,7 +375,7 @@ func sampleConfiguration() *types.Configuration {
},
},
},
TLSConfiguration: []*tls.Configuration{
TLS: []*tls.Configuration{
{
EntryPoints: []string{"https"},
Certificate: &tls.Certificate{

View file

@ -175,12 +175,12 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
continue
}
tlsConfigs, err := getTLSConfigurations(i, k8sClient)
tlsSection, err := getTLS(i, k8sClient)
if err != nil {
log.Errorf("Error configuring TLS for ingress %s/%s: %v", i.Namespace, i.Name, err)
continue
}
templateObjects.TLSConfiguration = append(templateObjects.TLSConfiguration, tlsConfigs...)
templateObjects.TLS = append(templateObjects.TLS, tlsSection...)
for _, r := range i.Spec.Rules {
if r.HTTP == nil {
@ -449,7 +449,7 @@ func loadAuthCredentials(namespace, secretName string, k8sClient Client) ([]stri
return creds, nil
}
func getTLSConfigurations(ingress *v1beta1.Ingress, k8sClient Client) ([]*tls.Configuration, error) {
func getTLS(ingress *v1beta1.Ingress, k8sClient Client) ([]*tls.Configuration, error) {
var tlsConfigs []*tls.Configuration
for _, t := range ingress.Spec.TLS {

View file

@ -1323,8 +1323,8 @@ func TestTLSSecretLoad(t *testing.T) {
),
),
),
tlsConfigurations(
tlsConfiguration(
tlsesSection(
tlsSection(
tlsEntryPoints("ep1", "ep2"),
certificate(
"-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----",
@ -1336,7 +1336,7 @@ func TestTLSSecretLoad(t *testing.T) {
assert.Equal(t, expected, actual)
}
func TestGetTLSConfigurations(t *testing.T) {
func TestGetTLS(t *testing.T) {
testIngressWithoutHostname := buildIngress(
iNamespace("testing"),
iRules(
@ -1503,7 +1503,7 @@ func TestGetTLSConfigurations(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
tlsConfigs, err := getTLSConfigurations(test.ingress, test.client)
tlsConfigs, err := getTLS(test.ingress, test.client)
if test.errResult != "" {
assert.EqualError(t, err, test.errResult)

View file

@ -62,10 +62,10 @@ const (
pathFrontendRoutes = "/routes/"
pathFrontendRule = "/rule"
pathTLSConfiguration = "/tlsconfiguration/"
pathTLSConfigurationEntryPoints = "/entrypoints"
pathTLSConfigurationCertFile = "/certificate/certfile"
pathTLSConfigurationKeyFile = "/certificate/keyfile"
pathTLS = "/tls/"
pathTLSEntryPoints = "/entrypoints"
pathTLSCertFile = "/certificate/certfile"
pathTLSKeyFile = "/certificate/keyfile"
pathTags = "/tags"
pathAlias = "/alias"

View file

@ -38,7 +38,7 @@ func (p *Provider) buildConfiguration() *types.Configuration {
"Last": p.last,
"Has": p.has,
"getTLSConfigurations": p.getTLSConfigurations,
"getTLSSection": p.getTLSSection,
// Frontend functions
"getBackendName": p.getFuncString(pathFrontendBackend, ""),
@ -273,19 +273,19 @@ func (p *Provider) getHealthCheck(rootPath string) *types.HealthCheck {
}
}
func (p *Provider) getTLSConfigurations(prefix string) []*tls.Configuration {
var tlsConfiguration []*tls.Configuration
func (p *Provider) getTLSSection(prefix string) []*tls.Configuration {
var tlsSection []*tls.Configuration
for _, tlsConfPath := range p.list(prefix, pathTLSConfiguration) {
certFile := p.get("", tlsConfPath, pathTLSConfigurationCertFile)
keyFile := p.get("", tlsConfPath, pathTLSConfigurationKeyFile)
for _, tlsConfPath := range p.list(prefix, pathTLS) {
certFile := p.get("", tlsConfPath, pathTLSCertFile)
keyFile := p.get("", tlsConfPath, pathTLSKeyFile)
if len(certFile) == 0 && len(keyFile) == 0 {
log.Warnf("Invalid TLS configuration (no cert and no key): %s", tlsConfPath)
continue
}
entryPoints := p.getList(tlsConfPath, pathTLSConfigurationEntryPoints)
entryPoints := p.getList(tlsConfPath, pathTLSEntryPoints)
if len(entryPoints) == 0 {
log.Warnf("Invalid TLS configuration (no entry points): %s", tlsConfPath)
continue
@ -299,10 +299,10 @@ func (p *Provider) getTLSConfigurations(prefix string) []*tls.Configuration {
},
}
tlsConfiguration = append(tlsConfiguration, tlsConf)
tlsSection = append(tlsSection, tlsConf)
}
return tlsConfiguration
return tlsSection
}
func (p *Provider) getRoutes(rootPath string) map[string]types.Route {

View file

@ -125,11 +125,11 @@ func TestProviderBuildConfiguration(t *testing.T) {
withPair("routes/route1/rule", "Host:test.localhost"),
withPair("routes/route2/rule", "Path:/foo")),
entry("tlsconfiguration/foo",
entry("tls/foo",
withPair("entrypoints", "http,https"),
withPair("certificate/certfile", "certfile1"),
withPair("certificate/keyfile", "keyfile1")),
entry("tlsconfiguration/bar",
entry("tls/bar",
withPair("entrypoints", "http,https"),
withPair("certificate/certfile", "certfile2"),
withPair("certificate/keyfile", "keyfile2")),
@ -246,7 +246,7 @@ func TestProviderBuildConfiguration(t *testing.T) {
},
},
},
TLSConfiguration: []*tls.Configuration{
TLS: []*tls.Configuration{
{
EntryPoints: []string{"http", "https"},
Certificate: &tls.Certificate{
@ -1700,7 +1700,7 @@ func TestProviderGetHealthCheck(t *testing.T) {
}
}
func TestProviderGetTLSConfigurations(t *testing.T) {
func TestProviderGetTLSes(t *testing.T) {
testCases := []struct {
desc string
kvPairs []*store.KVPair
@ -1709,11 +1709,11 @@ func TestProviderGetTLSConfigurations(t *testing.T) {
{
desc: "when several TLS configuration defined",
kvPairs: filler("traefik",
entry("tlsconfiguration/foo",
entry("tls/foo",
withPair("entrypoints", "http,https"),
withPair("certificate/certfile", "certfile1"),
withPair("certificate/keyfile", "keyfile1")),
entry("tlsconfiguration/bar",
entry("tls/bar",
withPair("entrypoints", "http,https"),
withPair("certificate/certfile", "certfile2"),
withPair("certificate/keyfile", "keyfile2"))),
@ -1736,13 +1736,13 @@ func TestProviderGetTLSConfigurations(t *testing.T) {
},
{
desc: "should return nil when no TLS configuration",
kvPairs: filler("traefik", entry("tlsconfiguration/foo")),
kvPairs: filler("traefik", entry("tls/foo")),
expected: nil,
},
{
desc: "should return nil when no entry points",
kvPairs: filler("traefik",
entry("tlsconfiguration/foo",
entry("tls/foo",
withPair("certificate/certfile", "certfile2"),
withPair("certificate/keyfile", "keyfile2"))),
expected: nil,
@ -1750,7 +1750,7 @@ func TestProviderGetTLSConfigurations(t *testing.T) {
{
desc: "should return nil when no cert file and no key file",
kvPairs: filler("traefik",
entry("tlsconfiguration/foo",
entry("tls/foo",
withPair("entrypoints", "http,https"))),
expected: nil,
},
@ -1764,7 +1764,7 @@ func TestProviderGetTLSConfigurations(t *testing.T) {
p := newProviderMock(test.kvPairs)
result := p.getTLSConfigurations(prefix)
result := p.getTLSSection(prefix)
assert.Equal(t, test.expected, result)
})

View file

@ -91,19 +91,24 @@ func (p *Provider) apiProvide(configurationChan chan<- types.ConfigMessage, pool
for {
select {
case <-ticker.C:
checkAPI, errAPI := rancherClient.ApiKey.List(withoutPagination)
log.Debugf("Refreshing new Data from Provider API")
var stacks = listRancherStacks(rancherClient)
var services = listRancherServices(rancherClient)
var container = listRancherContainer(rancherClient)
if errAPI != nil {
log.Errorf("Cannot establish connection: %+v, Rancher API return: %+v; Skipping refresh Data from Rancher API.", errAPI, checkAPI)
} else {
log.Debugf("Refreshing new Data from Rancher API")
stacks := listRancherStacks(rancherClient)
services := listRancherServices(rancherClient)
container := listRancherContainer(rancherClient)
rancherData := parseAPISourcedRancherData(stacks, services, container)
rancherData := parseAPISourcedRancherData(stacks, services, container)
configuration := p.buildConfiguration(rancherData)
if configuration != nil {
configurationChan <- types.ConfigMessage{
ProviderName: "rancher",
Configuration: configuration,
configuration := p.buildConfiguration(rancherData)
if configuration != nil {
configurationChan <- types.ConfigMessage{
ProviderName: "rancher",
Configuration: configuration,
}
}
}
case <-stop: