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

[processor/k8sattributes] Support name:tag@digest image name format #36145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spiffyy99
Copy link
Contributor

@spiffyy99 spiffyy99 commented Nov 2, 2024

Description

Fixed issue with k8sattributesprocessor where digest is not properly separated from tag if both are present. used official docker library to perform parsing.

Link to tracking issue

Fixes #36131

Testing

unit tests
integration/e2e tests

Documentation

N/A. Fields are already described correctly, this is simply fixing parsing logic

Copy link

linux-foundation-easycla bot commented Nov 2, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: spiffyy99 / name: Ryan Min (828a728)

@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Nov 2, 2024
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch 2 times, most recently from 8a9c1bd to 90d3a08 Compare November 2, 2024 03:33
@spiffyy99 spiffyy99 marked this pull request as ready for review November 2, 2024 03:33
@spiffyy99 spiffyy99 requested a review from a team as a code owner November 2, 2024 03:33
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch 3 times, most recently from e699514 to 09323ed Compare November 2, 2024 16:27
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank's for working on this @spiffyy99!

I think the fix is in the right direction but I left some concerns.

@@ -816,7 +818,7 @@ func TestE2E_NamespacedRBACNoPodIP(t *testing.T) {
"k8s.container.name": newExpectedValue(equal, "telemetrygen"),
"container.image.name": newExpectedValue(equal, "ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen"),
"container.image.repo_digests": newExpectedValue(shouldnotexist, ""),
"container.image.tag": newExpectedValue(equal, "latest"),
"container.image.tag": newExpectedValue(shouldnotexist, ""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we honor that implicitly latest version here? Otherwise this might break users that rely on this assumption right now. @TylerHelmuth wdyt?

@@ -504,7 +505,7 @@ func TestE2E_NamespacedRBAC(t *testing.T) {
"k8s.container.name": newExpectedValue(equal, "telemetrygen"),
"container.image.name": newExpectedValue(equal, "ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen"),
"container.image.repo_digests": newExpectedValue(regex, "ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen@sha256:[0-9a-fA-f]{64}"),
"container.image.tag": newExpectedValue(equal, "latest"),
"container.image.tag": newExpectedValue(shouldnotexist, ""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we preserve this? Unless it is a wrong assumption that we want to fix.

FWIWI a container with image: busybox in the spec will produce a running container with
image: docker.io/library/busybox:latest so technically I think that putting latest when the tag is absent in the spec, is correct.

if c.Rules.ContainerImageName {
container.ImageName = name
}
if c.Rules.ContainerImageTag {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

Since we are on it, I also wonder if we should override the ImageTag from the container's status in case it is available.
See https://github.com/kubernetes/api/blob/v0.32.0-alpha.3/core/v1/types.go#L3047-L3055.

container.ImageName = spec.Image[:nameTagSep]
} else {
container.ImageName = spec.Image
name, tag, err := parseNameAndTagFromImage(spec.Image)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reflect this logic in the documentation as well? Something like what was described at #36131 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/k8sattributes k8s Attributes processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[processor/k8sattributes] Support name:tag@digest image name format
3 participants