Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/apis/logging/v1alpha1/loggingplugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type Parameter struct {
// GetValue for a Parameter
func (p Parameter) GetValue(namespace string, client client.Client) (string, string) {
if p.ValueFrom != nil {
value, error := p.ValueFrom.GetValue(namespace, client)
if error != nil {
value, err := p.ValueFrom.GetValue(namespace, client)
if err != nil {
return "", ""
}
return p.Name, value
Expand Down
17 changes: 6 additions & 11 deletions pkg/controller/plugin/plugin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package plugin

import (
"context"

"github.com/banzaicloud/logging-operator/pkg/resources"
"github.com/banzaicloud/logging-operator/pkg/resources/plugins"

loggingv1alpha1 "github.com/banzaicloud/logging-operator/pkg/apis/logging/v1alpha1"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -89,20 +89,15 @@ func (r *ReconcilePlugin) Reconcile(request reconcile.Request) (reconcile.Result
reqLogger.Info("Reconciling Plugin")

// Fetch the Plugin instance
instance := &loggingv1alpha1.Plugin{}
err := r.client.Get(context.TODO(), request.NamespacedName, instance)
instanceList := &loggingv1alpha1.PluginList{}

err := r.client.List(context.TODO(), client.InNamespace(request.Namespace), instanceList)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}

reconcilers := []resources.ComponentReconciler{
plugins.New(r.client, instance),
plugins.New(r.client, instanceList, request.Namespace),
}

for _, rec := range reconcilers {
Expand Down
22 changes: 13 additions & 9 deletions pkg/resources/plugins/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package plugins

import (
"bytes"
"text/template"

"github.com/Masterminds/sprig"
loggingv1alpha1 "github.com/banzaicloud/logging-operator/pkg/apis/logging/v1alpha1"
"github.com/banzaicloud/logging-operator/pkg/resources/templates"
Expand All @@ -26,14 +28,12 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"text/template"
)

func generateFluentdConfig(plugin *loggingv1alpha1.Plugin, client client.Client) (string, string) {
var finalConfig string
// Generate filters
for _, filter := range plugin.Spec.Filter {
logrus.Info("Applying filter")
values, err := GetDefaultValues(filter.Type)
if err != nil {
logrus.Infof("Error in rendering template: %s", err)
Expand Down Expand Up @@ -92,15 +92,19 @@ func renderPlugin(plugin loggingv1alpha1.FPlugin, baseMap map[string]string, nam
}

func (r *Reconciler) appConfigMap() runtime.Object {
name, data := generateFluentdConfig(r.Plugin, r.Client)
if name != "" {
name = name + ".conf"
appConfigData := map[string]string{}
labels := map[string]string{}
for _, plugin := range r.PluginList.Items {
labels = util.MergeLabels(labels, plugin.Labels)
name, data := generateFluentdConfig(&plugin, r.Client)
if name != "" {
name = name + ".conf"
}
appConfigData[name] = data
}

return &corev1.ConfigMap{
ObjectMeta: templates.PluginsObjectMeta(appConfigMapName, util.MergeLabels(r.Plugin.Labels, labelSelector), r.Plugin),
Data: map[string]string{
name: data,
},
ObjectMeta: templates.PluginsObjectMeta(appConfigMapName, util.MergeLabels(map[string]string{}, labelSelector), r.Namespace),
Data: appConfigData,
}
}
7 changes: 4 additions & 3 deletions pkg/resources/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ type Reconciler struct {
}

// New creates a new FPlugin reconciler
func New(client client.Client, plugin *loggingv1alpha1.Plugin) *Reconciler {
func New(client client.Client, pluginList *loggingv1alpha1.PluginList, namespace string) *Reconciler {
return &Reconciler{
PluginReconciler: resources.PluginReconciler{
Client: client,
Plugin: plugin,
Client: client,
Namespace: namespace,
PluginList: pluginList,
},
}
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/resources/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (

// PluginReconciler reconciler struct for plugin
type PluginReconciler struct {
Client client.Client
Plugin *loggingv1alpha1.Plugin
Client client.Client
Namespace string
PluginList *loggingv1alpha1.PluginList
}

// FluentdReconciler reconciler struct for fluentd
Expand All @@ -51,3 +52,6 @@ type Resource func() runtime.Object

// ResourceVariation redeclaration of function with parameter and return type kubernetes Object
type ResourceVariation func(t string) runtime.Object

// ResourceWithLog redeclaration of function with logging parameter and return type kubernetes Object
type ResourceWithLog func(log logr.Logger) runtime.Object
12 changes: 2 additions & 10 deletions pkg/resources/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@ import (
)

// PluginsObjectMeta creates an objectMeta for resource plugin
func PluginsObjectMeta(name string, labels map[string]string, plugin *loggingv1alpha1.Plugin) metav1.ObjectMeta {
func PluginsObjectMeta(name string, labels map[string]string, namespace string) metav1.ObjectMeta {
o := metav1.ObjectMeta{
Name: name,
Namespace: plugin.Namespace,
Namespace: namespace,
Labels: labels,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: plugin.APIVersion,
Kind: plugin.Kind,
Name: plugin.Name,
UID: plugin.UID,
},
},
}
return o
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package util

// MergeLabels merges two map[string]string map
func MergeLabels(l map[string]string, l2 map[string]string) map[string]string {
if len(l) == 0 {
l = map[string]string{}
}
for lKey, lValue := range l2 {
l[lKey] = lValue
}
Expand Down