diff --git a/pkg/k8shandler/fluentd.go b/pkg/k8shandler/fluentd.go index 176a3fe43b..61ca06c701 100644 --- a/pkg/k8shandler/fluentd.go +++ b/pkg/k8shandler/fluentd.go @@ -503,7 +503,7 @@ func newFluentdPodSpec(cluster *logging.ClusterLogging, proxyConfig *configv1.Pr // for collection config generation. If first is provided without the latter a // ClusterLogFowarder with default fields is assumed. // (See ClusterLoggingRequest#getLogForwarder) - if pipelineSpec.HasDefaultOutput() && cluster.Spec.LogStore != nil { + if pipelineSpec.HasDefaultOutput() && cluster.Spec.LogStore != nil && cluster.Spec.LogStore.ElasticsearchSpec.NodeCount > 0 { fluentdPodSpec.InitContainers = []v1.Container{ newFluentdInitContainer(cluster), } diff --git a/pkg/k8shandler/fluentd_test.go b/pkg/k8shandler/fluentd_test.go index b9e08c9383..0f5e33bc34 100644 --- a/pkg/k8shandler/fluentd_test.go +++ b/pkg/k8shandler/fluentd_test.go @@ -287,6 +287,9 @@ func TestFluentdPodInitContainerWithDefaultForwarding(t *testing.T) { }, LogStore: &logging.LogStoreSpec{ Type: "elasticsearch", + ElasticsearchSpec: logging.ElasticsearchSpec{ + NodeCount: 1, + }, }, }, } @@ -302,6 +305,32 @@ func TestFluentdPodInitContainerWithDefaultForwarding(t *testing.T) { } } +func TestFluentdPodInitContainerWithZeroESCount(t *testing.T) { + cluster := &logging.ClusterLogging{ + Spec: logging.ClusterLoggingSpec{ + Collection: &logging.CollectionSpec{ + Logs: logging.LogCollectionSpec{ + Type: "fluentd", + FluentdSpec: logging.FluentdSpec{}, + }, + }, + LogStore: &logging.LogStoreSpec{ + Type: "elasticsearch", + }, + }, + } + + spec := logging.ClusterLogForwarderSpec{ + Outputs: []logging.OutputSpec{{Name: "default"}}, + } + + podSpec := newFluentdPodSpec(cluster, nil, nil, spec) + + if len(podSpec.InitContainers) > 0 { + t.Error("Expected pod not define init container") + } +} + func TestFluentdPodNoInitContainerWithOutDefaultForwarding(t *testing.T) { cluster := &logging.ClusterLogging{ Spec: logging.ClusterLoggingSpec{