mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
fix: use new healthcheck config if not overridden (#1801)
This commit is contained in:
parent
72e437f173
commit
40b8c77100
3 changed files with 93 additions and 1 deletions
|
@ -304,6 +304,27 @@ func (c Container) GetCreateConfig() *dockercontainer.Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear HEALTHCHECK configuration (if default)
|
||||||
|
if util.SliceEqual(config.Healthcheck.Test, imageConfig.Healthcheck.Test) {
|
||||||
|
config.Healthcheck.Test = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Healthcheck.Retries == imageConfig.Healthcheck.Retries {
|
||||||
|
config.Healthcheck.Retries = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Healthcheck.Interval == imageConfig.Healthcheck.Interval {
|
||||||
|
config.Healthcheck.Interval = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Healthcheck.Timeout == imageConfig.Healthcheck.Timeout {
|
||||||
|
config.Healthcheck.Timeout = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Healthcheck.StartPeriod == imageConfig.Healthcheck.StartPeriod {
|
||||||
|
config.Healthcheck.StartPeriod = 0
|
||||||
|
}
|
||||||
|
|
||||||
config.Env = util.SliceSubtract(config.Env, imageConfig.Env)
|
config.Env = util.SliceSubtract(config.Env, imageConfig.Env)
|
||||||
|
|
||||||
config.Labels = util.StringMapSubtract(config.Labels, imageConfig.Labels)
|
config.Labels = util.StringMapSubtract(config.Labels, imageConfig.Labels)
|
||||||
|
|
|
@ -22,6 +22,7 @@ func MockContainer(updates ...MockContainerUpdate) *Container {
|
||||||
}
|
}
|
||||||
image := types.ImageInspect{
|
image := types.ImageInspect{
|
||||||
ID: "image_id",
|
ID: "image_id",
|
||||||
|
Config: &dockerContainer.Config{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, update := range updates {
|
for _, update := range updates {
|
||||||
|
@ -64,3 +65,15 @@ func WithContainerState(state types.ContainerState) MockContainerUpdate {
|
||||||
cnt.State = &state
|
cnt.State = &state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithHealthcheck(healthConfig dockerContainer.HealthConfig) MockContainerUpdate {
|
||||||
|
return func(cnt *types.ContainerJSON, img *types.ImageInspect) {
|
||||||
|
cnt.Config.Healthcheck = &healthConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithImageHealthcheck(healthConfig dockerContainer.HealthConfig) MockContainerUpdate {
|
||||||
|
return func(cnt *types.ContainerJSON, img *types.ImageInspect) {
|
||||||
|
img.Config.Healthcheck = &healthConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containrrr/watchtower/pkg/types"
|
"github.com/containrrr/watchtower/pkg/types"
|
||||||
|
dc "github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -67,6 +68,63 @@ var _ = Describe("the container", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Describe("GetCreateConfig", func() {
|
||||||
|
When("container healthcheck config is equal to image config", func() {
|
||||||
|
It("should return empty healthcheck values", func() {
|
||||||
|
c := MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||||
|
Test: []string{"/usr/bin/sleep", "1s"},
|
||||||
|
}), WithImageHealthcheck(dc.HealthConfig{
|
||||||
|
Test: []string{"/usr/bin/sleep", "1s"},
|
||||||
|
}))
|
||||||
|
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||||
|
|
||||||
|
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||||
|
Timeout: 30,
|
||||||
|
}), WithImageHealthcheck(dc.HealthConfig{
|
||||||
|
Timeout: 30,
|
||||||
|
}))
|
||||||
|
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||||
|
|
||||||
|
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||||
|
StartPeriod: 30,
|
||||||
|
}), WithImageHealthcheck(dc.HealthConfig{
|
||||||
|
StartPeriod: 30,
|
||||||
|
}))
|
||||||
|
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||||
|
|
||||||
|
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||||
|
Retries: 30,
|
||||||
|
}), WithImageHealthcheck(dc.HealthConfig{
|
||||||
|
Retries: 30,
|
||||||
|
}))
|
||||||
|
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("container healthcheck config is different to image config", func() {
|
||||||
|
It("should return the container healthcheck values", func() {
|
||||||
|
c := MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||||
|
Test: []string{"/usr/bin/sleep", "1s"},
|
||||||
|
Interval: 30,
|
||||||
|
Timeout: 30,
|
||||||
|
StartPeriod: 10,
|
||||||
|
Retries: 2,
|
||||||
|
}), WithImageHealthcheck(dc.HealthConfig{
|
||||||
|
Test: []string{"/usr/bin/sleep", "10s"},
|
||||||
|
Interval: 10,
|
||||||
|
Timeout: 60,
|
||||||
|
StartPeriod: 30,
|
||||||
|
Retries: 10,
|
||||||
|
}))
|
||||||
|
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{
|
||||||
|
Test: []string{"/usr/bin/sleep", "1s"},
|
||||||
|
Interval: 30,
|
||||||
|
Timeout: 30,
|
||||||
|
StartPeriod: 10,
|
||||||
|
Retries: 2,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
When("asked for metadata", func() {
|
When("asked for metadata", func() {
|
||||||
var c *Container
|
var c *Container
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue