Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions availableVersions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"production": "1.6.20",
"test": "1.6.20",
"local": "1.6.20",
"all": "1.6.20"
"production": "1.6.21",
"test": "1.6.21",
"local": "1.6.21",
"all": "1.6.21"
}
35 changes: 18 additions & 17 deletions src/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ func (agent *Agent) OnConnect(reconnect bool) error {
return err
}

// updateRemoteDevice sends the connect's device report. It waits for nothing
// but its own call; the Docker engine is read again in the background after
// it (api.External.SendConnectReport).
func (agent *Agent) updateRemoteDevice() error {
_, err := agent.Messenger.Call(context.Background(), topics.UpdateDeviceArchitecture, []interface{}{agent.External.DeviceReport()}, nil, nil, nil)
return err
return agent.External.SendConnectReport()
}

// ensureAppCABundle refreshes the CA bundle app containers verify TLS against.
Expand Down Expand Up @@ -336,6 +338,11 @@ func NewAgent(generalConfig *config.Config) (agent *Agent) {
if err != nil {
log.Fatal().Stack().Err(err).Msg("failed to setup docker")
}
// The Docker engine's platform and version for the device report, read in
// the background and bounded: an absent or hung daemon holds up nothing,
// and the report then goes without them.
engineReport := api.NewEngineReport(container.EngineInfo)
safe.Go(engineReport.Refresh)

filesystem := filesystem.New()
tunnelManager, err := tunnel.NewFrpTunnelManager(dummyMessenger, generalConfig)
Expand Down Expand Up @@ -423,26 +430,14 @@ func NewAgent(generalConfig *config.Config) (agent *Agent) {
AppImageRegistry: generalConfig.ReswarmConfig.DockerRegistryURL,
// Every image reference the device still needs: present AND newest
// version per stage, so a reclaim that races an in-flight update
// cannot delete the version being pulled or the one still running.
// cannot delete the version being pulled or the one still running,
// and the images of the apps' Compose definitions.
WantedAppImages: func() (map[string]bool, error) {
payloads, err := appStore.GetRequestedStates()
if err != nil {
return nil, err
}
wanted := make(map[string]bool, len(payloads)*4)
for _, p := range payloads {
for _, repo := range []string{p.RegistryImageName.Prod, p.RegistryImageName.Dev} {
if repo == "" {
continue
}
for _, version := range []string{p.PresentVersion, p.NewestVersion, p.Version} {
if version != "" {
wanted[repo+":"+version] = true
}
}
}
}
return wanted, nil
return apps.WantedAppImages(generalConfig.ReswarmConfig, payloads), nil
},
// On recovery, reinstate the apps' requested states (which were
// stopped/blocked during the emergency), and reconcile every app's
Expand Down Expand Up @@ -534,6 +529,7 @@ func NewAgent(generalConfig *config.Config) (agent *Agent) {
}
}

safe.Go(engineReport.Refresh)
// compose support was probed (and latched negative) while the
// daemon was down
container.Compose().RefreshSupport()
Expand Down Expand Up @@ -624,12 +620,15 @@ func NewAgent(generalConfig *config.Config) (agent *Agent) {
// On daemon-availability transitions (event stream lost / daemon back) the
// recovery supervisor pokes an immediate status push so the badge flips
// right away instead of on the next heartbeat.
// A daemon that comes back may be another engine (Docker Desktop
// restarted with another one): read it again.
stateObserver.SetDaemonTransitionFunc(func() {
safe.Go(func() {
if err := mainSession.UpdateRemoteDeviceStatus(messenger.CONNECTED); err != nil {
log.Debug().Err(err).Msg("failed to push device status on a docker daemon transition")
}
})
safe.Go(engineReport.Refresh)
})
privilege := privilege.NewPrivilege(mainSession, generalConfig)

Expand All @@ -647,7 +646,9 @@ func NewAgent(generalConfig *config.Config) (agent *Agent) {
TerminalManager: &terminalManager,
LogManager: &logManager,
Config: generalConfig,
Engine: engineReport,
}
engineReport.SetResend(external.ResendDeviceReport)

agent = &Agent{
Config: generalConfig,
Expand Down
47 changes: 47 additions & 0 deletions src/agent_engine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"context"
"reagent/api"
"reagent/common"
"reagent/container"
"reagent/messenger/topics"
"reagent/safe"
"reagent/testutil/builders"
"reagent/testutil/fakes"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// The connect's report goes out at once while the Docker daemon hangs, without
// the engine's keys.
func TestConnectReportDoesNotWaitForDocker(t *testing.T) {
hung := make(chan struct{})
t.Cleanup(func() { close(hung) })
reading := make(chan struct{}, 1)
engine := api.NewEngineReport(func(ctx context.Context) (container.EngineInfo, error) {
reading <- struct{}{}
<-hung // longer than any timeout
return container.EngineInfo{}, context.DeadlineExceeded
})
safe.Go(engine.Refresh)
<-reading

m := fakes.NewMessenger()
agent := &Agent{Messenger: m, External: &api.External{Config: builders.DefaultTestConfig(), Messenger: m, Engine: engine}}

start := time.Now()
require.NoError(t, agent.updateRemoteDevice())
assert.Less(t, time.Since(start), time.Second)

require.Equal(t, 1, m.GetCallCount())
call := m.GetCallCalls()[0]
assert.Equal(t, topics.UpdateDeviceArchitecture, call.Topic)
report := call.Args[0].(common.Dict)
assert.Contains(t, report, "architecture")
assert.NotContains(t, report, "engine_platform")
assert.NotContains(t, report, "engine_version")
}
Loading
Loading