From 75cc6b8c6501aac5a3f052862771f920c9e06985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nedz=CC=8Cad=20Alibegovic=CC=81?= Date: Fri, 7 Oct 2022 21:30:46 +0200 Subject: [PATCH] feat: add no-pull label for containers --- pkg/container/client.go | 2 +- pkg/container/container.go | 16 ++++++++++++++++ pkg/container/metadata.go | 25 +++++++++++++------------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/container/client.go b/pkg/container/client.go index 7447828..7f133e1 100644 --- a/pkg/container/client.go +++ b/pkg/container/client.go @@ -280,7 +280,7 @@ func (client dockerClient) RenameContainer(c Container, newName string) error { func (client dockerClient) IsContainerStale(container Container) (stale bool, latestImage t.ImageID, err error) { ctx := context.Background() - if !client.PullImages { + if !client.PullImages || container.IsNoPull() { log.Debugf("Skipping image pull.") } else if err := client.PullImage(ctx, container); err != nil { return false, container.SafeImageID(), err diff --git a/pkg/container/container.go b/pkg/container/container.go index 0bbea16..36abe8c 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -125,6 +125,22 @@ func (c Container) IsMonitorOnly() bool { return parsedBool } +// IsNoPull returns the value of the no-pull label. If the label is not set +// then false is returned. +func (c Container) IsNoPull() bool { + rawBool, ok := c.getLabelValue(noPullLabel) + if !ok { + return false + } + + parsedBool, err := strconv.ParseBool(rawBool) + if err != nil { + return false + } + + return parsedBool +} + // Scope returns the value of the scope UID label and if the label // was set. func (c Container) Scope() (string, bool) { diff --git a/pkg/container/metadata.go b/pkg/container/metadata.go index ee9fddf..74a04cb 100644 --- a/pkg/container/metadata.go +++ b/pkg/container/metadata.go @@ -1,18 +1,19 @@ package container const ( - watchtowerLabel = "com.centurylinklabs.watchtower" - signalLabel = "com.centurylinklabs.watchtower.stop-signal" - enableLabel = "com.centurylinklabs.watchtower.enable" - monitorOnlyLabel = "com.centurylinklabs.watchtower.monitor-only" - dependsOnLabel = "com.centurylinklabs.watchtower.depends-on" - zodiacLabel = "com.centurylinklabs.zodiac.original-image" - scope = "com.centurylinklabs.watchtower.scope" - preCheckLabel = "com.centurylinklabs.watchtower.lifecycle.pre-check" - postCheckLabel = "com.centurylinklabs.watchtower.lifecycle.post-check" - preUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update" - postUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.post-update" - preUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update-timeout" + watchtowerLabel = "com.centurylinklabs.watchtower" + signalLabel = "com.centurylinklabs.watchtower.stop-signal" + enableLabel = "com.centurylinklabs.watchtower.enable" + monitorOnlyLabel = "com.centurylinklabs.watchtower.monitor-only" + noPullLabel = "com.centurylinklabs.watchtower.no-pull" + dependsOnLabel = "com.centurylinklabs.watchtower.depends-on" + zodiacLabel = "com.centurylinklabs.zodiac.original-image" + scope = "com.centurylinklabs.watchtower.scope" + preCheckLabel = "com.centurylinklabs.watchtower.lifecycle.pre-check" + postCheckLabel = "com.centurylinklabs.watchtower.lifecycle.post-check" + preUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update" + postUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.post-update" + preUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update-timeout" postUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.post-update-timeout" )