Skip to content

Commit

Permalink
feat: link ec2 node to ec2 instance
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jan 8, 2024
1 parent fa0dc96 commit 60d76a5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul
Relationship: "EKSClusterNode",
})
}

if computeType, ok := obj.GetLabels()["eks.amazonaws.com/compute-type"]; ok && computeType == "ec2" {
if spec, ok := obj.Object["spec"].(map[string]any); ok {
if providerID, ok := spec["providerID"].(string); ok {
// providerID is expected to be in the format "aws:///eu-west-1a/i-06ec81231075dd597"
splits := strings.Split(providerID, "/")
if len(splits) > 0 && strings.HasPrefix(splits[len(splits)-1], "i-") {
ec2InstanceID := splits[len(splits)-1]
relationships = append(relationships, v1.RelationshipResult{
ConfigExternalID: v1.ExternalID{ExternalID: []string{string(obj.GetUID())}, ConfigType: ConfigTypePrefix + "Node"},
RelatedExternalID: v1.ExternalID{ExternalID: []string{ec2InstanceID}, ConfigType: "AWS::EC2::Instance"},
Relationship: "EC2InstanceNode",
})
}
}
}
}
}

if obj.GetNamespace() != "" {
Expand Down

0 comments on commit 60d76a5

Please sign in to comment.