From 74ac515b9f197fe87b2a52fa674df2ed347bf75c Mon Sep 17 00:00:00 2001 From: chenk Date: Wed, 13 Sep 2023 13:20:01 +0300 Subject: [PATCH 1/4] fix: resolve image id Signed-off-by: chenk --- pkg/k8s/k8s.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 0de3354..dcbda71 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -420,11 +420,15 @@ func (c *cluster) collectComponents(ctx context.Context, labels map[string]strin for _, pod := range pods.Items { containers := make([]bom.Container, 0) for _, s := range pod.Status.ContainerStatuses { - imageRef, err := containerimage.ParseReference(s.ImageID) + imageName, err := containerimage.ParseReference(s.Image) if err != nil { return nil, err } - imageName, err := containerimage.ParseReference(s.Image) + imageID := s.ImageID + if len(imageID) == 0 { + imageID = getImageIDFromImage(s.Image) + } + imageRef, err := containerimage.ParseReference(imageID) if err != nil { return nil, err } @@ -723,3 +727,11 @@ func trimString(version string, trimValues []string) string { } return strings.TrimSpace(version) } + +func getImageIDFromImage(image string) string { + imageParts := strings.Split(image, "@") + if len(imageParts) > 1 && strings.HasPrefix(imageParts[1], "sha256") { + return imageParts[1] + } + return "" +} From 01952bbfc3694f09502c58315a0069e00545d1b0 Mon Sep 17 00:00:00 2001 From: chenk Date: Wed, 13 Sep 2023 13:31:41 +0300 Subject: [PATCH 2/4] fix: resolve image id Signed-off-by: chenk --- pkg/k8s/k8s.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index dcbda71..fd55f36 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -424,9 +424,9 @@ func (c *cluster) collectComponents(ctx context.Context, labels map[string]strin if err != nil { return nil, err } - imageID := s.ImageID + imageID := getImageIDFromImage(s.Image, s.ImageID) if len(imageID) == 0 { - imageID = getImageIDFromImage(s.Image) + continue } imageRef, err := containerimage.ParseReference(imageID) if err != nil { @@ -728,7 +728,10 @@ func trimString(version string, trimValues []string) string { return strings.TrimSpace(version) } -func getImageIDFromImage(image string) string { +func getImageIDFromImage(imageID string, image string) string { + if len(imageID) > 0 { + return imageID + } imageParts := strings.Split(image, "@") if len(imageParts) > 1 && strings.HasPrefix(imageParts[1], "sha256") { return imageParts[1] From 048d8a6f9fd76ab9564ccb0403ef2e2d420ae363 Mon Sep 17 00:00:00 2001 From: chenk Date: Wed, 13 Sep 2023 13:48:08 +0300 Subject: [PATCH 3/4] fix: resolve image id Signed-off-by: chenk --- pkg/k8s/k8s.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index fd55f36..9513a06 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -424,7 +424,7 @@ func (c *cluster) collectComponents(ctx context.Context, labels map[string]strin if err != nil { return nil, err } - imageID := getImageIDFromImage(s.Image, s.ImageID) + imageID := getImageID(s.Image, s.ImageID) if len(imageID) == 0 { continue } @@ -728,7 +728,7 @@ func trimString(version string, trimValues []string) string { return strings.TrimSpace(version) } -func getImageIDFromImage(imageID string, image string) string { +func getImageID(imageID string, image string) string { if len(imageID) > 0 { return imageID } From dc9b93c9a78c6e3838b49685ce90823f4ec5bf3e Mon Sep 17 00:00:00 2001 From: chenk Date: Wed, 13 Sep 2023 14:05:23 +0300 Subject: [PATCH 4/4] fix: resolve image id Signed-off-by: chenk --- pkg/k8s/k8s.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 9513a06..a7a83b7 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -312,7 +312,7 @@ func (c *cluster) CreateClusterBom(ctx context.Context) (*bom.Result, error) { // collect addons info var components []bom.Component labels := map[string]string{ - k8sComponentNamespace: "component", + "": "component", } if c.isOpenShift() { labels = map[string]string{