Skip to content
Open
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
14 changes: 10 additions & 4 deletions detectors/aws/eks/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
// Compile time assertion that eksDetectorUtils implements the detectorUtils interface.
var _ detectorUtils = (*eksDetectorUtils)(nil)

// is this going to stop working with 1.20 when Docker is deprecated?
var containerIDRegex = regexp.MustCompile(`^.*/docker/(.+)$`)
// Updated regex to support both Docker and Kubernetes/containerd cgroup formats

Check failure on line 58 in detectors/aws/eks/detector.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
Copy link
Member

Choose a reason for hiding this comment

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

Comments shouldn't be about things that have been updated (GIT has history for that), but actual issues.

var containerIDRegex = regexp.MustCompile(`^.*/(docker/|kubepods/.*/pod[a-f0-9-]+/)([a-f0-9]{12,})$`)

// NewResourceDetector returns a resource detector that will detect AWS EKS resources.
func NewResourceDetector() resource.Detector {
Expand Down Expand Up @@ -185,8 +185,14 @@
// Retrieve containerID from file
splitData := strings.Split(strings.TrimSpace(string(fileData)), "\n")
for _, str := range splitData {
if containerIDRegex.MatchString(str) {
return str[len(str)-containerIDLength:], nil
matches := containerIDRegex.FindStringSubmatch(str)
if len(matches) > 2 {
// Extract container ID from the third capture group (index 2)
containerID := matches[2]
// Ensure it's at least 12 characters (minimum container ID length)
if len(containerID) >= 12 {
return containerID, nil
}
}
}
return "", fmt.Errorf("getContainerID() error: cannot read containerID from file %s", defaultCgroupPath)
Expand Down
Loading