Skip to content

Commit

Permalink
feat: link pods to services via endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 16, 2024
1 parent f28e542 commit 0af8b7c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
"github.com/flanksource/duty/models"
"github.com/google/uuid"
"github.com/samber/lo"
coreV1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -387,6 +389,27 @@ func ExtractResults(ctx api.ScrapeContext, config v1.Kubernetes, objs []*unstruc
}
}

if obj.GetKind() == "Endpoints" {
var endpoint coreV1.Endpoints
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &endpoint); err != nil {
return results.Errorf(err, "failed to unmarshal endpoint (%s/%s)", obj.GetUID(), obj.GetName())
}

for _, subset := range endpoint.Subsets {
for _, address := range subset.Addresses {
if address.TargetRef != nil {
if address.TargetRef.Kind != "Service" {
relationships = append(relationships, v1.RelationshipResult{
ConfigID: string(address.TargetRef.UID),
RelatedExternalID: v1.ExternalID{ExternalID: []string{getKubernetesAlias("Service", obj.GetNamespace(), obj.GetName())}, ConfigType: ConfigTypePrefix + "Service"},
Relationship: fmt.Sprintf("%sService", address.TargetRef.Kind),
})
}
}
}
}
}

if obj.GetKind() == "Pod" {
spec := obj.Object["spec"].(map[string]interface{})
var nodeName string
Expand Down

0 comments on commit 0af8b7c

Please sign in to comment.