@@ -31,6 +31,7 @@ import (
3131 v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3232 "github.com/prometheus/client_golang/prometheus"
3333 corev1 "k8s.io/api/core/v1"
34+ "k8s.io/apimachinery/pkg/runtime/schema"
3435 "k8s.io/apimachinery/pkg/types"
3536 "k8s.io/client-go/tools/record"
3637 ctrl "sigs.k8s.io/controller-runtime"
@@ -542,6 +543,38 @@ func SetupLoggingWithManager(mgr ctrl.Manager, logger logr.Logger) *ctrl.Builder
542543 return nil
543544 }
544545
546+ for _ , ref := range obj .GetOwnerReferences () {
547+ refGV , err := schema .ParseGroupVersion (ref .APIVersion )
548+ if err != nil {
549+ logger .Error (err , "failed to parse group version" , "apiVersion" , ref .APIVersion )
550+ continue
551+ }
552+
553+ const (
554+ FluentbitAgentKind = "FluentbitAgent"
555+ FluentdConfigKind = "FluentdConfig"
556+ SyslogNGConfigKind = "SyslogNGConfig"
557+ )
558+
559+ // Check if this is owned by FluentbitAgent, FluentdConfig, or SyslogNGConfig
560+ // and then map back to the relevant Logging resource
561+ if refGV .Group == loggingv1beta1 .GroupVersion .Group {
562+ switch ref .Kind {
563+ case FluentbitAgentKind :
564+ var agent loggingv1beta1.FluentbitAgent
565+ if err := mgr .GetClient ().Get (ctx , types.NamespacedName {
566+ Name : ref .Name ,
567+ Namespace : obj .GetNamespace (),
568+ }, & agent ); err == nil {
569+ return reconcileRequestsForLoggingRef (loggingList .Items , agent .Spec .LoggingRef )
570+ }
571+
572+ case FluentdConfigKind , SyslogNGConfigKind :
573+ return reconcileRequestsForMatchingControlNamespace (loggingList .Items , obj .GetNamespace ())
574+ }
575+ }
576+ }
577+
545578 switch o := obj .(type ) {
546579 case * loggingv1beta1.ClusterOutput :
547580 return reconcileRequestsForLoggingRef (loggingList .Items , o .Spec .LoggingRef )
0 commit comments