Fix standalone docker agent version comparison prefix mismatch

The unified agent got the version normalization fix (1b866598), but the
standalone docker agent's checkForUpdates() still used direct string
comparison. When server returns "4.34.0" and agent has "v4.34.0", this
caused an infinite self-update loop.

Apply the same normalizeVersion() function used in the unified agent.

Related to #773
This commit is contained in:
rcourtman 2025-11-29 00:04:43 +00:00
parent 6852004ffb
commit c3a5aacd21

View file

@ -1615,8 +1615,10 @@ func (a *Agent) checkForUpdates(ctx context.Context) {
return
}
// Compare versions
if versionResp.Version == Version {
// Compare versions - normalize by stripping "v" prefix for comparison.
// Server returns version without prefix (e.g., "4.33.1"), but agent's
// Version may include it (e.g., "v4.33.1") depending on build.
if normalizeVersion(versionResp.Version) == normalizeVersion(Version) {
a.logger.Debug().Str("version", Version).Msg("Agent is up to date")
return
}
@ -1882,3 +1884,8 @@ func (a *Agent) selfUpdate(ctx context.Context) error {
return nil
}
// normalizeVersion strips the "v" prefix from version strings for comparison.
func normalizeVersion(version string) string {
return strings.TrimPrefix(strings.TrimSpace(version), "v")
}