Skip to content

Commit cf7f597

Browse files
committed
fix: fix automtion to track get most recent dated tag
1 parent 378790c commit cf7f597

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

hack/update/debian_version/debian_version.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"fmt"
21+
"regexp"
2122
"strings"
2223

2324
"k8s.io/klog/v2"
@@ -40,13 +41,36 @@ type Data struct {
4041
LatestVersion string
4142
}
4243

44+
// bookwormDateTag matches Debian bookworm slim tags that include an 8-digit
45+
// date stamp (for example, bookworm-20250929-slim).
46+
var bookwormDateTag = regexp.MustCompile(`^bookworm-\d{8}-slim$`)
47+
48+
// latestBookwormSlimTag returns the newest bookworm slim tag that includes a
49+
// date suffix. The updater now requires a dated tag to be present so that the
50+
// resulting image digest remains stable and predictable between runs.
4351
func latestBookwormSlimTag(tags []string) (string, error) {
52+
var newestDateTag string
4453
for _, tag := range tags {
45-
if strings.Contains(tag, "bookworm-slim") {
46-
return tag, nil
54+
// Skip anything that isn't a bookworm slim tag to avoid matching other
55+
// Debian variants.
56+
if !strings.HasPrefix(tag, "bookworm-") || !strings.HasSuffix(tag, "-slim") {
57+
continue
58+
}
59+
60+
// Track the lexicographically greatest dated tag, which corresponds to
61+
// the most recent date stamp provided by Debian.
62+
if bookwormDateTag.MatchString(tag) {
63+
if newestDateTag == "" || tag > newestDateTag {
64+
newestDateTag = tag
65+
}
4766
}
4867
}
49-
return "", fmt.Errorf("no tag found that matches: bookworm-slim")
68+
69+
// Prefer a dated tag when available.
70+
if newestDateTag != "" {
71+
return newestDateTag, nil
72+
}
73+
return "", fmt.Errorf("no dated tag found that matches: %s", bookwormDateTag.String())
5074
}
5175

5276
func main() {

0 commit comments

Comments
 (0)