Skip to content

Commit

Permalink
Add enabled flag
Browse files Browse the repository at this point in the history
  • Loading branch information
skhalash committed Sep 23, 2024
1 parent 7befb12 commit 7595cc8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions apis/telemetry/v1alpha1/logpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type Input struct {

// ApplicationInput specifies the default type of Input that handles application logs from runtime containers. It configures in more detail from which containers logs are selected as input.
type ApplicationInput struct {
// If enabled, application logs are collected. The default is `true`.
// +optional
// +kubebuilder:default=true
Enabled *bool `json:"enabled,omitempty"`
// Describes whether application logs from specific Namespaces are selected. The options are mutually exclusive. System Namespaces are excluded by default from the collection.
Namespaces InputNamespaces `json:"namespaces,omitempty"`
// Describes whether application logs from specific containers are selected. The options are mutually exclusive.
Expand Down
6 changes: 6 additions & 0 deletions internal/reconciler/logpipeline/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ func (r *Reconciler) isReconcilable(ctx context.Context, pipeline *telemetryv1al
return false, nil
}

// Treat the pipeline as non-reconcilable if the application input is explicitly disabled
appInputEnabled := pipeline.Spec.Input.Application.Enabled
if appInputEnabled != nil && !*appInputEnabled {
return false, nil
}

err := r.pipelineValidator.validate(ctx, pipeline)

// Pipeline with a certificate that is about to expire is still considered reconcilable
Expand Down
13 changes: 7 additions & 6 deletions internal/reconciler/logpipeline/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -89,8 +90,8 @@ func TestReconcile(t *testing.T) {
require.True(t, *updatedPipeline.Status.UnsupportedMode)
})

t.Run("should set status UnsupportedMode false if does not contains custom plugin", func(t *testing.T) {
pipeline := testutils.NewLogPipelineBuilder().WithFinalizer("FLUENT_BIT_SECTIONS_CONFIG_MAP").Build()
t.Run("no resources generated if app input disabled", func(t *testing.T) {
pipeline := testutils.NewLogPipelineBuilder().WithApplicationInputDisabled().Build()
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&pipeline).WithStatusSubresource(&pipeline).Build()

proberStub := commonStatusStubs.NewDaemonSetProber(nil)
Expand All @@ -110,10 +111,10 @@ func TestReconcile(t *testing.T) {
_, err := sut.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: pipeline.Name}})
require.NoError(t, err)

var updatedPipeline telemetryv1alpha1.LogPipeline
_ = fakeClient.Get(context.Background(), types.NamespacedName{Name: pipeline.Name}, &updatedPipeline)

require.False(t, *updatedPipeline.Status.UnsupportedMode)
// check Fluent Bit sections configmap as an indicator of resources generation
cm := &corev1.ConfigMap{}
err = fakeClient.Get(context.Background(), testConfig.SectionsConfigMap, cm)
require.True(t, apierrors.IsNotFound(err), "sections configmap should not exist")
})

t.Run("log agent is not ready", func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions internal/testutils/log_pipeline_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (b *LogPipelineBuilder) WithFinalizer(finalizer string) *LogPipelineBuilder
return b
}

func (b *LogPipelineBuilder) WithApplicationInputDisabled() *LogPipelineBuilder {
b.input.Application.Enabled = ptr.To(false)
return b
}

func (b *LogPipelineBuilder) WithIncludeContainers(containers ...string) *LogPipelineBuilder {
b.input.Application.Containers.Include = containers
return b
Expand Down

0 comments on commit 7595cc8

Please sign in to comment.