-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR allows configuration of Logstash pipeline.yml in CRD. pipeline.yml is an array of map of string/interface{} defining multiple pipelines. `.` in between the key is treated as string. Pipelines can be set from either inline in Pipelines or secret referencing in PipelinesRef. e2e test: TestPipelineConfigRefLogstash, TestPipelineConfigLogstash Co-authored-by: Rob Bavey <[email protected]> Co-authored-by: Michael Morello <[email protected]>
- Loading branch information
1 parent
450e61c
commit 7ce5d9a
Showing
26 changed files
with
1,334 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package logstash | ||
|
||
import ( | ||
"hash" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1" | ||
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/labels" | ||
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/reconciler" | ||
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/tracing" | ||
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/pipelines" | ||
) | ||
|
||
func reconcilePipeline(params Params, configHash hash.Hash) error { | ||
defer tracing.Span(¶ms.Context)() | ||
|
||
cfgBytes, err := buildPipeline(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
expected := corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: params.Logstash.Namespace, | ||
Name: logstashv1alpha1.PipelineSecretName(params.Logstash.Name), | ||
Labels: labels.AddCredentialsLabel(NewLabels(params.Logstash)), | ||
}, | ||
Data: map[string][]byte{ | ||
PipelineFileName: cfgBytes, | ||
}, | ||
} | ||
|
||
if _, err = reconciler.ReconcileSecret(params.Context, params.Client, expected, ¶ms.Logstash); err != nil { | ||
return err | ||
} | ||
|
||
_, _ = configHash.Write(cfgBytes) | ||
|
||
return nil | ||
} | ||
|
||
func buildPipeline(params Params) ([]byte, error) { | ||
userProvidedCfg, err := getUserPipeline(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if userProvidedCfg != nil { | ||
return userProvidedCfg.Render() | ||
} | ||
|
||
cfg := defaultPipeline | ||
return cfg.Render() | ||
} | ||
|
||
// getUserPipeline extracts the pipeline either from the spec `pipeline` field or from the Secret referenced by spec | ||
// `pipelineRef` field. | ||
func getUserPipeline(params Params) (*pipelines.Config, error) { | ||
if params.Logstash.Spec.Pipelines != nil { | ||
pipes := make([]map[string]interface{}, 0, len(params.Logstash.Spec.Pipelines)) | ||
for _, p := range params.Logstash.Spec.Pipelines { | ||
pipes = append(pipes, p.Data) | ||
} | ||
|
||
return pipelines.FromSpec(pipes) | ||
} | ||
return pipelines.ParsePipelinesRef(params, ¶ms.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName) | ||
} | ||
|
||
var ( | ||
defaultPipeline = pipelines.MustFromSpec([]map[string]string{ | ||
{ | ||
"pipeline.id": "main", | ||
"path.config": "/usr/share/logstash/pipeline", | ||
}, | ||
}) | ||
) |
Oops, something went wrong.