mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Fix image parsing for image referenced as digests (#3196)
* fixes image break with sha256 Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com> * fixes priority to digest Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
943fe2dd41
commit
5a541567de
2 changed files with 11 additions and 12 deletions
|
@ -35,10 +35,10 @@ type ImageInfo struct {
|
|||
|
||||
func (i *ImageInfo) String() string {
|
||||
image := i.Registry + "/" + i.Path + ":" + i.Tag
|
||||
// image that needs only digest and not the tag
|
||||
if i.Digest != "" {
|
||||
image = image + "@" + i.Digest
|
||||
image = i.Registry + "/" + i.Path + "@" + i.Digest
|
||||
}
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ func newImageInfo(image, jsonPointer string) (*ImageInfo, error) {
|
|||
}
|
||||
|
||||
// set default tag - the domain is set via addDefaultDomain before parsing
|
||||
if tag == "" {
|
||||
if digest == "" && tag == "" {
|
||||
tag = "latest"
|
||||
}
|
||||
|
||||
|
|
|
@ -59,15 +59,6 @@ func Test_extractImageInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_ImageInfo_String(t *testing.T) {
|
||||
validateImageInfo(t,
|
||||
"registry.test.io/test/myapp:v1.2-21.g5523e95@sha256:31aaf12480bd08c54e7990c6b0e43d775a7a84603d2921a6de4abbc317b2fd10",
|
||||
"myapp",
|
||||
"test/myapp",
|
||||
"registry.test.io",
|
||||
"v1.2-21.g5523e95",
|
||||
"sha256:31aaf12480bd08c54e7990c6b0e43d775a7a84603d2921a6de4abbc317b2fd10",
|
||||
"registry.test.io/test/myapp:v1.2-21.g5523e95@sha256:31aaf12480bd08c54e7990c6b0e43d775a7a84603d2921a6de4abbc317b2fd10")
|
||||
|
||||
validateImageInfo(t,
|
||||
"nginx",
|
||||
"nginx",
|
||||
|
@ -112,6 +103,14 @@ func Test_ImageInfo_String(t *testing.T) {
|
|||
"latest",
|
||||
"",
|
||||
"localhost:4443/test/nginx:latest")
|
||||
validateImageInfo(t,
|
||||
"docker.io/test/centos@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f",
|
||||
"centos",
|
||||
"test/centos",
|
||||
"docker.io",
|
||||
"",
|
||||
"sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f",
|
||||
"docker.io/test/centos@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f")
|
||||
}
|
||||
|
||||
func validateImageInfo(t *testing.T, raw, name, path, registry, tag, digest, str string) {
|
||||
|
|
Loading…
Add table
Reference in a new issue