Skip to content

Commit

Permalink
feat: generate config relationships from kubernetes ownerRef
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 6, 2023
1 parent 446af9a commit ac60cfd
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions db/update.go
Original file line number Diff line number Diff line change
@@ -351,21 +351,21 @@ func relationshipResultHandler(relationships v1.RelationshipResults) error {
for _, relationship := range relationships {
configID, err := FindConfigItemID(relationship.ConfigExternalID)
if err != nil {
logger.Errorf("Error fetching config item id: %v", err)
logger.Errorf("error fetching config item(id=%s): %v", relationship.ConfigExternalID, err)
continue
}
if configID == nil {
logger.Warnf("Failed to find config %s", relationship.ConfigExternalID)
logger.Warnf("failed to find config %s", relationship.ConfigExternalID)
continue
}

relatedID, err := FindConfigItemID(relationship.RelatedExternalID)
if err != nil {
logger.Errorf("Error fetching config item id: %v", err)
logger.Errorf("error fetching external config item(id=%s): %v", relationship.RelatedExternalID, err)
continue
}
if relatedID == nil {
logger.Warnf("Relationship not found %s", relationship.RelatedExternalID)
logger.Warnf("related external config item(id=%s) not found.", relationship.RelatedExternalID)
continue
}

15 changes: 15 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,21 @@ func (kubernetes KubernetesScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResul
}
}

for _, ownerRef := range obj.GetOwnerReferences() {
rel := v1.RelationshipResult{
ConfigExternalID: v1.ExternalID{
ExternalID: []string{string(obj.GetUID())},
ConfigType: ConfigTypePrefix + obj.GetKind(),
},
RelatedExternalID: v1.ExternalID{
ExternalID: []string{string(ownerRef.UID)},
ConfigType: ConfigTypePrefix + ownerRef.Kind,
},
Relationship: ownerRef.Kind + obj.GetKind(),
}
relationships = append(relationships, rel)
}

obj.SetManagedFields(nil)
annotations := obj.GetAnnotations()
if annotations != nil {

0 comments on commit ac60cfd

Please sign in to comment.