Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve image id #221

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 := getImageID(s.Image, s.ImageID)
if len(imageID) == 0 {
continue
}
imageRef, err := containerimage.ParseReference(imageID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -723,3 +727,14 @@ func trimString(version string, trimValues []string) string {
}
return strings.TrimSpace(version)
}

func getImageID(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]
}
return ""
}