mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
feat: check container config before update (#925)
* feat: check container config before restart * fix: only skip when hostconfig and config differ * fix: update test mocks to not fail tests * test: add verify config tests
This commit is contained in:
parent
fdf6e46e7b
commit
12467712a1
6 changed files with 151 additions and 13 deletions
|
@ -16,10 +16,13 @@ func CreateMockContainer(id string, name string, image string, created time.Time
|
|||
Image: image,
|
||||
Name: name,
|
||||
Created: created.String(),
|
||||
HostConfig: &container2.HostConfig{
|
||||
PortBindings: map[nat.Port][]nat.PortBinding{},
|
||||
},
|
||||
},
|
||||
Config: &container2.Config{
|
||||
Image: image,
|
||||
Labels: make(map[string]string),
|
||||
Image: image,
|
||||
Labels: make(map[string]string),
|
||||
ExposedPorts: map[nat.Port]struct{}{},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package actions
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/containrrr/watchtower/internal/util"
|
||||
"github.com/containrrr/watchtower/pkg/container"
|
||||
"github.com/containrrr/watchtower/pkg/lifecycle"
|
||||
|
@ -33,11 +32,23 @@ func Update(client container.Client, params types.UpdateParams) (*metrics2.Metri
|
|||
|
||||
for i, targetContainer := range containers {
|
||||
stale, err := client.IsContainerStale(targetContainer)
|
||||
if stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.IsMonitorOnly() && !targetContainer.HasImageInfo() {
|
||||
err = errors.New("no available image info")
|
||||
shouldUpdate := stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.IsMonitorOnly()
|
||||
if err == nil && shouldUpdate {
|
||||
// Check to make sure we have all the necessary information for recreating the container
|
||||
err = targetContainer.VerifyConfiguration()
|
||||
// If the image information is incomplete and trace logging is enabled, log it for further diagnosis
|
||||
if err != nil && log.IsLevelEnabled(log.TraceLevel) {
|
||||
imageInfo := targetContainer.ImageInfo()
|
||||
log.Tracef("Image info: %#v", imageInfo)
|
||||
log.Tracef("Container info: %#v", targetContainer.ContainerInfo())
|
||||
if imageInfo != nil {
|
||||
log.Tracef("Image config: %#v", imageInfo.Config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Infof("Unable to update container %q: %v. Proceeding to next.", containers[i].Name(), err)
|
||||
log.Infof("Unable to update container %q: %v. Proceeding to next.", targetContainer.Name(), err)
|
||||
stale = false
|
||||
staleCheckFailed++
|
||||
metric.Failed++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue