Skip to content

Commit 36f60ea

Browse files
committed
fix: correctly parse tags out of images
Use the last `:` in the image reference. Handle the case when no version was discovered. See siderolabs/theila#138 Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com> (cherry picked from commit 0cb84e8)
1 parent 05b4007 commit 36f60ea

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/cluster/kubernetes/detect.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func DetectLowestVersion(ctx context.Context, cluster UpgradeProvider, options U
4646
continue
4747
}
4848

49-
parts := strings.Split(container.Image, ":")
50-
if len(parts) == 1 {
49+
idx := strings.LastIndex(container.Image, ":")
50+
if idx == -1 {
5151
continue
5252
}
5353

54-
v, err := semver.NewVersion(strings.TrimLeft(parts[1], "v"))
54+
v, err := semver.NewVersion(strings.TrimLeft(container.Image[idx+1:], "v"))
5555
if err != nil {
5656
options.Log("failed to parse %s container version %s", app, err)
5757

@@ -64,5 +64,9 @@ func DetectLowestVersion(ctx context.Context, cluster UpgradeProvider, options U
6464
}
6565
}
6666

67+
if version == nil {
68+
return "", fmt.Errorf("failed to detect lowest Kubernetes version")
69+
}
70+
6771
return version.String(), nil
6872
}

0 commit comments

Comments
 (0)