Skip to content

Modern Docker Management, Designed for Everyone

fix: honor UI container exclusions in image update discovery (#3763)

Kyle Mendellb9b2092c0e36
diff --git a/backend/internal/imageupdate/image_update.go b/backend/internal/imageupdate/image_update.go
index ad75b2112..8e07ae324 100644
--- a/backend/internal/imageupdate/image_update.go
+++ b/backend/internal/imageupdate/image_update.go
@@ -9,6 +9,7 @@ import (
"fmt"
"log/slog"
"maps"
+ "slices"
"strings"
"sync"
"time"
@@ -712,7 +713,14 @@ func (s *ImageUpdateService) getAllImageRefsInternal(ctx context.Context, limit
return imageRefsFromSummariesInternal(imageList.Items, limit), nil
}
- return filterImageSummariesByContainerOptOutInternal(imageList.Items, containerList.Items, limit), nil
+ excludedContainers := make(map[string]bool)
+ if s.settingsService != nil {
+ for _, name := range settings.ParseExcludedContainerNames(s.settingsService.GetStringSetting(ctx, "autoUpdateExcludedContainers", "")) {
+ excludedContainers[name] = true
+ }
+ }
+
+ return filterImageSummariesByContainerOptOutInternal(imageList.Items, containerList.Items, excludedContainers, limit), nil
}
func imageRefsFromSummariesInternal(images []image.Summary, limit int) []string {
@@ -744,12 +752,14 @@ type imageContainerUsageInternal struct {
eligible bool
}
-func filterImageSummariesByContainerOptOutInternal(images []image.Summary, containers []container.Summary, limit int) []string {
+func filterImageSummariesByContainerOptOutInternal(images []image.Summary, containers []container.Summary, excludedContainers map[string]bool, limit int) []string {
usageByImageID := make(map[string]imageContainerUsageInternal)
usageByRef := make(map[string]imageContainerUsageInternal)
for _, summary := range containers {
- disabled := labels.IsUpdateDisabled(summary.Labels)
+ disabled := labels.IsUpdateDisabled(summary.Labels) || slices.ContainsFunc(summary.Names, func(name string) bool {
+ return excludedContainers[strings.TrimPrefix(name, "/")]
+ })
usage := imageContainerUsageInternal{
optedOut: disabled,
eligible: !disabled,
diff --git a/backend/internal/imageupdate/service_test.go b/backend/internal/imageupdate/service_test.go
index e12aa8f79..a31914d5f 100644
--- a/backend/internal/imageupdate/service_test.go
+++ b/backend/internal/imageupdate/service_test.go
@@ -2250,6 +2250,29 @@ func TestImageUpdateService_GetAllImageRefsFallsBackWhenContainerDiscoveryFailsI
assert.Equal(t, []string{firstRef, secondRef}, got)
}
+func TestFilterImageSummariesByContainerOptOutHonorsSettingsExclusionsInternal(t *testing.T) {
+ const (
+ excludedRef = "local/excluded:latest"
+ sharedRef = "local/shared:latest"
+ )
+
+ images := []dockertypesimage.Summary{
+ {ID: "sha256:excluded", RepoTags: []string{excludedRef}},
+ {ID: "sha256:shared", RepoTags: []string{sharedRef}},
+ }
+ containers := []dockertypescontainer.Summary{
+ {ID: "c1", Names: []string{"/excluded-app"}, ImageID: "sha256:excluded", Image: excludedRef},
+ {ID: "c2", Names: []string{"/shared-excluded"}, ImageID: "sha256:shared", Image: sharedRef},
+ {ID: "c3", Names: []string{"/shared-enabled"}, ImageID: "sha256:shared", Image: sharedRef},
+ }
+ excluded := map[string]bool{"excluded-app": true, "shared-excluded": true, "unknown-name": true}
+
+ got := filterImageSummariesByContainerOptOutInternal(images, containers, excluded, 0)
+
+ assert.NotContains(t, got, excludedRef)
+ assert.Contains(t, got, sharedRef)
+}
+
// testProjectRow is a minimal stand-in for project.Project: the project
// package imports this one, so the in-package test cannot import it back.
type testProjectRow struct {
diff --git a/backend/internal/settings/service.go b/backend/internal/settings/service.go
index a56a55787..d473adc10 100644
--- a/backend/internal/settings/service.go
+++ b/backend/internal/settings/service.go
@@ -938,27 +938,32 @@ func (s *SettingsService) SetStringSetting(ctx context.Context, key, value strin
return s.UpdateSetting(ctx, key, value)
}
+// ParseExcludedContainerNames returns the trimmed, deduplicated names from a comma-separated exclusion list.
+func ParseExcludedContainerNames(raw string) []string {
+ seen := make(map[string]struct{})
+ var ordered []string
+ for part := range strings.SplitSeq(raw, ",") {
+ name := strings.TrimSpace(part)
+ if name == "" {
+ continue
+ }
+ if _, ok := seen[name]; !ok {
+ seen[name] = struct{}{}
+ ordered = append(ordered, name)
+ }
+ }
+ return ordered
+}
+
// SetContainerAutoUpdateExclusionInternal adds or removes a container name from
// the autoUpdateExcludedContainers setting. When excluded is true the container
// is added to the list; when false it is removed.
func (s *SettingsService) SetContainerAutoUpdateExclusionInternal(ctx context.Context, containerName string, excluded bool) error {
_, err := actors.Execute(ctx, s.writes, "update container auto-update exclusion", func(writeCtx context.Context) (actors.NoPayload, error) {
- raw := s.GetStringSetting(writeCtx, "autoUpdateExcludedContainers", "")
- existing := make(map[string]struct{})
- var ordered []string
- for part := range strings.SplitSeq(raw, ",") {
- name := strings.TrimSpace(part)
- if name == "" {
- continue
- }
- if _, ok := existing[name]; !ok {
- existing[name] = struct{}{}
- ordered = append(ordered, name)
- }
- }
+ ordered := ParseExcludedContainerNames(s.GetStringSetting(writeCtx, "autoUpdateExcludedContainers", ""))
if excluded {
- if _, ok := existing[containerName]; !ok {
+ if !slices.Contains(ordered, containerName) {
ordered = append(ordered, containerName)
}
} else {
diff --git a/backend/internal/updater/service.go b/backend/internal/updater/service.go
index 2c4b73811..38961849f 100644
--- a/backend/internal/updater/service.go
+++ b/backend/internal/updater/service.go
@@ -655,15 +655,10 @@ func (s *UpdaterService) ExcludedContainers(ctx context.Context) ([]string, erro
if s == nil {
return nil, nil
}
- excluded := s.buildExcludedContainerSetInternal(ctx)
- if len(excluded) == 0 {
+ if s.deps.Settings == nil {
return nil, nil
}
- out := make([]string, 0, len(excluded))
- for name := range excluded {
- out = append(out, name)
- }
- return out, nil
+ return settings.ParseExcludedContainerNames(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", "")), nil
}
// ProjectByComposeName resolves an Arcane project from a Docker Compose project name.
@@ -1270,15 +1265,13 @@ func (s *UpdaterService) buildExcludedContainerSetInternal(ctx context.Context)
if s.deps.Settings == nil {
return nil
}
- raw := s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", "")
- if raw == "" {
+ names := settings.ParseExcludedContainerNames(s.deps.Settings.GetStringSetting(ctx, "autoUpdateExcludedContainers", ""))
+ if len(names) == 0 {
return nil
}
- excluded := make(map[string]bool)
- for part := range strings.SplitSeq(raw, ",") {
- if name := strings.TrimSpace(part); name != "" {
- excluded[name] = true
- }
+ excluded := make(map[string]bool, len(names))
+ for _, name := range names {
+ excluded[name] = true
}
return excluded
}