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 (
"context"
"crypto"
"docker-updater/config"
"docker-updater/constant"
"docker-updater/contextutil"
"encoding/hex"
"fmt"
"io"
"log/slog"
@@ -55,15 +53,9 @@ type (
name string
image Image
status container.ContainerState
labels Labels
appliedConfiguration config.ContainerConfiguration
}
Labels struct {
labels map[string]string
hash string
}
Image struct {
id string
name string
@@ -169,9 +161,10 @@ func (w *watcher) Watch(ctx context.Context, dh *DockerHelper) {
for _, runningContainer := range runningContainers {
if foundContainer, ok := dh.w.cache.containers[runningContainer.name]; ok {
if runningContainer.labels.hash != foundContainer.c.labels.hash {
foundContainer.c = runningContainer
dh.w.cache.containers[runningContainer.name] = foundContainer
if runningContainer.id != foundContainer.c.id {
dh.w.cache.containers[runningContainer.name] = cacheEntry{
c: runningContainer,
}
dh.w.containersEventCallback(ContainerEvent{
ctx: ctx,
@@ -437,7 +430,6 @@ func (dh *DockerHelper) parseContainer(ctx context.Context, container container.
id: container.ID,
name: name,
status: container.State,
labels: convertLabels(container.Labels),
appliedConfiguration: config,
image: Image{
id: container.ImageID,
@@ -459,22 +451,6 @@ func formatName(names []string) string {
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) {
c := dh.config.GlobalContainerConfiguration