Skip to content
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

feat: generate config relationships from kubernetes ownerRef #310

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading