mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
fix: always add missing slashes to link names (#1588)
This commit is contained in:
parent
bbbe04119c
commit
9470bf81c5
3 changed files with 17 additions and 8 deletions
|
@ -2,7 +2,6 @@ package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containrrr/watchtower/internal/util"
|
"github.com/containrrr/watchtower/internal/util"
|
||||||
"github.com/containrrr/watchtower/pkg/container"
|
"github.com/containrrr/watchtower/pkg/container"
|
||||||
|
@ -260,10 +259,6 @@ func UpdateImplicitRestart(containers []container.Container) {
|
||||||
// container marked for restart
|
// container marked for restart
|
||||||
func linkedContainerMarkedForRestart(links []string, containers []container.Container) string {
|
func linkedContainerMarkedForRestart(links []string, containers []container.Container) string {
|
||||||
for _, linkName := range links {
|
for _, linkName := range links {
|
||||||
// Since the container names need to start with '/', let's prepend it if it's missing
|
|
||||||
if !strings.HasPrefix(linkName, "/") {
|
|
||||||
linkName = "/" + linkName
|
|
||||||
}
|
|
||||||
for _, candidate := range containers {
|
for _, candidate := range containers {
|
||||||
if candidate.Name() == linkName && candidate.ToRestart() {
|
if candidate.Name() == linkName && candidate.ToRestart() {
|
||||||
return linkName
|
return linkName
|
||||||
|
|
|
@ -160,7 +160,14 @@ func (c Container) Links() []string {
|
||||||
dependsOnLabelValue := c.getLabelValueOrEmpty(dependsOnLabel)
|
dependsOnLabelValue := c.getLabelValueOrEmpty(dependsOnLabel)
|
||||||
|
|
||||||
if dependsOnLabelValue != "" {
|
if dependsOnLabelValue != "" {
|
||||||
links := strings.Split(dependsOnLabelValue, ",")
|
for _, link := range strings.Split(dependsOnLabelValue, ",") {
|
||||||
|
// Since the container names need to start with '/', let's prepend it if it's missing
|
||||||
|
if !strings.HasPrefix(link, "/") {
|
||||||
|
link = "/" + link
|
||||||
|
}
|
||||||
|
links = append(links, link)
|
||||||
|
}
|
||||||
|
|
||||||
return links
|
return links
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,14 +178,21 @@ var _ = Describe("the container", func() {
|
||||||
"com.centurylinklabs.watchtower.depends-on": "postgres",
|
"com.centurylinklabs.watchtower.depends-on": "postgres",
|
||||||
}))
|
}))
|
||||||
links := c.Links()
|
links := c.Links()
|
||||||
Expect(links).To(SatisfyAll(ContainElement("postgres"), HaveLen(1)))
|
Expect(links).To(SatisfyAll(ContainElement("/postgres"), HaveLen(1)))
|
||||||
})
|
})
|
||||||
It("should fetch depending containers if there are many", func() {
|
It("should fetch depending containers if there are many", func() {
|
||||||
c = MockContainer(WithLabels(map[string]string{
|
c = MockContainer(WithLabels(map[string]string{
|
||||||
"com.centurylinklabs.watchtower.depends-on": "postgres,redis",
|
"com.centurylinklabs.watchtower.depends-on": "postgres,redis",
|
||||||
}))
|
}))
|
||||||
links := c.Links()
|
links := c.Links()
|
||||||
Expect(links).To(SatisfyAll(ContainElement("postgres"), ContainElement("redis"), HaveLen(2)))
|
Expect(links).To(SatisfyAll(ContainElement("/postgres"), ContainElement("/redis"), HaveLen(2)))
|
||||||
|
})
|
||||||
|
It("should only add slashes to names when they are missing", func() {
|
||||||
|
c = MockContainer(WithLabels(map[string]string{
|
||||||
|
"com.centurylinklabs.watchtower.depends-on": "/postgres,redis",
|
||||||
|
}))
|
||||||
|
links := c.Links()
|
||||||
|
Expect(links).To(SatisfyAll(ContainElement("/postgres"), ContainElement("/redis")))
|
||||||
})
|
})
|
||||||
It("should fetch depending containers if label is blank", func() {
|
It("should fetch depending containers if label is blank", func() {
|
||||||
c = MockContainer(WithLabels(map[string]string{
|
c = MockContainer(WithLabels(map[string]string{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue