Skip to content

Commit

Permalink
fix: set nopull param from args (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Nov 11, 2023
1 parent 7fb04d0 commit 48539c4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
scheduleSpec string
cleanup bool
noRestart bool
noPull bool
monitorOnly bool
enableLabel bool
disableContainers []string
Expand Down Expand Up @@ -110,7 +111,7 @@ func PreRun(cmd *cobra.Command, _ []string) {
log.Fatal(err)
}

noPull, _ := f.GetBool("no-pull")
noPull, _ = f.GetBool("no-pull")
includeStopped, _ := f.GetBool("include-stopped")
includeRestarting, _ := f.GetBool("include-restarting")
reviveStopped, _ := f.GetBool("revive-stopped")
Expand All @@ -122,7 +123,6 @@ func PreRun(cmd *cobra.Command, _ []string) {
}

client = container.NewClient(container.ClientOptions{
PullImages: !noPull,
IncludeStopped: includeStopped,
ReviveStopped: reviveStopped,
RemoveVolumes: removeVolumes,
Expand Down Expand Up @@ -187,7 +187,7 @@ func Run(c *cobra.Command, names []string) {
metrics.RegisterScan(metric)
}, updateLock)
httpAPI.RegisterFunc(updateHandler.Path, updateHandler.Handle)
// If polling isn't enabled the scheduler is never started and
// If polling isn't enabled the scheduler is never started, and
// we need to trigger the startup messages manually.
if !unblockHTTPAPI {
writeStartupMessage(c, time.Time{}, filterDesc)
Expand Down Expand Up @@ -367,6 +367,7 @@ func runUpdatesWithNotifications(filter t.Filter) *metrics.Metric {
LifecycleHooks: lifecycleHooks,
RollingRestart: rollingRestart,
LabelPrecedence: labelPrecedence,
NoPull: noPull,
}
result, err := actions.Update(client, updateParams)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func NewClient(opts ClientOptions) Client {

// ClientOptions contains the options for how the docker client wrapper should behave
type ClientOptions struct {
PullImages bool
RemoveVolumes bool
IncludeStopped bool
ReviveStopped bool
Expand Down
23 changes: 12 additions & 11 deletions pkg/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ var _ = Describe("the client", func() {
It("should gracefully fail with a useful message", func() {
c := dockerClient{}
pinnedContainer := MockContainer(WithImageName("sha256:fa5269854a5e615e51a72b17ad3fd1e01268f278a6684c8ed3c5f0cdce3f230b"))
c.PullImage(context.Background(), pinnedContainer)
err := c.PullImage(context.Background(), pinnedContainer)
Expect(err).To(MatchError(`container uses a pinned image, and cannot be updated by watchtower`))
})
})
})
Expand Down Expand Up @@ -144,7 +145,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&mocks.Watchtower, &mocks.Running)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}
containers, err := client.ListContainers(filters.NoFilter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -158,7 +159,7 @@ var _ = Describe("the client", func() {
filter := filters.FilterByNames([]string{"lollercoaster"}, filters.NoFilter)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}
containers, err := client.ListContainers(filter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -171,7 +172,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&mocks.Watchtower, &mocks.Running)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}
containers, err := client.ListContainers(filters.WatchtowerContainersFilter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -184,7 +185,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&mocks.Stopped, &mocks.Watchtower, &mocks.Running)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false, IncludeStopped: true},
ClientOptions: ClientOptions{IncludeStopped: true},
}
containers, err := client.ListContainers(filters.NoFilter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -197,7 +198,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&mocks.Watchtower, &mocks.Running, &mocks.Restarting)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false, IncludeRestarting: true},
ClientOptions: ClientOptions{IncludeRestarting: true},
}
containers, err := client.ListContainers(filters.NoFilter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -210,7 +211,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&mocks.Watchtower, &mocks.Running)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false, IncludeRestarting: false},
ClientOptions: ClientOptions{IncludeRestarting: false},
}
containers, err := client.ListContainers(filters.NoFilter)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -224,7 +225,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&consumerContainerRef)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}
container, err := client.GetContainer(consumerContainerRef.ContainerID())
Expect(err).NotTo(HaveOccurred())
Expand All @@ -238,7 +239,7 @@ var _ = Describe("the client", func() {
mockServer.AppendHandlers(mocks.GetContainerHandlers(&consumerContainerRef)...)
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}
container, err := client.GetContainer(consumerContainerRef.ContainerID())
Expect(err).NotTo(HaveOccurred())
Expand All @@ -253,7 +254,7 @@ var _ = Describe("the client", func() {
It("should include container id field", func() {
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false},
ClientOptions: ClientOptions{},
}

// Capture logrus output in buffer
Expand Down Expand Up @@ -320,7 +321,7 @@ var _ = Describe("the client", func() {
It(`should omit the container ID alias`, func() {
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false, IncludeRestarting: false},
ClientOptions: ClientOptions{IncludeRestarting: false},
}
container := MockContainer(WithImageName("docker.io/prefix/imagename:latest"))

Expand Down
4 changes: 2 additions & 2 deletions pkg/notifications/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (n *shoutrrrTypeNotifier) GetNames() []string {
return names
}

// GetNames returns a list of URLs for notification services that has been added
// GetURLs returns a list of URLs for notification services that has been added
func (n *shoutrrrTypeNotifier) GetURLs() []string {
return n.Urls
}
Expand All @@ -73,7 +73,7 @@ func (n *shoutrrrTypeNotifier) AddLogHook() {
n.receiving = true
log.AddHook(n)

// Do the sending in a separate goroutine so we don't block the main process.
// Do the sending in a separate goroutine, so we don't block the main process.
go sendNotifications(n)
}

Expand Down

0 comments on commit 48539c4

Please sign in to comment.