From a61b5b4dd5a0dbfad4aa5c2bc00ce9470db4a01b Mon Sep 17 00:00:00 2001 From: bcaton Date: Thu, 7 Mar 2024 15:21:11 -0500 Subject: [PATCH] adding check for pods that do not specify a tag --- image/image.go | 10 +++++++++- image/image_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/image/image.go b/image/image.go index 0c45703..43221d9 100644 --- a/image/image.go +++ b/image/image.go @@ -306,10 +306,18 @@ func ParseContainer(pod *v1.Pod, containerName string) (*Image, error) { // Set tag name s := strings.Split(container.Image, ":") - if len(s) != 2 && len(s) != 3 { + if len(s) > 3 { return nil, fmt.Errorf("Wrong image format: %s", container.Image) } + // If the string after the colon contains a / we + // can assume it's the repository and no tag has been + // defined. + if len(s) == 1 || strings.Contains(s[len(s)-1], "/") { + image.Tag = "latest" + return image, nil + } + tagname := s[len(s)-1] if len(tagname) == 0 { return nil, fmt.Errorf("Empty Tag") diff --git a/image/image_test.go b/image/image_test.go index ab724af..05e1215 100644 --- a/image/image_test.go +++ b/image/image_test.go @@ -142,6 +142,42 @@ var containerStatusTable = []struct { expectedError error }{ + { + "my-test-repository", + "QUAY:443/my-test-namespace/my-test-repository", + "docker-pullable://QUAY:443/my-test-namespace/my-test-repository@sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "my-test-repository", + "QUAY:443", + "my-test-namespace", + "my-test-repository", + "sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "latest", + nil, + }, + { + "my-test-repository", + "quay.io/my-test-namespace/my-test-repository", + "docker-pullable://quay.io/my-test-namespace/my-test-repository@sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "my-test-repository", + "quay.io", + "my-test-namespace", + "my-test-repository", + "sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "latest", + nil, + }, + { + "redis", + "redis", + "docker-pullable://redis@sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "redis", + "docker.io", + "library", + "redis", + "sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba", + "latest", + nil, + }, { "my-test-repository", "QUAY:443/my-test-namespace/my-test-repository@sha256:c549c6151dd8f4098fd02198913c0f6c55b240b156475588257f19d57e7b1fba",