diff --git a/internal/actions/update.go b/internal/actions/update.go index 436b2d8..a242b4f 100644 --- a/internal/actions/update.go +++ b/internal/actions/update.go @@ -34,7 +34,7 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e for i, targetContainer := range containers { 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 { // Check to make sure we have all the necessary information for recreating the container err = targetContainer.VerifyConfiguration() @@ -72,12 +72,10 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e UpdateImplicitRestart(containers) var containersToUpdate []types.Container - if ( !params.MonitorOnly || params.LabelPrecedence ) { - for _, c := range containers { - if !c.IsMonitorOnly() { - containersToUpdate = append(containersToUpdate, c) - progress.MarkForUpdate(c.ID()) - } + for _, c := range containers { + if !c.IsMonitorOnly(params) { + containersToUpdate = append(containersToUpdate, c) + progress.MarkForUpdate(c.ID()) } } diff --git a/internal/actions/update_test.go b/internal/actions/update_test.go index 467439c..03fdfbf 100644 --- a/internal/actions/update_test.go +++ b/internal/actions/update_test.go @@ -178,22 +178,17 @@ var _ = Describe("the update action", func() { 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(client.TestData.TriedToRemoveImageCount).To(Equal(0)) }) 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( &TestData{ - NameOfContainerToKeep: "test-container-02", + //NameOfContainerToKeep: "test-container-02", Containers: []types.Container{ - CreateMockContainer( - "test-container-01", - "test-container-01", - "fake-image1:latest", - time.Now()), CreateMockContainerWithConfig( "test-container-02", "test-container-02", @@ -211,8 +206,8 @@ var _ = Describe("the update action", func() { false, false, ) - _, err := actions.Update(client, types.UpdateParams{MonitorOnly: true, LabelPrecedence: true}) - Expect(err).To(HaveOccurred()) + _, err := actions.Update(client, types.UpdateParams{Cleanup: true, MonitorOnly: true, LabelPrecedence: true}) + Expect(err).NotTo(HaveOccurred()) Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1)) }) }) diff --git a/oryxBuildBinary b/oryxBuildBinary new file mode 100755 index 0000000..86cbe57 Binary files /dev/null and b/oryxBuildBinary differ diff --git a/pkg/container/container.go b/pkg/container/container.go index 0f78f62..7f7b078 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -129,20 +129,43 @@ func (c Container) Enabled() (bool, bool) { return parsedBool, true } -// IsMonitorOnly returns the value of the monitor-only label. If the label -// is not set then false is returned. -func (c Container) IsMonitorOnly() bool { +// IsMonitorOnly returns whether the container should only be monitored based on values of +// the monitor-only label, the monitor-only argument and the label-take-precedence argument. +func (c Container) IsMonitorOnly(params wt.UpdateParams) bool { + var containerMonitorOnlyLabel bool + + MonitorOnlyLabelIsDefined := false + rawBool, ok := c.getLabelValue(monitorOnlyLabel) - if !ok { - return false + if ok { + 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) - if err != nil { - return false + // 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 params.MonitorOnly { + 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 diff --git a/pkg/types/container.go b/pkg/types/container.go index 752fd11..8f82033 100644 --- a/pkg/types/container.go +++ b/pkg/types/container.go @@ -52,7 +52,7 @@ type Container interface { SafeImageID() ImageID ImageName() string Enabled() (bool, bool) - IsMonitorOnly() bool + IsMonitorOnly(UpdateParams) bool Scope() (string, bool) Links() []string ToRestart() bool