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:
parent
920f271b41
commit
0f0832d30f
5 changed files with 48 additions and 2 deletions
|
|
@ -82,6 +82,7 @@ func main() {
|
||||||
HostnameOverride: cfg.HostnameOverride,
|
HostnameOverride: cfg.HostnameOverride,
|
||||||
AgentID: cfg.AgentID, // Shared ID? Or separate? Usually separate for now.
|
AgentID: cfg.AgentID, // Shared ID? Or separate? Usually separate for now.
|
||||||
AgentType: "unified",
|
AgentType: "unified",
|
||||||
|
AgentVersion: Version, // Pass unified agent version
|
||||||
Tags: cfg.Tags,
|
Tags: cfg.Tags,
|
||||||
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
||||||
LogLevel: cfg.LogLevel,
|
LogLevel: cfg.LogLevel,
|
||||||
|
|
@ -111,6 +112,7 @@ func main() {
|
||||||
HostnameOverride: cfg.HostnameOverride,
|
HostnameOverride: cfg.HostnameOverride,
|
||||||
AgentID: cfg.AgentID,
|
AgentID: cfg.AgentID,
|
||||||
AgentType: "unified",
|
AgentType: "unified",
|
||||||
|
AgentVersion: Version, // Pass unified agent version
|
||||||
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
InsecureSkipVerify: cfg.InsecureSkipVerify,
|
||||||
DisableAutoUpdate: true, // Unified agent handles updates
|
DisableAutoUpdate: true, // Unified agent handles updates
|
||||||
LogLevel: cfg.LogLevel,
|
LogLevel: cfg.LogLevel,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ type Config struct {
|
||||||
HostnameOverride string
|
HostnameOverride string
|
||||||
AgentID string
|
AgentID string
|
||||||
AgentType string // "unified" when running as part of pulse-agent, empty for standalone
|
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
|
InsecureSkipVerify bool
|
||||||
DisableAutoUpdate bool
|
DisableAutoUpdate bool
|
||||||
Targets []TargetConfig
|
Targets []TargetConfig
|
||||||
|
|
@ -88,6 +89,7 @@ type Agent struct {
|
||||||
daemonHost string
|
daemonHost string
|
||||||
runtime RuntimeKind
|
runtime RuntimeKind
|
||||||
runtimeVer string
|
runtimeVer string
|
||||||
|
agentVersion string
|
||||||
supportsSwarm bool
|
supportsSwarm bool
|
||||||
httpClients map[bool]*http.Client
|
httpClients map[bool]*http.Client
|
||||||
logger zerolog.Logger
|
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{
|
agent := &Agent{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
docker: dockerClient,
|
docker: dockerClient,
|
||||||
daemonHost: dockerClient.DaemonHost(),
|
daemonHost: dockerClient.DaemonHost(),
|
||||||
runtime: runtimeKind,
|
runtime: runtimeKind,
|
||||||
runtimeVer: info.ServerVersion,
|
runtimeVer: info.ServerVersion,
|
||||||
|
agentVersion: agentVersion,
|
||||||
supportsSwarm: runtimeKind == RuntimeDocker,
|
supportsSwarm: runtimeKind == RuntimeDocker,
|
||||||
httpClients: httpClients,
|
httpClients: httpClients,
|
||||||
logger: *logger,
|
logger: *logger,
|
||||||
|
|
@ -656,7 +665,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) {
|
||||||
report := agentsdocker.Report{
|
report := agentsdocker.Report{
|
||||||
Agent: agentsdocker.AgentInfo{
|
Agent: agentsdocker.AgentInfo{
|
||||||
ID: agentID,
|
ID: agentID,
|
||||||
Version: Version,
|
Version: a.agentVersion,
|
||||||
Type: a.cfg.AgentType,
|
Type: a.cfg.AgentType,
|
||||||
IntervalSeconds: int(a.cfg.Interval / time.Second),
|
IntervalSeconds: int(a.cfg.Interval / time.Second),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ type Config struct {
|
||||||
HostnameOverride string
|
HostnameOverride string
|
||||||
AgentID string
|
AgentID string
|
||||||
AgentType string // "unified" when running as part of pulse-agent, empty for standalone
|
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
|
Tags []string
|
||||||
InsecureSkipVerify bool
|
InsecureSkipVerify bool
|
||||||
RunOnce bool
|
RunOnce bool
|
||||||
|
|
@ -51,6 +52,7 @@ type Agent struct {
|
||||||
architecture string
|
architecture string
|
||||||
machineID string
|
machineID string
|
||||||
agentID string
|
agentID string
|
||||||
|
agentVersion string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
trimmedPulseURL string
|
trimmedPulseURL string
|
||||||
}
|
}
|
||||||
|
|
@ -156,6 +158,12 @@ func New(cfg Config) (*Agent, error) {
|
||||||
}
|
}
|
||||||
cfg.Tags = trimmedTags
|
cfg.Tags = trimmedTags
|
||||||
|
|
||||||
|
// Use configured version or fall back to package version
|
||||||
|
agentVersion := cfg.AgentVersion
|
||||||
|
if agentVersion == "" {
|
||||||
|
agentVersion = Version
|
||||||
|
}
|
||||||
|
|
||||||
return &Agent{
|
return &Agent{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
@ -170,6 +178,7 @@ func New(cfg Config) (*Agent, error) {
|
||||||
architecture: arch,
|
architecture: arch,
|
||||||
machineID: machineID,
|
machineID: machineID,
|
||||||
agentID: agentID,
|
agentID: agentID,
|
||||||
|
agentVersion: agentVersion,
|
||||||
interval: cfg.Interval,
|
interval: cfg.Interval,
|
||||||
trimmedPulseURL: pulseURL,
|
trimmedPulseURL: pulseURL,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -241,7 +250,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {
|
||||||
report := agentshost.Report{
|
report := agentshost.Report{
|
||||||
Agent: agentshost.AgentInfo{
|
Agent: agentshost.AgentInfo{
|
||||||
ID: a.agentID,
|
ID: a.agentID,
|
||||||
Version: Version,
|
Version: a.agentVersion,
|
||||||
Type: a.cfg.AgentType,
|
Type: a.cfg.AgentType,
|
||||||
IntervalSeconds: int(a.interval / time.Second),
|
IntervalSeconds: int(a.interval / time.Second),
|
||||||
Hostname: a.hostname,
|
Hostname: a.hostname,
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,26 @@ try {
|
||||||
Exit 1
|
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 ---
|
# --- Service Installation ---
|
||||||
Write-Host "Configuring Windows Service..." -ForegroundColor Cyan
|
Write-Host "Configuring Windows Service..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,12 @@ if [[ "$OS" == "darwin" ]]; then
|
||||||
rm -f /Library/LaunchDaemons/com.pulse.host-agent.plist
|
rm -f /Library/LaunchDaemons/com.pulse.host-agent.plist
|
||||||
rm -f /usr/local/bin/pulse-host-agent
|
rm -f /usr/local/bin/pulse-host-agent
|
||||||
fi
|
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
|
fi
|
||||||
|
|
||||||
# --- Service Installation ---
|
# --- Service Installation ---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue