Skip to content

Commit 039cd52

Browse files
authored
Merge pull request #20 from sarus-suite/fc-improved-robustness-canonicalimagename
Fixed crash when system has missconfigured registries. More robust code now based on Resolve()
2 parents ebd9818 + 880c5d2 commit 039cd52

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

common/imageutil.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,35 @@ import (
55
"strings"
66

77
"github.com/containers/image/v5/pkg/shortnames"
8-
"github.com/containers/image/v5/pkg/sysregistriesv2"
98
"github.com/containers/storage"
109
)
1110

12-
// We get fully qualified name
11+
// We get fully qualified name with more robust Resolve()
1312
func CanonicalImageName(ref string) (string, error) {
1413
parts := strings.Split(ref, ":")
1514
name := parts[0]
1615

17-
// if there is no tag, we default it to latest
16+
// default to "latest"
1817
tag := "latest"
1918
if len(parts) == 2 && parts[1] != "" {
2019
tag = parts[1]
2120
}
2221

2322
if shortnames.IsShortName(ref) {
24-
alias, _, err := sysregistriesv2.ResolveShortNameAlias(nil, name)
23+
resolved, err := shortnames.Resolve(nil, ref)
2524
if err != nil {
26-
return "", err
25+
return "", fmt.Errorf("failed to resolve short name %q: %w", ref, err)
2726
}
28-
name = alias.Name()
27+
if len(resolved.PullCandidates) == 0 {
28+
return "", fmt.Errorf("no resolution candidates found for short name %q", ref)
29+
}
30+
candidate := resolved.PullCandidates[0] // take first candidate
31+
return candidate.Value.String(), nil // Already includes tag
2932
}
3033

3134
return fmt.Sprintf("%s:%s", name, tag), nil
3235
}
3336

34-
3537
func FindImage(store storage.Store, name string) (storage.Image, error){
3638
canonical, err := CanonicalImageName(name)
3739
if err != nil {

0 commit comments

Comments
 (0)