mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-17 23:50:13 +01:00
Add the label take precedence check in isMonitorOnly()
This commit is contained in:
parent
3d4bac9c78
commit
ca227f5a57
5 changed files with 43 additions and 27 deletions
|
|
@ -34,7 +34,7 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e
|
||||||
|
|
||||||
for i, targetContainer := range containers {
|
for i, targetContainer := range containers {
|
||||||
stale, newestImage, err := client.IsContainerStale(targetContainer)
|
stale, newestImage, err := client.IsContainerStale(targetContainer)
|
||||||
shouldUpdate := stale && !params.NoRestart && (( !params.MonitorOnly && !targetContainer.IsMonitorOnly() ) || ( params.LabelPrecedence && !targetContainer.IsMonitorOnly() ))
|
shouldUpdate := stale && !params.NoRestart && !targetContainer.IsMonitorOnly(params)
|
||||||
if err == nil && shouldUpdate {
|
if err == nil && shouldUpdate {
|
||||||
// Check to make sure we have all the necessary information for recreating the container
|
// Check to make sure we have all the necessary information for recreating the container
|
||||||
err = targetContainer.VerifyConfiguration()
|
err = targetContainer.VerifyConfiguration()
|
||||||
|
|
@ -72,12 +72,10 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e
|
||||||
UpdateImplicitRestart(containers)
|
UpdateImplicitRestart(containers)
|
||||||
|
|
||||||
var containersToUpdate []types.Container
|
var containersToUpdate []types.Container
|
||||||
if ( !params.MonitorOnly || params.LabelPrecedence ) {
|
for _, c := range containers {
|
||||||
for _, c := range containers {
|
if !c.IsMonitorOnly(params) {
|
||||||
if !c.IsMonitorOnly() {
|
containersToUpdate = append(containersToUpdate, c)
|
||||||
containersToUpdate = append(containersToUpdate, c)
|
progress.MarkForUpdate(c.ID())
|
||||||
progress.MarkForUpdate(c.ID())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,22 +178,17 @@ var _ = Describe("the update action", func() {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
_, err := actions.Update(client, types.UpdateParams{MonitorOnly: true})
|
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, MonitorOnly: true})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0))
|
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
When("watchtower has been instructed to have label take precedence", func() {
|
When("watchtower has been instructed to have label take precedence", func() {
|
||||||
It("it should update containers with monitor only set to false", func() {
|
It("it should update containers when monitor only is set to false", func() {
|
||||||
client := CreateMockClient(
|
client := CreateMockClient(
|
||||||
&TestData{
|
&TestData{
|
||||||
NameOfContainerToKeep: "test-container-02",
|
//NameOfContainerToKeep: "test-container-02",
|
||||||
Containers: []types.Container{
|
Containers: []types.Container{
|
||||||
CreateMockContainer(
|
|
||||||
"test-container-01",
|
|
||||||
"test-container-01",
|
|
||||||
"fake-image1:latest",
|
|
||||||
time.Now()),
|
|
||||||
CreateMockContainerWithConfig(
|
CreateMockContainerWithConfig(
|
||||||
"test-container-02",
|
"test-container-02",
|
||||||
"test-container-02",
|
"test-container-02",
|
||||||
|
|
@ -211,8 +206,8 @@ var _ = Describe("the update action", func() {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
_, err := actions.Update(client, types.UpdateParams{MonitorOnly: true, LabelPrecedence: true})
|
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, MonitorOnly: true, LabelPrecedence: true})
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
BIN
oryxBuildBinary
Executable file
BIN
oryxBuildBinary
Executable file
Binary file not shown.
|
|
@ -129,20 +129,43 @@ func (c Container) Enabled() (bool, bool) {
|
||||||
return parsedBool, true
|
return parsedBool, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMonitorOnly returns the value of the monitor-only label. If the label
|
// IsMonitorOnly returns whether the container should only be monitored based on values of
|
||||||
// is not set then false is returned.
|
// the monitor-only label, the monitor-only argument and the label-take-precedence argument.
|
||||||
func (c Container) IsMonitorOnly() bool {
|
func (c Container) IsMonitorOnly(params wt.UpdateParams) bool {
|
||||||
|
var containerMonitorOnlyLabel bool
|
||||||
|
|
||||||
|
MonitorOnlyLabelIsDefined := false
|
||||||
|
|
||||||
rawBool, ok := c.getLabelValue(monitorOnlyLabel)
|
rawBool, ok := c.getLabelValue(monitorOnlyLabel)
|
||||||
if !ok {
|
if ok {
|
||||||
return false
|
parsedBool, err := strconv.ParseBool(rawBool)
|
||||||
|
if err == nil {
|
||||||
|
MonitorOnlyLabelIsDefined = true
|
||||||
|
containerMonitorOnlyLabel = parsedBool
|
||||||
|
} else {
|
||||||
|
// Defaulting to false
|
||||||
|
containerMonitorOnlyLabel = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Defaulting to false
|
||||||
|
containerMonitorOnlyLabel = false
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedBool, err := strconv.ParseBool(rawBool)
|
// in case MonitorOnly argument is true, the results change if the container monitor-only label is explicitly set to false if the label-take-precedence is true
|
||||||
if err != nil {
|
if params.MonitorOnly {
|
||||||
return false
|
if (MonitorOnlyLabelIsDefined) {
|
||||||
|
if params.LabelPrecedence {
|
||||||
|
return containerMonitorOnlyLabel
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return containerMonitorOnlyLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedBool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNoPull returns the value of the no-pull label. If the label is not set
|
// IsNoPull returns the value of the no-pull label. If the label is not set
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ type Container interface {
|
||||||
SafeImageID() ImageID
|
SafeImageID() ImageID
|
||||||
ImageName() string
|
ImageName() string
|
||||||
Enabled() (bool, bool)
|
Enabled() (bool, bool)
|
||||||
IsMonitorOnly() bool
|
IsMonitorOnly(UpdateParams) bool
|
||||||
Scope() (string, bool)
|
Scope() (string, bool)
|
||||||
Links() []string
|
Links() []string
|
||||||
ToRestart() bool
|
ToRestart() bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue