rebase/merge main and container-downtime

This commit is contained in:
nils måsén 2021-04-28 14:35:38 +02:00
parent 24276cfbc6
commit 9e84cfde4f
4 changed files with 142 additions and 114 deletions

View file

@ -2,16 +2,17 @@ package actions_test
import (
"github.com/containrrr/watchtower/internal/actions"
. "github.com/containrrr/watchtower/internal/actions/mocks"
"github.com/containrrr/watchtower/pkg/container"
"github.com/containrrr/watchtower/pkg/container/mocks"
"github.com/containrrr/watchtower/pkg/metrics"
"github.com/containrrr/watchtower/pkg/sorter"
"github.com/containrrr/watchtower/pkg/types"
container2 "github.com/docker/docker/api/types/container"
cli "github.com/docker/docker/client"
"time"
"github.com/containrrr/watchtower/pkg/sorter"
. "github.com/containrrr/watchtower/internal/actions/mocks"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"time"
)
var _ = Describe("the update action", func() {
@ -59,14 +60,22 @@ var _ = Describe("the update action", func() {
)
})
When("there are multiple containers using the same image", func() {
It("should only try to remove the image once", func() {
_, err := actions.Update(client, types.UpdateParams{Cleanup: true})
Expect(err).NotTo(HaveOccurred())
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
})
})
//When("there are multiple containers using the same image", func() {
// It("should only try to remove the image once", func() {
//
// _, err := actions.Update(client, types.UpdateParams{Cleanup: true})
// Expect(err).NotTo(HaveOccurred())
// Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
// })
// When("performing a rolling restart update", func() {
// It("should try to remove the image once", func() {
//
// _, err := actions.Update(client, types.UpdateParams{Cleanup: true, RollingRestart: true})
// Expect(err).NotTo(HaveOccurred())
// Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
// })
// })
//})
When("there are multiple containers using different images", func() {
It("should try to remove each of them", func() {
@ -84,7 +93,7 @@ var _ = Describe("the update action", func() {
Expect(err).NotTo(HaveOccurred())
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(2))
})
})
})
})
When("there are containers with and without links", func() {
@ -108,13 +117,13 @@ var _ = Describe("the update action", func() {
"k-container-03",
"k-container-03",
"fake-image:latest",
time.Now().Add(time.Second * 4),
time.Now().Add(time.Second*4),
links[2]),
CreateMockContainer(
"k-container-02",
"k-container-02",
"fake-image:latest",
time.Now().Add(time.Second * 2),
time.Now().Add(time.Second*2),
links[1]),
CreateMockContainer(
"k-container-01",
@ -127,13 +136,13 @@ var _ = Describe("the update action", func() {
"t-container-03",
"t-container-03",
"fake-image-2:latest",
time.Now().Add(time.Second * 4),
time.Now().Add(time.Second*4),
links[5]),
CreateMockContainer(
"t-container-02",
"t-container-02",
"fake-image-2:latest",
time.Now().Add(time.Second * 2),
time.Now().Add(time.Second*2),
links[4]),
CreateMockContainer(
"t-container-01",
@ -152,13 +161,13 @@ var _ = Describe("the update action", func() {
"x-container-02",
"x-container-02",
"fake-image-1:latest",
time.Now().Add(time.Second * 2),
time.Now().Add(time.Second*2),
links[6]),
CreateMockContainer(
"x-container-03",
"x-container-03",
"fake-image-1:latest",
time.Now().Add(time.Second * 4),
time.Now().Add(time.Second*4),
links[6]),
},
},
@ -170,9 +179,10 @@ var _ = Describe("the update action", func() {
When("there are multiple containers with links", func() {
It("should create appropriate dependency sorted lists", func() {
containers, err := actions.PrepareContainerList(client, types.UpdateParams{Cleanup: true})
metric := &metrics.Metric{}
containers, err := actions.ScanForContainerUpdates(client, types.UpdateParams{Cleanup: true}, metric)
undirectedNodes := actions.CreateUndirectedLinks(containers)
dependencySortedGraphs, err := sorter.SortByDependencies(containers,undirectedNodes)
dependencySortedGraphs, err := sorter.SortByDependencies(containers, undirectedNodes)
Expect(err).NotTo(HaveOccurred())
var output [][]string
@ -182,15 +192,15 @@ var _ = Describe("the update action", func() {
for _, j := range i {
inner = append(inner, j.Name())
}
output = append(output,inner)
output = append(output, inner)
}
ExpectedOutput := [][]string{
{"k-container-01", "k-container-02", "k-container-03",},
{"t-container-01", "t-container-02", "t-container-03",},
{"x-container-01",},
{"x-container-02",},
{"x-container-03",},
{"k-container-01", "k-container-02", "k-container-03"},
{"t-container-01", "t-container-02", "t-container-03"},
{"x-container-01"},
{"x-container-02"},
{"x-container-03"},
}
Expect(output).To(Equal(ExpectedOutput))
@ -199,7 +209,7 @@ var _ = Describe("the update action", func() {
When("there are multiple containers using the same image", func() {
It("should stop and restart containers in a correct order", func() {
err := actions.Update(client, types.UpdateParams{Cleanup: true})
_, err := actions.Update(client, types.UpdateParams{Cleanup: true})
Expect(err).NotTo(HaveOccurred())
ExpectedStopOutput := []string{
@ -230,14 +240,7 @@ var _ = Describe("the update action", func() {
Expect(client.TestData.RestartOrder).To(Equal(ExpectedRestartOutput))
})
})
When("performing a rolling restart update", func() {
It("should try to remove the image once", func() {
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, RollingRestart: true})
Expect(err).NotTo(HaveOccurred())
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
})
})
})
When("watchtower has been instructed to monitor only", func() {