Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test]Add e2e testcases, integrates with CI #206

Merged
merged 6 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions controllers/fluentbitconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type FluentBitConfigReconciler struct {
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=fluentbit.fluent.io,resources=fluentbitconfigs,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=fluentbit.fluent.io,resources=inputs;filters;outputs;parsers,verbs=list
//+kubebuilder:rbac:groups=fluentbit.fluent.io,resources=clusterfluentbitconfigs,verbs=get;list;watch;create;update;patch;delete
zhu733756 marked this conversation as resolved.
Show resolved Hide resolved
//+kubebuilder:rbac:groups=fluentbit.fluent.io,resources=clusterinputs;clusterfilters;clusteroutputs;clusterparsers,verbs=list
//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete

// Reconcile is part of the main kubernetes reconciliation loop which aims to
Expand Down Expand Up @@ -158,6 +158,8 @@ func (r *FluentBitConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}); err != nil {
return ctrl.Result{}, err
}

r.Log.Info("Fluent Bit main configuration has updated", "logging-control-plane", ns, "fluentbitconfig", cfg.Name, "secret", sec.Name)
}

return ctrl.Result{}, nil
Expand Down
44 changes: 20 additions & 24 deletions controllers/fluentdconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ type FluentdConfigReconciler struct {
func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("fluendconfig", req.NamespacedName)

// Get Fluentd instances located ns
var fluentdList fluentdv1alpha1.FluentdList

// List all fluentd instances to bind the generated runtime configuration to each fluentd.
if err := r.List(ctx, &fluentdList); err != nil {
if errors.IsNotFound(err) {
r.Log.V(1).Info("can not find fluentd CR definition.")
Expand All @@ -114,35 +113,35 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}

for _, fd := range fluentdList.Items {
// Get the selector contained in this fluentd instance
// Get the config selector in this fluentd instance
fdSelector, err := metav1.LabelSelectorAsSelector(&fd.Spec.FluentdCfgSelector)
if err != nil {
// Patch this fluentd instance if the selectors exsits errors
// Patch this fluentd instance if the selectors exsit errors
if err := r.PatchObjectErrors(ctx, &fd, err.Error()); err != nil {
return ctrl.Result{}, err
}
}

// A secret loader supports method to store the targeted fluentd config to the fd namespace, the the fd instance can share it.
// A secret loader supports LoadSecret method to parse the targeted secret.
sl := plugins.NewSecretLoader(r.Client, fd.Namespace, r.Log)

// pgr acts as a global plugins to store the related plugin resources
// pgr acts as a global resource to store the related plugin resources
pgr := fluentdv1alpha1.NewGlobalPluginResources("main")
zhu733756 marked this conversation as resolved.
Show resolved Hide resolved

// Firstly, we will combine the defined global inputs.
// Each cluster/namespace fluentd config will generate its own filters/outputs plugins with its cfgId/cfgLabel,
// and finally they would combine here together.
// Each cluster/namespace scope fluentd config will generate its own filters/outputs plugins with its cfgId/cfgLabel,
zhu733756 marked this conversation as resolved.
Show resolved Hide resolved
// and finally they would be combined.
pgr.CombineGlobalInputsPlugins(sl, fd.Spec.GlobalInputs)

// globalCfgLabels stores cfgLabels, the same cfg label is not allowed.
globalCfgLabels := make(map[string]bool)

// combine cluster cfgs
// Combine the resources which the cluster cfgs selected into pgr
zhu733756 marked this conversation as resolved.
Show resolved Hide resolved
if err := r.ClusterCfgsForFluentd(ctx, fdSelector, sl, pgr, globalCfgLabels); err != nil {
return ctrl.Result{}, err
}

// combine namespaced cfgs
// Combine the resources which the cfgs selected into pgr
zhu733756 marked this conversation as resolved.
Show resolved Hide resolved
if err := r.CfgsForFluentd(ctx, fdSelector, sl, pgr, globalCfgLabels); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -158,7 +157,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
enableMultiWorkers = true
}

// Create or update the global main app secret of the fluentd instance in its namespace.
// Create or update the secret of the fluentd instance in its namespace.
mainAppCfg, err := pgr.RenderMainConfig(enableMultiWorkers)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -190,7 +189,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}

r.Log.Info("Main configuration has updated", "logging-control-plane", fd.Namespace, "fd", fd.Name, "secret", secName)
r.Log.Info("Fluentd main configuration has updated", "logging-control-plane", fd.Namespace, "fd", fd.Name, "secret", secName)

}

Expand All @@ -211,25 +210,22 @@ func (r *FluentdConfigReconciler) ClusterCfgsForFluentd(
return err
}

allNamespaces := make([]string, 0)

for _, cfg := range clustercfgs.Items {
// If the field watchedNamespaces is empty, all namesapces will be watched.
watchedNamespaces := cfg.GetWatchedNamespaces()

if len(watchedNamespaces) == 0 {
if len(allNamespaces) == 0 {
var namespaceList corev1.NamespaceList
if err := r.List(ctx, &namespaceList); err != nil {
return err
}

for _, item := range namespaceList.Items {
allNamespaces = append(allNamespaces, item.Name)
}
var namespaceList corev1.NamespaceList
if err := r.List(ctx, &namespaceList); err != nil {
return err
}

for _, item := range namespaceList.Items {
watchedNamespaces = append(watchedNamespaces, item.Name)
}

cfg.Spec.WatchedNamespaces = allNamespaces
// Don't patch the CR, or it would requeue.
cfg.Spec.WatchedNamespaces = watchedNamespaces
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to put every namespace into WatchedNamespaces?
No easier way to represent all namespace instead of iterating every namespace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The former codes cache it, I wonder if the namespaces changed, would mix some namespaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss this later, I think there is no need to iterating every ns in case of all namespace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.


// Build the inner router for this cfg.
Expand Down