Support Nomad canary deployment
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com> Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
parent
ab94bbaece
commit
2a2ea759d1
10 changed files with 593 additions and 51 deletions
|
@ -273,7 +273,7 @@ func TestDefaultRule(t *testing.T) {
|
|||
|
||||
for i := 0; i < len(test.items); i++ {
|
||||
var err error
|
||||
test.items[i].ExtraConf, err = p.getConfiguration(test.items[i].Labels)
|
||||
test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -2611,6 +2611,253 @@ func Test_buildConfiguration(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "two HTTP service instances with one canary",
|
||||
ConnectAware: true,
|
||||
items: []itemData{
|
||||
{
|
||||
ID: "1",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.consulcatalog.connect": "true",
|
||||
},
|
||||
Address: "127.0.0.1",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.consulcatalog.connect": "true",
|
||||
"traefik.consulcatalog.canary": "true",
|
||||
},
|
||||
Address: "127.0.0.2",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
},
|
||||
expected: &dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{},
|
||||
Middlewares: map[string]*dynamic.TCPMiddleware{},
|
||||
Services: map[string]*dynamic.TCPService{},
|
||||
},
|
||||
UDP: &dynamic.UDPConfiguration{
|
||||
Routers: map[string]*dynamic.UDPRouter{},
|
||||
Services: map[string]*dynamic.UDPService{},
|
||||
},
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Routers: map[string]*dynamic.Router{
|
||||
"Test": {
|
||||
Service: "Test",
|
||||
Rule: "Host(`Test.traefik.wtf`)",
|
||||
},
|
||||
"Test-97077516270503695": {
|
||||
Service: "Test-97077516270503695",
|
||||
Rule: "Host(`Test.traefik.wtf`)",
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Services: map[string]*dynamic.Service{
|
||||
"Test": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "https://127.0.0.1:80",
|
||||
},
|
||||
},
|
||||
PassHostHeader: Bool(true),
|
||||
ServersTransport: "tls-ns-dc1-Test",
|
||||
},
|
||||
},
|
||||
"Test-97077516270503695": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "https://127.0.0.2:80",
|
||||
},
|
||||
},
|
||||
PassHostHeader: Bool(true),
|
||||
ServersTransport: "tls-ns-dc1-Test",
|
||||
},
|
||||
},
|
||||
},
|
||||
ServersTransports: map[string]*dynamic.ServersTransport{
|
||||
"tls-ns-dc1-Test": {
|
||||
ServerName: "ns-dc1-Test",
|
||||
InsecureSkipVerify: true,
|
||||
RootCAs: []tls.FileOrContent{
|
||||
"root",
|
||||
},
|
||||
Certificates: []tls.Certificate{
|
||||
{
|
||||
CertFile: "cert",
|
||||
KeyFile: "key",
|
||||
},
|
||||
},
|
||||
PeerCertURI: "spiffe:///ns/ns/dc/dc1/svc/Test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "two TCP service instances with one canary",
|
||||
ConnectAware: true,
|
||||
items: []itemData{
|
||||
{
|
||||
ID: "1",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.tcp.routers.test.rule": "HostSNI(`foobar`)",
|
||||
},
|
||||
Address: "127.0.0.1",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.consulcatalog.canary": "true",
|
||||
"traefik.tcp.routers.test-canary.rule": "HostSNI(`canary.foobar`)",
|
||||
},
|
||||
Address: "127.0.0.2",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
},
|
||||
expected: &dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{
|
||||
"test": {
|
||||
Service: "Test",
|
||||
Rule: "HostSNI(`foobar`)",
|
||||
},
|
||||
"test-canary": {
|
||||
Service: "Test-17573747155436217342",
|
||||
Rule: "HostSNI(`canary.foobar`)",
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*dynamic.TCPMiddleware{},
|
||||
Services: map[string]*dynamic.TCPService{
|
||||
"Test": {
|
||||
LoadBalancer: &dynamic.TCPServersLoadBalancer{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{Address: "127.0.0.1:80"},
|
||||
},
|
||||
TerminationDelay: Int(100),
|
||||
},
|
||||
},
|
||||
"Test-17573747155436217342": {
|
||||
LoadBalancer: &dynamic.TCPServersLoadBalancer{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{Address: "127.0.0.2:80"},
|
||||
},
|
||||
TerminationDelay: Int(100),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
UDP: &dynamic.UDPConfiguration{
|
||||
Routers: map[string]*dynamic.UDPRouter{},
|
||||
Services: map[string]*dynamic.UDPService{},
|
||||
},
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Routers: map[string]*dynamic.Router{},
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Services: map[string]*dynamic.Service{},
|
||||
ServersTransports: map[string]*dynamic.ServersTransport{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "two UDP service instances with one canary",
|
||||
ConnectAware: true,
|
||||
items: []itemData{
|
||||
{
|
||||
ID: "1",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.udp.routers.test.entrypoints": "udp",
|
||||
},
|
||||
Address: "127.0.0.1",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Node: "Node1",
|
||||
Datacenter: "dc1",
|
||||
Name: "Test",
|
||||
Namespace: "ns",
|
||||
Labels: map[string]string{
|
||||
"traefik.consulcatalog.canary": "true",
|
||||
"traefik.udp.routers.test-canary.entrypoints": "udp",
|
||||
},
|
||||
Address: "127.0.0.2",
|
||||
Port: "80",
|
||||
Status: api.HealthPassing,
|
||||
},
|
||||
},
|
||||
expected: &dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{},
|
||||
Middlewares: map[string]*dynamic.TCPMiddleware{},
|
||||
Services: map[string]*dynamic.TCPService{},
|
||||
},
|
||||
UDP: &dynamic.UDPConfiguration{
|
||||
Routers: map[string]*dynamic.UDPRouter{
|
||||
"test": {
|
||||
EntryPoints: []string{"udp"},
|
||||
Service: "Test",
|
||||
},
|
||||
"test-canary": {
|
||||
EntryPoints: []string{"udp"},
|
||||
Service: "Test-12825244908842506376",
|
||||
},
|
||||
},
|
||||
Services: map[string]*dynamic.UDPService{
|
||||
"Test": {
|
||||
LoadBalancer: &dynamic.UDPServersLoadBalancer{
|
||||
Servers: []dynamic.UDPServer{
|
||||
{Address: "127.0.0.1:80"},
|
||||
},
|
||||
},
|
||||
},
|
||||
"Test-12825244908842506376": {
|
||||
LoadBalancer: &dynamic.UDPServersLoadBalancer{
|
||||
Servers: []dynamic.UDPServer{
|
||||
{Address: "127.0.0.2:80"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Routers: map[string]*dynamic.Router{},
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Services: map[string]*dynamic.Service{},
|
||||
ServersTransports: map[string]*dynamic.ServersTransport{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
@ -2633,7 +2880,7 @@ func Test_buildConfiguration(t *testing.T) {
|
|||
|
||||
for i := 0; i < len(test.items); i++ {
|
||||
var err error
|
||||
test.items[i].ExtraConf, err = p.getConfiguration(test.items[i].Labels)
|
||||
test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels)
|
||||
require.NoError(t, err)
|
||||
|
||||
var tags []string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue