-
Notifications
You must be signed in to change notification settings - Fork 485
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
Robust cgroup path parsing of docker container ID #1605
Robust cgroup path parsing of docker container ID #1605
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @azdagron, it looks great!
I have a couple of small suggestions.
// The "finder" found a container ID, but it was blank. This is a | ||
// defensive measure against bad matcher patterns and shouldn't | ||
// be possible with the default finder. | ||
return "", fmt.Errorf("workloadattestor/docker: a pattern matched, but no container id was found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", fmt.Errorf("workloadattestor/docker: a pattern matched, but no container id was found") | |
return "", errors.New("workloadattestor/docker: a pattern matched, but no container id was found") |
|
||
type defaultContainerIDFinder struct{} | ||
|
||
func (f *defaultContainerIDFinder) FindContainerID(cgroupPath string) (string, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a small comment about this function would be good. We can point that dockerCGroupRE
is used here and it would be good to explain the meaning of an empty string result and the boolean returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
- Uses a simple regex to extract the 64 hex character container ID from any cgroup path with a "docker" whole word prefix somewhere before the ID. - Replaces the default finder with the above regex - Still supports the legacy and pattern-based finders Signed-off-by: Andrew Harding <andrew.harding@hpe.com>
2e556c6
to
a185db6
Compare
Fixed a misspelling in a comment to pass the linter and squashed the commits. |
Affected functionality
Changes the default docker container ID parsing behavior. Current default behavior parses cgroup paths that look like
/docker/<containerid>
. This however does not work in general and the existing (undocumented) options are inflexible enough to handle cgroup paths like those generated by RHEL.@vbotez prepared a targeted fix with #1522 (thank you!!). It opened up a discussion of the desired semantics, which ended up being quite the departure for the direction the PR started with. This PR
summarizes the functionality we landed with during that discussion.
Description of change
Which issue this PR fixes
Fixes #1518