@@ -18,6 +18,8 @@ package plugins
1818
1919import (
2020 "bytes"
21+ "context"
22+ logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
2123 "text/template"
2224
2325 "github.com/Masterminds/sprig"
@@ -30,6 +32,8 @@ import (
3032 "sigs.k8s.io/controller-runtime/pkg/client"
3133)
3234
35+ var log = logf .Log .WithName ("plugins.configmap" )
36+
3337func generateFluentdConfig (plugin * loggingv1alpha1.Plugin , client client.Client ) (string , string ) {
3438 var finalConfig string
3539 // Generate filters
@@ -102,9 +106,28 @@ func (r *Reconciler) appConfigMap() runtime.Object {
102106 }
103107 appConfigData [name ] = data
104108 }
109+ pluginConfigMapNamespace := r .Namespace
110+ cmLog := log .WithValues ("pluginConfigMapNamespace" , pluginConfigMapNamespace )
111+ fluentdList := loggingv1alpha1.FluentdList {}
112+ err := r .Client .List (context .TODO (), client .MatchingLabels (map [string ]string {}), & fluentdList )
113+ if err != nil {
114+ cmLog .Error (err , "Reconciler query failed." )
115+ }
105116
117+ if len (fluentdList .Items ) > 0 {
118+ cmLog = log .WithValues ("pluginConfigMapNamespace" , pluginConfigMapNamespace , "FluentdNamespace" , fluentdList .Items [0 ].Namespace )
119+ cmLog .Info ("Check Fluentd Namespace" )
120+ if pluginConfigMapNamespace != fluentdList .Items [0 ].Namespace {
121+ pluginConfigMapNamespace = fluentdList .Items [0 ].Namespace
122+ cmLog = log .WithValues ("pluginConfigMapNamespace" , pluginConfigMapNamespace )
123+ cmLog .Info ("Plugin ConfigMap Namespace Updated" )
124+
125+ }
126+ } else {
127+ log .Info ("The is no Fluentd resource available" )
128+ }
106129 return & corev1.ConfigMap {
107- ObjectMeta : templates .PluginsObjectMeta (appConfigMapName , util .MergeLabels (map [string ]string {}, labelSelector ), r . Namespace ),
130+ ObjectMeta : templates .PluginsObjectMeta (appConfigMapName , util .MergeLabels (map [string ]string {}, labelSelector ), pluginConfigMapNamespace ),
108131 Data : appConfigData ,
109132 }
110133}
0 commit comments