diff --git a/scrapers/kubernetes/kubernetes.go b/scrapers/kubernetes/kubernetes.go index 4106131c3..5d506bb57 100644 --- a/scrapers/kubernetes/kubernetes.go +++ b/scrapers/kubernetes/kubernetes.go @@ -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" @@ -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