fix bad container detection

This commit is contained in:
2026-02-09 00:07:17 +01:00
parent 3bfca34f3a
commit ccd3bfadb4
2 changed files with 9 additions and 28 deletions

View File

@@ -2,11 +2,9 @@ package helper
import ( import (
"context" "context"
"crypto"
"docker-updater/config" "docker-updater/config"
"docker-updater/constant" "docker-updater/constant"
"docker-updater/contextutil" "docker-updater/contextutil"
"encoding/hex"
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
@@ -55,15 +53,9 @@ type (
name string name string
image Image image Image
status container.ContainerState status container.ContainerState
labels Labels
appliedConfiguration config.ContainerConfiguration appliedConfiguration config.ContainerConfiguration
} }
Labels struct {
labels map[string]string
hash string
}
Image struct { Image struct {
id string id string
name string name string
@@ -169,9 +161,10 @@ func (w *watcher) Watch(ctx context.Context, dh *DockerHelper) {
for _, runningContainer := range runningContainers { for _, runningContainer := range runningContainers {
if foundContainer, ok := dh.w.cache.containers[runningContainer.name]; ok { if foundContainer, ok := dh.w.cache.containers[runningContainer.name]; ok {
if runningContainer.labels.hash != foundContainer.c.labels.hash { if runningContainer.id != foundContainer.c.id {
foundContainer.c = runningContainer dh.w.cache.containers[runningContainer.name] = cacheEntry{
dh.w.cache.containers[runningContainer.name] = foundContainer c: runningContainer,
}
dh.w.containersEventCallback(ContainerEvent{ dh.w.containersEventCallback(ContainerEvent{
ctx: ctx, ctx: ctx,
@@ -437,7 +430,6 @@ func (dh *DockerHelper) parseContainer(ctx context.Context, container container.
id: container.ID, id: container.ID,
name: name, name: name,
status: container.State, status: container.State,
labels: convertLabels(container.Labels),
appliedConfiguration: config, appliedConfiguration: config,
image: Image{ image: Image{
id: container.ImageID, id: container.ImageID,
@@ -459,22 +451,6 @@ func formatName(names []string) string {
return name return name
} }
func convertLabels(labels map[string]string) Labels {
var p string
for key, value := range labels {
p += key + ":" + value
}
md5 := crypto.MD5.New()
hash := md5.Sum([]byte(p))
return Labels{
labels: labels,
hash: hex.EncodeToString(hash),
}
}
func (dh *DockerHelper) parseLocalConfiguration(labels map[string]string) (config.ContainerConfiguration, error) { func (dh *DockerHelper) parseLocalConfiguration(labels map[string]string) (config.ContainerConfiguration, error) {
c := dh.config.GlobalContainerConfiguration c := dh.config.GlobalContainerConfiguration

View File

@@ -218,6 +218,11 @@ func (el *EventLoop) process(ev helper.ContainerEvent) {
case helper.DeletedContainer: case helper.DeletedContainer:
{ {
el.unregister(container) el.unregister(container)
slog.Info("a container was unregistered",
"thread", "event_loop",
"container_name", container.Name(),
"container_id", container.ID(),
)
} }
case helper.UpdatedContainer: case helper.UpdatedContainer:
{ {