mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
Merge pull request #51804 from thaJeztah/no_shadow
daemon: minor cleanup and linting fixes
This commit is contained in:
@@ -37,22 +37,11 @@ func TestHealthStates(t *testing.T) {
|
||||
Annotations: api.Annotations{Name: "name"},
|
||||
}
|
||||
|
||||
c := &container.Container{
|
||||
ID: "id",
|
||||
Name: "name",
|
||||
Config: &containertypes.Config{
|
||||
Image: "image_name",
|
||||
Labels: map[string]string{
|
||||
"com.docker.swarm.task.id": "id",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
daemon := &daemon.Daemon{
|
||||
EventsService: e,
|
||||
}
|
||||
|
||||
controller, err := newController(daemon, nil, nil, task, nil, nil)
|
||||
ctrlr, err := newController(daemon, nil, nil, task, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("create controller fail %v", err)
|
||||
}
|
||||
@@ -62,7 +51,7 @@ func TestHealthStates(t *testing.T) {
|
||||
|
||||
// fire checkHealth
|
||||
go func() {
|
||||
err := controller.checkHealth(ctx)
|
||||
err := ctrlr.checkHealth(ctx)
|
||||
select {
|
||||
case errChan <- err:
|
||||
case <-ctx.Done():
|
||||
@@ -72,7 +61,17 @@ func TestHealthStates(t *testing.T) {
|
||||
// send an event and expect to get expectedErr
|
||||
// if expectedErr is nil, shouldn't get any error
|
||||
logAndExpect := func(msg eventtypes.Action, expectedErr error) {
|
||||
daemon.LogContainerEvent(c, msg)
|
||||
ctr := &container.Container{
|
||||
ID: "id",
|
||||
Name: "name",
|
||||
Config: &containertypes.Config{
|
||||
Image: "image_name",
|
||||
Labels: map[string]string{
|
||||
"com.docker.swarm.task.id": "id",
|
||||
},
|
||||
},
|
||||
}
|
||||
daemon.LogContainerEvent(ctr, msg)
|
||||
|
||||
timer := time.NewTimer(1 * time.Second)
|
||||
defer timer.Stop()
|
||||
|
||||
@@ -24,7 +24,9 @@ func (daemon *Daemon) LogContainerEvent(container *container.Container, action e
|
||||
|
||||
// LogContainerEventWithAttributes generates an event related to a container with specific given attributes.
|
||||
func (daemon *Daemon) LogContainerEventWithAttributes(container *container.Container, action events.Action, attributes map[string]string) {
|
||||
copyAttributes(attributes, container.Config.Labels)
|
||||
if container.Config.Labels != nil {
|
||||
maps.Copy(attributes, container.Config.Labels)
|
||||
}
|
||||
if container.Config.Image != "" {
|
||||
attributes["image"] = container.Config.Image
|
||||
}
|
||||
@@ -90,14 +92,6 @@ func (daemon *Daemon) UnsubscribeFromEvents(listener chan any) {
|
||||
daemon.EventsService.Evict(listener)
|
||||
}
|
||||
|
||||
// copyAttributes guarantees that labels are not mutated by event triggers.
|
||||
func copyAttributes(attributes, labels map[string]string) {
|
||||
if labels == nil {
|
||||
return
|
||||
}
|
||||
maps.Copy(attributes, labels)
|
||||
}
|
||||
|
||||
// ProcessClusterNotifications gets changes from store and add them to event list
|
||||
func (daemon *Daemon) ProcessClusterNotifications(ctx context.Context, watchStream chan *swarmapi.WatchMessage) {
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user