build - prozess optimiert mit push nach zot
nginx-kill - > maint. site...
This commit is contained in:
1 parent
665135f87e
commit
64417d8353
19 files changed
+447
-61
No files matched your search
@@ -27,7 +27,7 @@ func wpLabels() map[string]string {
|
||||
|
||||
func TestWorkloads_TranslatesPublishedPort(t *testing.T) {
|
||||
in := ctr("wordpress", wpLabels(), pub(80, 8081), pub(443, 8443))
|
||||
got, warnings := Workloads([]docker.Container{in}, "100.64.0.42")
|
||||
got, _, warnings := Workloads([]docker.Container{in}, "100.64.0.42")
|
||||
if len(warnings) != 0 {
|
||||
t.Errorf("Warnungen: %v", warnings)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func TestWorkloads_SkipsDisabled(t *testing.T) {
|
||||
off["traefik.enable"] = "false"
|
||||
none := wpLabels()
|
||||
delete(none, "traefik.enable")
|
||||
got, warnings := Workloads([]docker.Container{
|
||||
got, _, warnings := Workloads([]docker.Container{
|
||||
ctr("aus", off, pub(80, 8081)),
|
||||
ctr("ohne", none, pub(80, 8082)),
|
||||
ctr("db", map[string]string{}, pub(5432, 5432)),
|
||||
@@ -71,7 +71,7 @@ func TestWorkloads_UnreachablePorts(t *testing.T) {
|
||||
"anderer Port": {pub(8080, 8081)},
|
||||
}
|
||||
for name, ports := range tests {
|
||||
got, warnings := Workloads([]docker.Container{ctr("wordpress", wpLabels(), ports...)}, "h")
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("wordpress", wpLabels(), ports...)}, "h")
|
||||
if len(got) != 0 {
|
||||
t.Errorf("%s: Workload trotz unerreichbarem Port: %+v", name, got)
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func TestWorkloads_UnreachablePorts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkloads_IPv6AnyIsReachable(t *testing.T) {
|
||||
got, _ := Workloads([]docker.Container{ctr("wordpress", wpLabels(),
|
||||
got, _, _ := Workloads([]docker.Container{ctr("wordpress", wpLabels(),
|
||||
docker.Port{IP: "::", PrivatePort: 80, PublicPort: 8081, Type: "tcp"})}, "h")
|
||||
if len(got) != 1 || got[0].Labels["traefik.http.services.wp.loadbalancer.server.port"] != "8081" {
|
||||
t.Errorf("got = %+v", got)
|
||||
@@ -93,7 +93,7 @@ func TestWorkloads_IPv6AnyIsReachable(t *testing.T) {
|
||||
// mit dem Containernamen und dem einzigen veröffentlichten Port.
|
||||
func TestWorkloads_DefaultService(t *testing.T) {
|
||||
labels := map[string]string{"traefik.enable": "true", "traefik.http.routers.app.rule": "Host(`app.kunde.de`)"}
|
||||
got, warnings := Workloads([]docker.Container{ctr("my.app", labels, pub(3000, 13000))}, "h")
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("my.app", labels, pub(3000, 13000))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func TestWorkloads_DefaultService(t *testing.T) {
|
||||
t.Errorf("Default-Service fehlt: %v", got[0].Labels)
|
||||
}
|
||||
|
||||
_, warnings = Workloads([]docker.Container{ctr("multi", labels, pub(3000, 13000), pub(3001, 13001))}, "h")
|
||||
_, _, warnings = Workloads([]docker.Container{ctr("multi", labels, pub(3000, 13000), pub(3001, 13001))}, "h")
|
||||
if len(warnings) != 1 || !strings.Contains(warnings[0], "multi") {
|
||||
t.Errorf("mehrere Ports ohne Port-Label: Warnungen = %v", warnings)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func TestWorkloads_ServiceWithoutPortLabel(t *testing.T) {
|
||||
"traefik.http.routers.wp.rule": "Host(`kunde.de`)",
|
||||
"traefik.http.services.wp.loadbalancer.passhostheader": "true",
|
||||
}
|
||||
got, warnings := Workloads([]docker.Container{ctr("wordpress", labels, pub(80, 8081))}, "h")
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("wordpress", labels, pub(80, 8081))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 || got[0].Labels["traefik.http.services.wp.loadbalancer.server.port"] != "8081" {
|
||||
t.Errorf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func TestWorkloads_MultipleServicesAndCaseInsensitiveKeys(t *testing.T) {
|
||||
"traefik.http.services.web.loadbalancer.server.port": "80",
|
||||
"Traefik.HTTP.Services.Api.LoadBalancer.Server.Port": "9000",
|
||||
}
|
||||
got, warnings := Workloads([]docker.Container{ctr("app", labels, pub(80, 8080), pub(9000, 19000))}, "h")
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("app", labels, pub(80, 8080), pub(9000, 19000))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func TestWorkloads_MultipleServicesAndCaseInsensitiveKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkloads_SortedByName(t *testing.T) {
|
||||
got, _ := Workloads([]docker.Container{
|
||||
got, _, _ := Workloads([]docker.Container{
|
||||
ctr("b", wpLabels(), pub(80, 8082)),
|
||||
ctr("a", wpLabels(), pub(80, 8081)),
|
||||
}, "h")
|
||||
@@ -148,3 +148,75 @@ func TestWorkloads_SortedByName(t *testing.T) {
|
||||
t.Errorf("Reihenfolge: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func stopped(c docker.Container, state string) docker.Container {
|
||||
c.State = state
|
||||
return c
|
||||
}
|
||||
|
||||
// Gestoppt (nicht entfernt): Route bleibt, Services gelten als down → die
|
||||
// Policy leitet zur Wartungsseite statt 404. Die Ports kommen bei gestoppten
|
||||
// Containern aus PortBindings (der Agent setzt sie vorher in Ports ein).
|
||||
func TestWorkloads_StoppedContainerIsDown(t *testing.T) {
|
||||
for _, state := range []string{"exited", "created", "restarting", "paused", "dead"} {
|
||||
got, down, warnings := Workloads([]docker.Container{stopped(ctr("nginx", wpLabels(), pub(80, 9080)), state)}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("%s: got=%+v warnings=%v", state, got, warnings)
|
||||
}
|
||||
if got[0].Labels["traefik.http.services.wp.loadbalancer.server.port"] != "9080" {
|
||||
t.Errorf("%s: Labels = %v", state, got[0].Labels)
|
||||
}
|
||||
if !reflect.DeepEqual(down, []string{"wp"}) {
|
||||
t.Errorf("%s: down = %v, erwartet [wp]", state, down)
|
||||
}
|
||||
}
|
||||
|
||||
// Default-Service und mehrere Services, alle down, sortiert.
|
||||
labels := map[string]string{"traefik.enable": "true", "traefik.http.routers.app.rule": "Host(`app.kunde.de`)"}
|
||||
_, down, _ := Workloads([]docker.Container{stopped(ctr("my.app", labels, pub(3000, 13000)), "exited")}, "h")
|
||||
if !reflect.DeepEqual(down, []string{"my-app"}) {
|
||||
t.Errorf("Default-Service: down = %v", down)
|
||||
}
|
||||
multi := map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.http.routers.web.rule": "Host(`kunde.de`)",
|
||||
"traefik.http.routers.web.service": "web",
|
||||
"traefik.http.services.web.loadbalancer.server.port": "80",
|
||||
"traefik.http.services.Api.loadbalancer.server.port": "9000",
|
||||
}
|
||||
_, down, _ = Workloads([]docker.Container{stopped(ctr("app", multi, pub(80, 8080), pub(9000, 19000)), "exited")}, "h")
|
||||
if !reflect.DeepEqual(down, []string{"Api", "web"}) {
|
||||
t.Errorf("mehrere Services: down = %v", down)
|
||||
}
|
||||
|
||||
// Laufend: nichts down.
|
||||
if _, down, _ := Workloads([]docker.Container{ctr("nginx", wpLabels(), pub(80, 9080))}, "h"); len(down) != 0 {
|
||||
t.Errorf("laufend: down = %v", down)
|
||||
}
|
||||
}
|
||||
|
||||
// Ein gestoppter Container mit denselben Router- oder Service-Namen wie ein
|
||||
// laufender (z. B. alte Kopie) darf diesen nicht verdrängen.
|
||||
func TestWorkloads_RunningWinsOverStopped(t *testing.T) {
|
||||
routerOnly := map[string]string{"traefik.enable": "true", "traefik.http.routers.WP.rule": "Host(`alt.kunde.de`)",
|
||||
"traefik.http.services.other.loadbalancer.server.port": "80"}
|
||||
serviceOnly := map[string]string{"traefik.enable": "true", "traefik.http.routers.x.rule": "Host(`x.kunde.de`)",
|
||||
"traefik.http.routers.x.service": "wp", "traefik.http.services.wp.loadbalancer.server.port": "80"}
|
||||
for name, labels := range map[string]map[string]string{"gleiche Labels": wpLabels(), "gleicher Router": routerOnly, "gleicher Service": serviceOnly} {
|
||||
got, down, warnings := Workloads([]docker.Container{
|
||||
stopped(ctr("a-alt", labels, pub(80, 9081)), "exited"),
|
||||
ctr("b-neu", wpLabels(), pub(80, 9080)),
|
||||
}, "h")
|
||||
if len(got) != 1 || got[0].Name != "b-neu" || len(down) != 0 || len(warnings) != 0 {
|
||||
t.Errorf("%s: got=%+v down=%v warnings=%v", name, got, down, warnings)
|
||||
}
|
||||
}
|
||||
|
||||
// Ohne Überschneidung bleiben beide.
|
||||
other := map[string]string{"traefik.enable": "true", "traefik.http.routers.alt.rule": "Host(`alt.kunde.de`)",
|
||||
"traefik.http.services.alt.loadbalancer.server.port": "80"}
|
||||
got, down, _ := Workloads([]docker.Container{stopped(ctr("a-alt", other, pub(80, 9081)), "exited"), ctr("b-neu", wpLabels(), pub(80, 9080))}, "h")
|
||||
if len(got) != 2 || !reflect.DeepEqual(down, []string{"alt"}) {
|
||||
t.Errorf("ohne Überschneidung: got=%+v down=%v", got, down)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user