Skip to content

Commit 263c354

Browse files
committed
return a valid image user and image uid
1 parent ecce43e commit 263c354

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cri/v1alpha2/cri_utils.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -892,23 +892,25 @@ func containerNetns(container *mgr.Container) string {
892892

893893
// imageToCriImage converts pouch image API to CRI image API.
894894
func imageToCriImage(image *apitypes.ImageInfo) (*runtime.Image, error) {
895-
uid := &runtime.Int64Value{}
896-
imageUID, username := getUserFromImageUser(image.Config.User)
897-
if imageUID != nil {
898-
uid.Value = *imageUID
895+
if image == nil || image.Config == nil {
896+
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
899897
}
900-
901898
size := uint64(image.Size)
902899
// TODO: improve type ImageInfo to include RepoTags and RepoDigests.
903-
return &runtime.Image{
900+
runtimeImage := &runtime.Image{
904901
Id: image.ID,
905902
RepoTags: image.RepoTags,
906903
RepoDigests: image.RepoDigests,
907904
Size_: size,
908-
Uid: uid,
909-
Username: username,
910905
Volumes: parseVolumesFromPouch(image.Config.Volumes),
911-
}, nil
906+
}
907+
908+
imageUID, username := getUserFromImageUser(image.Config.User)
909+
if imageUID != nil {
910+
runtimeImage.Uid = &runtime.Int64Value{Value: *imageUID}
911+
}
912+
runtimeImage.Username = username
913+
return runtimeImage, nil
912914
}
913915

914916
// ensureSandboxImageExists pulls the image when it's not present.

cri/v1alpha2/cri_utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ func Test_imageToCriImage(t *testing.T) {
11821182
RepoTags: repoDigests,
11831183
RepoDigests: repoDigests,
11841184
Size_: uint64(1024),
1185-
Uid: &runtime.Int64Value{},
1185+
Uid: nil,
11861186
Username: "foo",
11871187
Volumes: runtimeVolumes,
11881188
},

0 commit comments

Comments
 (0)