Merge branch v2.10 into v3.0
This commit is contained in:
commit
606281a4a5
20 changed files with 196 additions and 73 deletions
|
@ -218,7 +218,7 @@ func TestBasicAuthUsersFromFile(t *testing.T) {
|
|||
usersFile, err := os.CreateTemp(t.TempDir(), "auth-users")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = usersFile.Write([]byte(test.userFileContent))
|
||||
_, err = usersFile.WriteString(test.userFileContent)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Creates the configuration for our Authenticator
|
||||
|
|
|
@ -96,7 +96,7 @@ func TestDigestAuthUsersFromFile(t *testing.T) {
|
|||
usersFile, err := os.CreateTemp(t.TempDir(), "auth-users")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = usersFile.Write([]byte(test.userFileContent))
|
||||
_, err = usersFile.WriteString(test.userFileContent)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Creates the configuration for our Authenticator
|
||||
|
|
|
@ -177,7 +177,7 @@ func generateBytes(length int) []byte {
|
|||
}
|
||||
|
||||
func TestRequestReader(t *testing.T) {
|
||||
buff := bytes.NewBuffer([]byte("foo"))
|
||||
buff := bytes.NewBufferString("foo")
|
||||
rr := readCounter{source: io.NopCloser(buff)}
|
||||
assert.Equal(t, int64(0), rr.size)
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
|||
schemeRegex := `^(https?):\/\/(\[[\w:.]+\]|[\w\._-]+)?(:\d+)?(.*)$`
|
||||
re, _ := regexp.Compile(schemeRegex)
|
||||
|
||||
if re.Match([]byte(test.url)) {
|
||||
if re.MatchString(test.url) {
|
||||
match := re.FindStringSubmatch(test.url)
|
||||
req.RequestURI = match[4]
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ func (c *Client) unzipArchive(pName, pVersion string) error {
|
|||
for _, f := range archive.File {
|
||||
err = unzipFile(f, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to unzip %s: %w", f.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,12 +281,17 @@ func unzipFile(f *zipa.File, dest string) error {
|
|||
p := filepath.Join(dest, pathParts[1])
|
||||
|
||||
if f.FileInfo().IsDir() {
|
||||
return os.MkdirAll(p, f.Mode())
|
||||
err = os.MkdirAll(p, f.Mode())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create archive directory %s: %w", p, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(p), 0o750)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to create archive directory %s for file %s: %w", filepath.Dir(p), p, err)
|
||||
}
|
||||
|
||||
elt, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
||||
|
@ -345,7 +350,7 @@ func (c *Client) WriteState(plugins map[string]Descriptor) error {
|
|||
|
||||
mp, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to marshal plugin state: %w", err)
|
||||
}
|
||||
|
||||
return os.WriteFile(c.stateFile, mp, 0o600)
|
||||
|
@ -359,10 +364,15 @@ func (c *Client) ResetAll() error {
|
|||
|
||||
err := resetDirectory(filepath.Join(c.goPath, ".."))
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to reset plugins GoPath directory %s: %w", c.goPath, err)
|
||||
}
|
||||
|
||||
return resetDirectory(c.archives)
|
||||
err = resetDirectory(c.archives)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to reset plugins archives directory: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) buildArchivePath(pName, pVersion string) string {
|
||||
|
@ -372,12 +382,12 @@ func (c *Client) buildArchivePath(pName, pVersion string) string {
|
|||
func resetDirectory(dir string) error {
|
||||
dirPath, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to get absolute path of %s: %w", dir, err)
|
||||
}
|
||||
|
||||
currentPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to get the current directory: %w", err)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(currentPath, dirPath) {
|
||||
|
@ -386,10 +396,15 @@ func resetDirectory(dir string) error {
|
|||
|
||||
err = os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("unable to remove directory %s: %w", dirPath, err)
|
||||
}
|
||||
|
||||
return os.MkdirAll(dir, 0o755)
|
||||
err = os.MkdirAll(dir, 0o755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create directory %s: %w", dirPath, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func computeHash(filepath string) (string, error) {
|
||||
|
|
|
@ -21,7 +21,7 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error {
|
|||
|
||||
err = client.CleanArchives(plugins)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to clean archives: %w", err)
|
||||
return fmt.Errorf("unable to clean archives: %w", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
@ -32,27 +32,27 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error {
|
|||
hash, err := client.Download(ctx, desc.ModuleName, desc.Version)
|
||||
if err != nil {
|
||||
_ = client.ResetAll()
|
||||
return fmt.Errorf("failed to download plugin %s: %w", desc.ModuleName, err)
|
||||
return fmt.Errorf("unable to download plugin %s: %w", desc.ModuleName, err)
|
||||
}
|
||||
|
||||
err = client.Check(ctx, desc.ModuleName, desc.Version, hash)
|
||||
if err != nil {
|
||||
_ = client.ResetAll()
|
||||
return fmt.Errorf("failed to check archive integrity of the plugin %s: %w", desc.ModuleName, err)
|
||||
return fmt.Errorf("unable to check archive integrity of the plugin %s: %w", desc.ModuleName, err)
|
||||
}
|
||||
}
|
||||
|
||||
err = client.WriteState(plugins)
|
||||
if err != nil {
|
||||
_ = client.ResetAll()
|
||||
return fmt.Errorf("failed to write plugins state: %w", err)
|
||||
return fmt.Errorf("unable to write plugins state: %w", err)
|
||||
}
|
||||
|
||||
for _, desc := range plugins {
|
||||
err = client.Unzip(desc.ModuleName, desc.Version)
|
||||
if err != nil {
|
||||
_ = client.ResetAll()
|
||||
return fmt.Errorf("failed to unzip archive: %w", err)
|
||||
return fmt.Errorf("unable to unzip archive: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestTLSCertificateContent(t *testing.T) {
|
|||
keyFile = "` + fileTLSKey.Name() + `"
|
||||
`
|
||||
|
||||
_, err = fileConfig.Write([]byte(content))
|
||||
_, err = fileConfig.WriteString(content)
|
||||
require.NoError(t, err)
|
||||
|
||||
provider := &Provider{}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: whoami-svc-multiple-subsets
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
ports:
|
||||
- name: web
|
||||
port: 80
|
||||
- name: web2
|
||||
port: 8080
|
||||
selector:
|
||||
app: traefiklabs
|
||||
task: whoami
|
||||
|
||||
---
|
||||
kind: Endpoints
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: whoami-svc-multiple-subsets
|
||||
namespace: default
|
||||
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: 10.10.0.1
|
||||
- ip: 10.10.0.2
|
||||
ports:
|
||||
- name: web
|
||||
port: 80
|
||||
- addresses:
|
||||
- ip: 10.10.0.3
|
||||
- ip: 10.10.0.4
|
||||
ports:
|
||||
- name: web2
|
||||
port: 8080
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: test.route
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
entryPoints:
|
||||
- foo
|
||||
|
||||
routes:
|
||||
- match: Host(`foo.com`) && PathPrefix(`/bar`)
|
||||
kind: Rule
|
||||
priority: 12
|
||||
services:
|
||||
- name: whoami-svc-multiple-subsets
|
||||
port: 8080
|
|
@ -420,8 +420,8 @@ func (c configBuilder) loadServers(parentNamespace string, svc traefikv1alpha1.L
|
|||
return nil, fmt.Errorf("subset not found for %s/%s", namespace, sanitizedName)
|
||||
}
|
||||
|
||||
var port int32
|
||||
for _, subset := range endpoints.Subsets {
|
||||
var port int32
|
||||
for _, p := range subset.Ports {
|
||||
if svcPort.Name == p.Name {
|
||||
port = p.Port
|
||||
|
@ -430,7 +430,7 @@ func (c configBuilder) loadServers(parentNamespace string, svc traefikv1alpha1.L
|
|||
}
|
||||
|
||||
if port == 0 {
|
||||
return nil, fmt.Errorf("cannot define a port for %s/%s", namespace, sanitizedName)
|
||||
continue
|
||||
}
|
||||
|
||||
protocol, err := parseServiceProtocol(svc.Scheme, svcPort.Name, svcPort.Port)
|
||||
|
|
|
@ -4370,6 +4370,54 @@ func TestLoadIngressRoutes(t *testing.T) {
|
|||
TLS: &dynamic.TLSConfiguration{},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "IngressRoute, service with multiple subsets",
|
||||
allowEmptyServices: true,
|
||||
paths: []string{"services.yml", "with_multiple_subsets.yml"},
|
||||
expected: &dynamic.Configuration{
|
||||
UDP: &dynamic.UDPConfiguration{
|
||||
Routers: map[string]*dynamic.UDPRouter{},
|
||||
Services: map[string]*dynamic.UDPService{},
|
||||
},
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{},
|
||||
Middlewares: map[string]*dynamic.TCPMiddleware{},
|
||||
Services: map[string]*dynamic.TCPService{},
|
||||
ServersTransports: map[string]*dynamic.TCPServersTransport{},
|
||||
},
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Routers: map[string]*dynamic.Router{
|
||||
"default-test-route-6b204d94623b3df4370c": {
|
||||
EntryPoints: []string{"foo"},
|
||||
Service: "default-test-route-6b204d94623b3df4370c",
|
||||
Rule: "Host(`foo.com`) && PathPrefix(`/bar`)",
|
||||
Priority: 12,
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Services: map[string]*dynamic.Service{
|
||||
"default-test-route-6b204d94623b3df4370c": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "http://10.10.0.3:8080",
|
||||
},
|
||||
{
|
||||
URL: "http://10.10.0.4:8080",
|
||||
},
|
||||
},
|
||||
PassHostHeader: Bool(true),
|
||||
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ServersTransports: map[string]*dynamic.ServersTransport{},
|
||||
},
|
||||
TLS: &dynamic.TLSConfiguration{},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "TraefikService, empty service allowed",
|
||||
allowEmptyServices: true,
|
||||
|
|
|
@ -842,7 +842,7 @@ func checkTCPTLS(addr string, timeout time.Duration, tlsVersion uint16) (err err
|
|||
|
||||
err = conn.SetReadDeadline(time.Now().Add(timeout))
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
|
|
@ -73,6 +73,7 @@ func (s *Server) Wait() {
|
|||
|
||||
// Stop stops the server.
|
||||
func (s *Server) Stop() {
|
||||
//nolint:zerologlint // false-positive https://github.com/ykadowak/zerologlint/issues/3
|
||||
defer log.Info().Msg("Server stopped")
|
||||
|
||||
s.tcpEntryPoints.Stop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue