Skip to content

Commit 9e78bf3

Browse files
authored
Namespace fix (#87)
* Namespace fix * Configmap generator variable fix
1 parent f0171d7 commit 9e78bf3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

pkg/controller/plugin/plugin_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (r *ReconcilePlugin) Reconcile(request reconcile.Request) (reconcile.Result
9191
// Fetch the Plugin instance
9292
instanceList := &loggingv1alpha1.PluginList{}
9393

94-
err := r.client.List(context.TODO(), client.InNamespace(request.Namespace), instanceList)
94+
err := r.client.List(context.TODO(), client.MatchingLabels(map[string]string{}), instanceList)
9595
if err != nil {
9696
return reconcile.Result{}, err
9797
}

pkg/resources/plugins/configmap.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package plugins
1818

1919
import (
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+
3337
func 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
}

pkg/resources/plugins/init.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ func GetDefaultValues(name string) (map[string]string, error) {
4949
if !ok {
5050
err = fmt.Errorf("plugin %q not found", name)
5151
}
52-
return value.DefaultValues, err
52+
newMap := make(map[string]string)
53+
for k, v := range value.DefaultValues {
54+
newMap[k] = v
55+
}
56+
return newMap, err
5357
}
5458

5559
// GetTemplate get template string by name

0 commit comments

Comments
 (0)