-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[processor/k8sattributes] Support name:tag@digest image name format #36145
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: bug_fix | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: processor/k8sattribute | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: fixes parsing of k8s image names to support images with tags and digests. | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [36131] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | ||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [user] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ package kube // import "github.com/open-telemetry/opentelemetry-collector-contri | |
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
|
|
@@ -632,6 +633,30 @@ func removeUnnecessaryPodData(pod *api_v1.Pod, rules ExtractionRules) *api_v1.Po | |
| return &transformedPod | ||
| } | ||
|
|
||
| // parseNameAndTagFromImage parses the image name and tag for differently-formatted image names. | ||
| // returns "latest" as the default if tag not present. also checks if the image contains a digest. | ||
| // if it does, no latest tag is assumed. | ||
|
TylerHelmuth marked this conversation as resolved.
|
||
| func parseNameAndTagFromImage(image string) (name, tag string, err error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use the already available internal docker.ParseImageName function instead? I would prefer to all components use the same strategy for common functionalities. Note that the shared function cannot parse images with digest at the moment and should be fixed beforehand: #36279
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a single implementation makes sense.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a private implementation I am ok moving forward with this approach for now, but I agree it should used the shared function. Created #36418
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @spiffyy99 I was gonna merge this before the release but now I want to make our test coverage is still handling when no digest is set. If you get to using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, I can update.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, looking at this further, wouldn't it be better to use the official docker api code for things like this? i'm sure this regex is correct as well but I'd think that the official one is a better practice (reference.Parse). another option is we can update i'm not the one maintaining this though, so I don't feel strongly. just pointing it out |
||
| ref, err := reference.Parse(image) | ||
| if err != nil { | ||
| return | ||
| } | ||
| namedRef, ok := ref.(reference.Named) | ||
| if !ok { | ||
| return "", "", errors.New("cannot retrieve image name") | ||
| } | ||
| name = namedRef.Name() | ||
| if taggedRef, ok := namedRef.(reference.Tagged); ok { | ||
| tag = taggedRef.Tag() | ||
| } | ||
| if tag == "" { | ||
| if digestedRef, ok := namedRef.(reference.Digested); !ok || digestedRef.String() == "" { | ||
| tag = "latest" | ||
| } | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContainers { | ||
| containers := PodContainers{ | ||
| ByID: map[string]*Container{}, | ||
|
|
@@ -643,16 +668,14 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain | |
| if c.Rules.ContainerImageName || c.Rules.ContainerImageTag { | ||
| for _, spec := range append(pod.Spec.Containers, pod.Spec.InitContainers...) { | ||
| container := &Container{} | ||
| nameTagSep := strings.LastIndex(spec.Image, ":") | ||
| if c.Rules.ContainerImageName { | ||
| if nameTagSep > 0 { | ||
| container.ImageName = spec.Image[:nameTagSep] | ||
| } else { | ||
| container.ImageName = spec.Image | ||
| name, tag, err := parseNameAndTagFromImage(spec.Image) | ||
|
ChrsMark marked this conversation as resolved.
|
||
| if err == nil { | ||
| if c.Rules.ContainerImageName { | ||
| container.ImageName = name | ||
| } | ||
| if c.Rules.ContainerImageTag { | ||
|
ChrsMark marked this conversation as resolved.
|
||
| container.ImageTag = tag | ||
| } | ||
| } | ||
| if c.Rules.ContainerImageTag && nameTagSep > 0 { | ||
| container.ImageTag = spec.Image[nameTagSep+1:] | ||
| } | ||
| containers.ByName[spec.Name] = container | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.