This commit is contained in:
Tycho Andersen 2024-04-20 09:40:58 +02:00 committed by GitHub
commit c9acfc2589
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 51 additions and 9 deletions

View file

@ -73,10 +73,11 @@ type Config struct {
// Mac Address of the container.
//
// Deprecated: this field is deprecated since API v1.44. Use EndpointSettings.MacAddress instead.
MacAddress string `json:",omitempty"`
OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile
Labels map[string]string // List of labels set to this container
StopSignal string `json:",omitempty"` // Signal to stop a container
StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container
Shell strslice.StrSlice `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT
MacAddress string `json:",omitempty"`
OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile
Labels map[string]string // List of labels set to this container
StopSignal string `json:",omitempty"` // Signal to stop a container
StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container
DeleteTimeout *int `json:",omitempty"` // Timeout (in seconds) to wait for a container to be deleted
Shell strslice.StrSlice `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT
}

View file

@ -45,8 +45,9 @@ import (
)
const (
configFileName = "config.v2.json"
hostConfigFileName = "hostconfig.json"
configFileName = "config.v2.json"
hostConfigFileName = "hostconfig.json"
defaultDeleteTimeout = 30
)
// ExitStatus provides exit reasons for a container.
@ -562,6 +563,15 @@ func (container *Container) StopTimeout() int {
return defaultStopTimeout
}
// DeleteTimeout returns the timeout (in seconds) to wait for a container to be deleted.
func (container *Container) DeleteTimeout() int {
if container.Config.DeleteTimeout != nil {
return *container.Config.DeleteTimeout
}
return defaultDeleteTimeout
}
// InitDNSHostConfig ensures that the dns fields are never nil.
// New containers don't ever have those fields nil,
// but pre created containers can still have those nil values.

View file

@ -57,6 +57,26 @@ func TestContainerStopTimeout(t *testing.T) {
}
}
func TestContainerDeleteTimeout(t *testing.T) {
c := &Container{
Config: &container.Config{},
}
s := c.DeleteTimeout()
if s != defaultDeleteTimeout {
t.Fatalf("Expected %v, got %v", defaultDeleteTimeout, s)
}
deleteTimeout := 15
c = &Container{
Config: &container.Config{DeleteTimeout: &deleteTimeout},
}
s = c.DeleteTimeout()
if s != deleteTimeout {
t.Fatalf("Expected %v, got %v", deleteTimeout, s)
}
}
func TestContainerSecretReferenceDestTarget(t *testing.T) {
ref := &swarmtypes.SecretReference{
File: &swarmtypes.SecretReferenceFileTarget{

View file

@ -39,7 +39,8 @@ func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontaine
tsk, ok := c.Task()
if ok {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
deleteTimeout := time.Duration(c.DeleteTimeout()) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), deleteTimeout)
es, err := tsk.Delete(ctx)
cancel()
if err != nil {

View file

@ -149,6 +149,16 @@ func compare(a, b *container.Config) bool {
return false
}
}
if (a.DeleteTimeout == nil) != (b.DeleteTimeout == nil) {
return false
}
if a.DeleteTimeout != nil && b.DeleteTimeout != nil {
if *a.DeleteTimeout != *b.DeleteTimeout {
return false
}
}
if (a.Healthcheck == nil) != (b.Healthcheck == nil) {
return false
}