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
7 changes: 5 additions & 2 deletions internal/command/image/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ func showMachineImage(ctx context.Context, app *fly.AppCompact) error {
}
}

// Exclude machines that are already running the latest version
if machine.ImageRef.Digest == latest.Digest {
// Exclude machines that are already running the latest version, and
// skip cases where the resolver returned an older or non-newer build
// (e.g. a stale pinned minor tag at a lower fly.version than the
// machine's current rolling tag) to avoid suggesting downgrades.
if !IsUpdateCandidate(machine, latest) {
continue
}
updatable = append(updatable, machine)
Expand Down
43 changes: 43 additions & 0 deletions internal/command/image/update_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package image

import (
"strings"

"github.com/hashicorp/go-version"
fly "github.com/superfly/fly-go"
)

// IsUpdateCandidate reports whether latest is a strictly newer build than the
// machine's current image. It guards against a backend resolver bug where
// asking for the latest details of a rolling tag (e.g. "flyio/postgres-flex:16")
// returns an older fly.version than the rolling tag's current one, which would
// otherwise surface as a spurious "update available" — actually a downgrade.
//
// When either fly.version label is missing or unparseable (e.g. custom images),
// falls back to a digest-inequality check so we preserve the prior behavior for
// cases that don't use semver-tagged builds.
func IsUpdateCandidate(machine *fly.Machine, latest *fly.ImageVersion) bool {
if machine == nil || latest == nil {
return false
}
if machine.ImageRef.Digest == latest.Digest {
return false
}

current := strings.TrimPrefix(machine.ImageVersion(), "v")
candidate := strings.TrimPrefix(latest.Version, "v")
if current == "" || candidate == "" {
return true
}

curV, err := version.NewVersion(current)
if err != nil {
return true
}
latV, err := version.NewVersion(candidate)
if err != nil {
return true
}

return latV.GreaterThan(curV)
}
2 changes: 1 addition & 1 deletion internal/command/image/update_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func resolveImage(ctx context.Context, machine fly.Machine) (string, error) {
return "", err
}

if latestImage != nil {
if latestImage != nil && IsUpdateCandidate(&machine, latestImage) {
image = latestImage.FullImageRef()
}

Expand Down
13 changes: 9 additions & 4 deletions internal/command/status/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

fly "github.com/superfly/fly-go"
imagecmd "github.com/superfly/flyctl/internal/command/image"
"github.com/superfly/flyctl/internal/command/postgres"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flapsutil"
Expand Down Expand Up @@ -125,8 +126,10 @@ func RenderMachineStatus(ctx context.Context, app *fly.AppCompact, out io.Writer
latest = latestImage
}

// Exclude machines that are already running the latest version
if machine.ImageRef.Digest == latest.Digest {
// Exclude machines that are already running the latest version, and
// skip cases where the resolver returned an older or non-newer build
// to avoid suggesting downgrades.
if !imagecmd.IsUpdateCandidate(machine, latest) {
continue
}
updatable = append(updatable, machine)
Expand Down Expand Up @@ -319,8 +322,10 @@ func renderPGStatus(ctx context.Context, app *fly.AppCompact, machines []*fly.Ma
return fmt.Errorf("major version mismatch detected")
}

// Exclude machines that are already running the latest version
if machine.ImageRef.Digest == latest.Digest {
// Exclude machines that are already running the latest version, and
// skip cases where the resolver returned an older or non-newer build
// to avoid suggesting downgrades.
if !imagecmd.IsUpdateCandidate(machine, latest) {
continue
}
updatable = append(updatable, machine)
Expand Down