fix: handle missing healthcheck keys in config (#1810)

pull/1811/head
nils måsén 1 year ago committed by GitHub
parent dd54055143
commit c4d493881d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -305,24 +305,26 @@ func (c Container) GetCreateConfig() *dockercontainer.Config {
} }
// Clear HEALTHCHECK configuration (if default) // Clear HEALTHCHECK configuration (if default)
if util.SliceEqual(config.Healthcheck.Test, imageConfig.Healthcheck.Test) { if config.Healthcheck != nil && imageConfig.Healthcheck != nil {
config.Healthcheck.Test = nil if util.SliceEqual(config.Healthcheck.Test, imageConfig.Healthcheck.Test) {
} config.Healthcheck.Test = nil
}
if config.Healthcheck.Retries == imageConfig.Healthcheck.Retries { if config.Healthcheck.Retries == imageConfig.Healthcheck.Retries {
config.Healthcheck.Retries = 0 config.Healthcheck.Retries = 0
} }
if config.Healthcheck.Interval == imageConfig.Healthcheck.Interval { if config.Healthcheck.Interval == imageConfig.Healthcheck.Interval {
config.Healthcheck.Interval = 0 config.Healthcheck.Interval = 0
} }
if config.Healthcheck.Timeout == imageConfig.Healthcheck.Timeout { if config.Healthcheck.Timeout == imageConfig.Healthcheck.Timeout {
config.Healthcheck.Timeout = 0 config.Healthcheck.Timeout = 0
} }
if config.Healthcheck.StartPeriod == imageConfig.Healthcheck.StartPeriod { if config.Healthcheck.StartPeriod == imageConfig.Healthcheck.StartPeriod {
config.Healthcheck.StartPeriod = 0 config.Healthcheck.StartPeriod = 0
}
} }
config.Env = util.SliceSubtract(config.Env, imageConfig.Env) config.Env = util.SliceSubtract(config.Env, imageConfig.Env)

@ -124,6 +124,36 @@ var _ = Describe("the container", func() {
})) }))
}) })
}) })
When("container healthcheck config is empty", func() {
It("should not panic", func() {
c := MockContainer(WithImageHealthcheck(dc.HealthConfig{
Test: []string{"/usr/bin/sleep", "10s"},
Interval: 10,
Timeout: 60,
StartPeriod: 30,
Retries: 10,
}))
Expect(c.GetCreateConfig().Healthcheck).To(BeNil())
})
})
When("container image healthcheck config is empty", func() {
It("should not panic", func() {
c := MockContainer(WithHealthcheck(dc.HealthConfig{
Test: []string{"/usr/bin/sleep", "1s"},
Interval: 30,
Timeout: 30,
StartPeriod: 10,
Retries: 2,
}))
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

Loading…
Cancel
Save