func()

in operatortrace-go/pkg/handlers/owns.go [191:254]


func (e *enqueueRequestForOwner[object]) getOwnerReconcileRequest(obj metav1.Object, result map[requestWithTraceID]empty, eventKind string) {
	// Iterate through the OwnerReferences looking for a match on Group and Kind against what was requested
	// by the user
	for _, ref := range e.getOwnersReferences(obj) {
		// Parse the Group out of the OwnerReference to compare it to what was parsed out of the requested OwnerType
		refGV, err := schema.ParseGroupVersion(ref.APIVersion)
		if err != nil {
			// log.Error(err, "Could not parse OwnerReference APIVersion",
			// 	"api version", ref.APIVersion)
			return
		}

		runtimeObj, _ := obj.(runtime.Object)
		gvk, err := apiutil.GVKForObject(runtimeObj, e.scheme)
		kind := ""
		if err != nil {
			// log.Error(err, "Could not retrieve GVK for object", "object", obj)
			return
		} else {
			kind = gvk.GroupKind().Kind
		}

		// Compare the OwnerReference Group and Kind against the OwnerType Group and Kind specified by the user.
		// If the two match, create a Request for the objected referred to by
		// the OwnerReference.  Use the Name from the OwnerReference and the Namespace from the
		// object in the event.
		if ref.Kind == e.groupKind.Kind && refGV.Group == e.groupKind.Group {
			// Match found - add a Request for the object referred to in the OwnerReference
			request := requestWithTraceID{
				NamespacedName: reconcile.Request{
					NamespacedName: types.NamespacedName{
						Name: ref.Name,
					},
				},
			}

			// if owner is not namespaced then we should not set the namespace
			mapping, err := e.mapper.RESTMapping(e.groupKind, refGV.Version)
			if err != nil {
				// log.Error(err, "Could not retrieve rest mapping", "kind", e.groupKind)
				return
			}
			if mapping.Scope.Name() != meta.RESTScopeNameRoot {
				request.NamespacedName.Namespace = obj.GetNamespace()
			}

			traceId := obj.GetAnnotations()[constants.TraceIDAnnotation]
			spanId := obj.GetAnnotations()[constants.SpanIDAnnotation]
			senderName := obj.GetName()
			senderKind := kind

			if traceId != "" && spanId != "" {
				request.TraceID = traceId
				request.SpanID = spanId
			}

			request.EventKind = eventKind
			request.SenderName = senderName
			request.SenderKind = senderKind

			result[request] = empty{}
		}
	}
}