diff --git a/hack/update/amd_device_gpu_plugin_version/amd_device_gpu_plugin_version.go b/hack/update/amd_device_gpu_plugin_version/amd_device_gpu_plugin_version.go index 6251973396..f5c84ebf0a 100644 --- a/hack/update/amd_device_gpu_plugin_version/amd_device_gpu_plugin_version.go +++ b/hack/update/amd_device_gpu_plugin_version/amd_device_gpu_plugin_version.go @@ -19,6 +19,7 @@ package main import ( "context" "fmt" + "strings" "time" "k8s.io/minikube/hack/update" @@ -39,6 +40,19 @@ type Data struct { SHA string } +// findMatchingImageTag finds the Docker Hub image tag corresponding to a GitHub release tag. +// Docker Hub tags may include a numeric patch suffix not present in the GitHub release tag +// (e.g. GitHub "v1.25.2" may correspond to Docker Hub "v1.25.2.8"). +// Tags should be provided newest-first (Docker Hub API default); the first match is returned. +func findMatchingImageTag(tags []string, ghTag string) (string, error) { + for _, tag := range tags { + if tag == ghTag || strings.HasPrefix(tag, ghTag+".") { + return tag, nil + } + } + return "", fmt.Errorf("no Docker Hub image tag found matching GitHub release tag %s", ghTag) +} + func main() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() @@ -47,12 +61,23 @@ func main() { if err != nil { klog.Fatalf("Unable to get stable version: %v", err) } - sha, err := update.GetImageSHA(fmt.Sprintf("rocm/k8s-device-plugin:%s", stable.Tag)) + + dockerTags, err := update.ImageTagsFromDockerHub("rocm/k8s-device-plugin") + if err != nil { + klog.Fatalf("failed to get Docker Hub tags for rocm/k8s-device-plugin: %v", err) + } + + imageTag, err := findMatchingImageTag(dockerTags, stable.Tag) + if err != nil { + klog.Fatalf("failed to find Docker Hub image tag matching GitHub release tag %s: %v", stable.Tag, err) + } + + sha, err := update.GetImageSHA(fmt.Sprintf("rocm/k8s-device-plugin:%s", imageTag)) if err != nil { klog.Fatalf("failed to get image SHA: %v", err) } - data := Data{Version: stable.Tag, SHA: sha} + data := Data{Version: imageTag, SHA: sha} if err := update.Apply(schema, data); err != nil { klog.Fatalf("unable to apply update: %v", err)