fix: propagate unified agent version and improve legacy cleanup

Issues found during scenario testing:

1. Version propagation: The hostagent and dockeragent packages were
   reporting their own Version (0.1.0-dev) instead of the unified
   agent's version. Added AgentVersion config field to pass the
   parent's version down.

2. macOS legacy cleanup: The install.sh script was missing cleanup
   for pulse-docker-agent on macOS.

3. Windows legacy cleanup: The install.ps1 script was missing cleanup
   for legacy PulseHostAgent and PulseDockerAgent services.

These fixes ensure:
- Unified agent reports consistent version across host/docker metrics
- Legacy agents are properly removed on all platforms during upgrade
- Users migrating from legacy agents get a clean transition
This commit is contained in:
rcourtman
2025-11-25 23:39:10 +00:00
parent ea335546fc
commit ae3b78d661
5 changed files with 48 additions and 2 deletions

View File

@@ -82,6 +82,7 @@ func main() {
HostnameOverride: cfg.HostnameOverride,
AgentID: cfg.AgentID, // Shared ID? Or separate? Usually separate for now.
AgentType: "unified",
AgentVersion: Version, // Pass unified agent version
Tags: cfg.Tags,
InsecureSkipVerify: cfg.InsecureSkipVerify,
LogLevel: cfg.LogLevel,
@@ -111,6 +112,7 @@ func main() {
HostnameOverride: cfg.HostnameOverride,
AgentID: cfg.AgentID,
AgentType: "unified",
AgentVersion: Version, // Pass unified agent version
InsecureSkipVerify: cfg.InsecureSkipVerify,
DisableAutoUpdate: true, // Unified agent handles updates
LogLevel: cfg.LogLevel,

View File

@@ -48,6 +48,7 @@ type Config struct {
HostnameOverride string
AgentID string
AgentType string // "unified" when running as part of pulse-agent, empty for standalone
AgentVersion string // Version to report; if empty, uses dockeragent.Version
InsecureSkipVerify bool
DisableAutoUpdate bool
Targets []TargetConfig
@@ -88,6 +89,7 @@ type Agent struct {
daemonHost string
runtime RuntimeKind
runtimeVer string
agentVersion string
supportsSwarm bool
httpClients map[bool]*http.Client
logger zerolog.Logger
@@ -226,12 +228,19 @@ func New(cfg Config) (*Agent, error) {
}
}
// Use configured version or fall back to package version
agentVersion := cfg.AgentVersion
if agentVersion == "" {
agentVersion = Version
}
agent := &Agent{
cfg: cfg,
docker: dockerClient,
daemonHost: dockerClient.DaemonHost(),
runtime: runtimeKind,
runtimeVer: info.ServerVersion,
agentVersion: agentVersion,
supportsSwarm: runtimeKind == RuntimeDocker,
httpClients: httpClients,
logger: *logger,
@@ -656,7 +665,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) {
report := agentsdocker.Report{
Agent: agentsdocker.AgentInfo{
ID: agentID,
Version: Version,
Version: a.agentVersion,
Type: a.cfg.AgentType,
IntervalSeconds: int(a.cfg.Interval / time.Second),
},

View File

@@ -28,6 +28,7 @@ type Config struct {
HostnameOverride string
AgentID string
AgentType string // "unified" when running as part of pulse-agent, empty for standalone
AgentVersion string // Version to report; if empty, uses hostagent.Version
Tags []string
InsecureSkipVerify bool
RunOnce bool
@@ -51,6 +52,7 @@ type Agent struct {
architecture string
machineID string
agentID string
agentVersion string
interval time.Duration
trimmedPulseURL string
}
@@ -156,6 +158,12 @@ func New(cfg Config) (*Agent, error) {
}
cfg.Tags = trimmedTags
// Use configured version or fall back to package version
agentVersion := cfg.AgentVersion
if agentVersion == "" {
agentVersion = Version
}
return &Agent{
cfg: cfg,
logger: logger,
@@ -170,6 +178,7 @@ func New(cfg Config) (*Agent, error) {
architecture: arch,
machineID: machineID,
agentID: agentID,
agentVersion: agentVersion,
interval: cfg.Interval,
trimmedPulseURL: pulseURL,
}, nil
@@ -241,7 +250,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {
report := agentshost.Report{
Agent: agentshost.AgentInfo{
ID: a.agentID,
Version: Version,
Version: a.agentVersion,
Type: a.cfg.AgentType,
IntervalSeconds: int(a.interval / time.Second),
Hostname: a.hostname,

View File

@@ -70,6 +70,26 @@ try {
Exit 1
}
# --- Legacy Cleanup ---
# Remove old agents if they exist to prevent conflicts
Write-Host "Checking for legacy agents..." -ForegroundColor Cyan
if (Get-Service "PulseHostAgent" -ErrorAction SilentlyContinue) {
Write-Host "Removing legacy PulseHostAgent..." -ForegroundColor Yellow
Stop-Service "PulseHostAgent" -Force -ErrorAction SilentlyContinue
sc.exe delete "PulseHostAgent" | Out-Null
Remove-Item "C:\Program Files\Pulse\pulse-host-agent.exe" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
}
if (Get-Service "PulseDockerAgent" -ErrorAction SilentlyContinue) {
Write-Host "Removing legacy PulseDockerAgent..." -ForegroundColor Yellow
Stop-Service "PulseDockerAgent" -Force -ErrorAction SilentlyContinue
sc.exe delete "PulseDockerAgent" | Out-Null
Remove-Item "C:\Program Files\Pulse\pulse-docker-agent.exe" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
}
# --- Service Installation ---
Write-Host "Configuring Windows Service..." -ForegroundColor Cyan

View File

@@ -166,6 +166,12 @@ if [[ "$OS" == "darwin" ]]; then
rm -f /Library/LaunchDaemons/com.pulse.host-agent.plist
rm -f /usr/local/bin/pulse-host-agent
fi
if launchctl list | grep -q "com.pulse.docker-agent"; then
log_warn "Removing legacy com.pulse.docker-agent..."
launchctl unload /Library/LaunchDaemons/com.pulse.docker-agent.plist 2>/dev/null || true
rm -f /Library/LaunchDaemons/com.pulse.docker-agent.plist
rm -f /usr/local/bin/pulse-docker-agent
fi
fi
# --- Service Installation ---