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

Logstash pipelines #6480

Merged
merged 164 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
99d86cf
Initial Commit of ECK for Logstash
robbavey Feb 10, 2023
11f0f79
Comment out certs for HTTPS for now
robbavey Feb 10, 2023
7414098
Fix up linter issus
robbavey Feb 10, 2023
2304fa3
Generate API docs
robbavey Feb 10, 2023
9459a70
First set of unit tests
robbavey Feb 13, 2023
285c7bf
Fix goimports
robbavey Feb 13, 2023
d6e7ef2
Add version check
robbavey Feb 13, 2023
8016b7b
Add e2e tests
robbavey Feb 14, 2023
6eabf4c
Temporarily take out probes
robbavey Feb 14, 2023
d4908b7
Revert "Temporarily take out probes"
robbavey Feb 15, 2023
b5c775e
Revert "Add e2e tests"
robbavey Feb 15, 2023
33371ad
Fix linter
robbavey Feb 15, 2023
8e6e707
Add logstash config details
robbavey Feb 15, 2023
4afe0de
Fix up typos
robbavey Feb 15, 2023
5f9040f
Revert "Revert "Add e2e tests""
robbavey Feb 15, 2023
803b9ab
Revert "Revert "Temporarily take out probes""
robbavey Feb 15, 2023
0d79bc9
Tidying up
robbavey Feb 16, 2023
4e73a41
Add Logstash to sample and stack tests
robbavey Feb 16, 2023
5713bb4
Added basic logstash verification
robbavey Feb 16, 2023
e66b380
Fix readiness probe
robbavey Feb 16, 2023
9fb1e20
Tidy up
robbavey Feb 16, 2023
34c2aca
add stack monitoring
kaisecheng Feb 16, 2023
131f17c
update test
kaisecheng Feb 21, 2023
b553970
fix sidecar ES ref namespace
kaisecheng Feb 21, 2023
d9f8f90
allow podTemplate update
kaisecheng Feb 21, 2023
f31ba83
fix stack monitoring e2e
kaisecheng Feb 21, 2023
7ff0f46
doc and lint
kaisecheng Feb 22, 2023
9cf60b1
lint
kaisecheng Feb 22, 2023
d7a587e
fix doc gen
kaisecheng Feb 22, 2023
0b41a42
bring back lint
kaisecheng Feb 22, 2023
d96098f
add sample resources for stack monitoring
kaisecheng Feb 23, 2023
8eb21a2
add unit test
kaisecheng Feb 23, 2023
a524216
remove useless NamespacedName as metrics API does not take username a…
kaisecheng Feb 23, 2023
86df8fd
remove useless NamespacedName method
kaisecheng Feb 27, 2023
ce56d6a
Initial Commit of ECK for Logstash
robbavey Feb 10, 2023
02a5451
Comment out certs for HTTPS for now
robbavey Feb 10, 2023
b72182f
Fix up linter issus
robbavey Feb 10, 2023
9cf0a45
Generate API docs
robbavey Feb 10, 2023
4d62ab5
First set of unit tests
robbavey Feb 13, 2023
cf1379c
Fix goimports
robbavey Feb 13, 2023
e5a4621
Add version check
robbavey Feb 13, 2023
a74da1d
Add e2e tests
robbavey Feb 14, 2023
d3878a5
Temporarily take out probes
robbavey Feb 14, 2023
cd7f8f6
Revert "Temporarily take out probes"
robbavey Feb 15, 2023
793ff28
Revert "Add e2e tests"
robbavey Feb 15, 2023
1a83870
Fix linter
robbavey Feb 15, 2023
d3edd1e
Add logstash config details
robbavey Feb 15, 2023
4e4303d
Fix up typos
robbavey Feb 15, 2023
50e834e
Revert "Revert "Add e2e tests""
robbavey Feb 15, 2023
2692661
Revert "Revert "Temporarily take out probes""
robbavey Feb 15, 2023
865d06a
Tidying up
robbavey Feb 16, 2023
84dd489
Add Logstash to sample and stack tests
robbavey Feb 16, 2023
12430d9
Added basic logstash verification
robbavey Feb 16, 2023
d2ac277
Fix readiness probe
robbavey Feb 16, 2023
214f63d
Tidy up
robbavey Feb 16, 2023
b9cb06a
Update config/crds/v1/patches/kustomization.yaml
kaisecheng Feb 22, 2023
51f2bad
Update pkg/apis/logstash/v1alpha1/name.go
kaisecheng Feb 22, 2023
b52d9ee
change HTTPConfig to []LogstashService
kaisecheng Feb 23, 2023
94b84b5
webhook check all rules
kaisecheng Feb 23, 2023
1cfb725
remove building config from existing config in Secret
kaisecheng Feb 23, 2023
bb79c17
rename k8sutils EmitErrorEvent() to MaybeEmitErrorEvent()
kaisecheng Feb 23, 2023
8ec1501
remove nil error in StatefulSet
kaisecheng Feb 23, 2023
aec57e4
remove APIError struct in test
kaisecheng Feb 23, 2023
b27445c
add license header
kaisecheng Feb 23, 2023
746a307
lint
kaisecheng Feb 24, 2023
822f0ab
reconcileConfig return error
kaisecheng Feb 24, 2023
0a37afe
change the default Service to headless service
kaisecheng Feb 24, 2023
df96068
fix service test
kaisecheng Feb 24, 2023
4c414bd
fix podTemplate and doc generation
kaisecheng Feb 27, 2023
018dfbc
Fix Service tests
robbavey Feb 27, 2023
de1fb22
Update comments to reflect change from HTTPConfig to LogstashService
robbavey Feb 27, 2023
41612f7
Update pkg/controller/logstash/service.go
robbavey Feb 27, 2023
a0d176a
remove duplicate err check
kaisecheng Feb 28, 2023
b9610da
Add support for overriding "default" service
robbavey Feb 28, 2023
0c9409a
Replace 'default' service name with 'api'
robbavey Feb 28, 2023
6167cb7
merge from feature/logstash
robbavey Feb 28, 2023
30aa37b
remove irrelevant es ref
kaisecheng Mar 1, 2023
d4c5e05
Add tests and checks for services and endpoints
robbavey Mar 2, 2023
044b2c9
add issues to track log monitoring
kaisecheng Mar 2, 2023
7e38109
add env LOG_STYLE for log monitoring
kaisecheng Mar 2, 2023
1f77430
Update pkg/apis/logstash/v1alpha1/webhook.go
robbavey Mar 2, 2023
b677c65
Update pkg/controller/logstash/service.go
robbavey Mar 2, 2023
a797940
Addressing code review comments
robbavey Mar 2, 2023
315a803
add pipeline config and unit test
kaisecheng Feb 28, 2023
9f6ccf1
add pipeline to sample
kaisecheng Mar 3, 2023
db5dd82
lint and doc
kaisecheng Mar 3, 2023
e94b7f3
add e2e test
kaisecheng Mar 3, 2023
e0699c5
Merge remote-tracking branch 'upstream/feature/logstash' into logstas…
kaisecheng Mar 7, 2023
149a9b7
lint, doc, generate
kaisecheng Mar 7, 2023
b98a36c
update example
kaisecheng Mar 7, 2023
85decbb
add webhook
kaisecheng Mar 7, 2023
ee630d2
add todo
kaisecheng Mar 7, 2023
e1a413c
Merge remote-tracking branch 'upstream/feature/logstash' into logstas…
kaisecheng Mar 7, 2023
6fc77c0
lint, doc and generate
kaisecheng Mar 7, 2023
6badd2e
add pipelines and pipelinesRef validation
kaisecheng Mar 7, 2023
3d2f47b
rename and comment pipelines config
kaisecheng Mar 7, 2023
53aa657
Update pkg/controller/logstash/stackmon/sidecar.go
kaisecheng Mar 8, 2023
3f76e57
Update pkg/apis/logstash/v1alpha1/logstash_types.go
kaisecheng Mar 8, 2023
18609b5
Update pkg/controller/logstash/stackmon/sidecar.go
kaisecheng Mar 8, 2023
9ceef2b
ship deprecation log with filebeat
kaisecheng Mar 8, 2023
ef6437f
add comments
kaisecheng Mar 8, 2023
9c9c12e
use static log4j2.properties
kaisecheng Mar 8, 2023
e4e5d84
rename receiver
kaisecheng Mar 8, 2023
fab33db
remove duplicate container name
kaisecheng Mar 8, 2023
60736da
set minimum es version for test
kaisecheng Mar 8, 2023
0fb3299
add doc for log4j2 requirement
kaisecheng Mar 8, 2023
29c66ff
Revert "set minimum es version for test"
kaisecheng Mar 8, 2023
461fbf7
reuse ParseConfigRef
kaisecheng Mar 8, 2023
16092ca
lint
kaisecheng Mar 8, 2023
b5943a4
set minimum es version for test
kaisecheng Mar 9, 2023
48915cf
- refactor version validation
kaisecheng Mar 9, 2023
7c57920
change Pipelines to []commonv1.Config
kaisecheng Mar 14, 2023
092508e
remove pipelinesref watch
kaisecheng Mar 15, 2023
9c8c999
Update test/e2e/logstash/stack_monitoring_test.go
kaisecheng Mar 20, 2023
76d8756
Update test/e2e/test/logstash/builder.go
kaisecheng Mar 20, 2023
809b32a
Update test/e2e/test/logstash/builder.go
kaisecheng Mar 20, 2023
da2f36e
fix comment
kaisecheng Mar 20, 2023
94e7c75
fix lint and import
kaisecheng Mar 20, 2023
218a1e9
refactor CheckBeatSidecars
kaisecheng Mar 20, 2023
21e3c5b
fix lint
kaisecheng Mar 20, 2023
53ed2df
Update pkg/controller/logstash/driver.go
kaisecheng Mar 21, 2023
ea84d94
Update pkg/apis/logstash/v1alpha1/validations.go
kaisecheng Mar 21, 2023
14563e1
Revert "refactor CheckBeatSidecars"
kaisecheng Mar 21, 2023
62463ac
rename CheckBeatSidecars to CheckBeatSidecarsInElasticsearch
kaisecheng Mar 21, 2023
85bc3e2
lint
kaisecheng Mar 21, 2023
44c9afa
add monitoring status check
kaisecheng Mar 21, 2023
c9d059b
lint
kaisecheng Mar 21, 2023
0cd242e
rename configRef to pipelinesRef
kaisecheng Mar 22, 2023
f7ea881
fix metrics check in test
kaisecheng Mar 22, 2023
4c15694
Merge remote-tracking branch 'origin/logstash_stack_monitoring' into …
kaisecheng Mar 22, 2023
80ad3e1
generate crd
kaisecheng Mar 22, 2023
569b319
rename configRef to pipelinesRef
kaisecheng Mar 22, 2023
4d7855d
Merge branch 'feature/logstash' into logstash_pipelines
kaisecheng Mar 22, 2023
7057ed3
fix generate
kaisecheng Mar 22, 2023
e2a4831
Update pkg/controller/logstash/pipeline_test.go
kaisecheng Mar 23, 2023
2b8056c
Update pkg/controller/logstash/pipeline_test.go
kaisecheng Mar 23, 2023
eba35e8
Update pkg/controller/logstash/pipeline_test.go
kaisecheng Mar 23, 2023
677be46
Update pkg/controller/logstash/pipeline_test.go
kaisecheng Mar 23, 2023
0a57f07
fix rename
kaisecheng Mar 23, 2023
9a4af9b
change metric check to eventually
kaisecheng Mar 30, 2023
f012dcb
fix pipeline id in test
kaisecheng Mar 30, 2023
8943822
Update pkg/controller/logstash/pipelines_config.go
kaisecheng Apr 4, 2023
980a505
Update pkg/controller/logstash/pipelines_config.go
kaisecheng Apr 4, 2023
124d774
Update pkg/controller/logstash/pipeline.go
kaisecheng Apr 4, 2023
9089f79
Update pkg/controller/logstash/pipeline.go
kaisecheng Apr 4, 2023
8cdb763
Update test/e2e/test/logstash/builder.go
kaisecheng Apr 4, 2023
6ceda8c
move test func to test class
kaisecheng Apr 4, 2023
9922520
Update pkg/apis/logstash/v1alpha1/logstash_types.go
kaisecheng Apr 4, 2023
7a0072d
Update test/e2e/logstash/pipeline_test.go
kaisecheng Apr 4, 2023
4a47fb4
Update test/e2e/logstash/pipeline_test.go
kaisecheng Apr 4, 2023
754a74e
update metrics api checking
kaisecheng Apr 4, 2023
d8cf066
fix naming pipelines.yml
kaisecheng Apr 4, 2023
a976bda
delete pipeline secret at the end of test
kaisecheng Apr 4, 2023
b6b4ad0
fix naming pipelines.yml
kaisecheng Apr 4, 2023
eebc8a6
move pipelines_*.go to pipelines package
kaisecheng Apr 4, 2023
8d52421
rename & comment
kaisecheng Apr 5, 2023
991e636
lint
kaisecheng Apr 5, 2023
7bb3f5d
Update pkg/controller/logstash/pipelines/config.go
kaisecheng Apr 6, 2023
7e816da
Update pkg/controller/logstash/pipelines/config.go
kaisecheng Apr 6, 2023
791e02d
Update pkg/controller/logstash/pipelines/config.go
kaisecheng Apr 6, 2023
9967ca4
Update pkg/controller/logstash/pipelines/config.go
kaisecheng Apr 6, 2023
203a3b4
Update test/e2e/logstash/pipeline_test.go
kaisecheng Apr 6, 2023
f756314
Update test/e2e/logstash/pipeline_test.go
kaisecheng Apr 6, 2023
3cc5964
import grouping
kaisecheng Apr 6, 2023
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
17 changes: 17 additions & 0 deletions config/crds/v1/all-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9223,6 +9223,23 @@ spec:
type: array
type: object
type: object
pipelines:
description: Pipelines holds the Logstash Pipelines. At most one of
[`Pipelines`, `PipelinesRef`] can be specified.
items:
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
pipelinesRef:
description: PipelinesRef contains a reference to an existing Kubernetes
Secret holding the Logstash Pipelines. Logstash pipelines must be
specified as yaml, under a single "pipelines.yml" entry. At most
one of [`Pipelines`, `PipelinesRef`] can be specified.
properties:
secretName:
description: SecretName is the name of the secret.
type: string
type: object
podTemplate:
description: PodTemplate provides customisation options for the Logstash
pods.
Expand Down
17 changes: 17 additions & 0 deletions config/crds/v1/bases/logstash.k8s.elastic.co_logstashes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ spec:
type: array
type: object
type: object
pipelines:
description: Pipelines holds the Logstash Pipelines. At most one of
[`Pipelines`, `PipelinesRef`] can be specified.
items:
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
pipelinesRef:
description: PipelinesRef contains a reference to an existing Kubernetes
Secret holding the Logstash Pipelines. Logstash pipelines must be
specified as yaml, under a single "pipelines.yml" entry. At most
one of [`Pipelines`, `PipelinesRef`] can be specified.
properties:
secretName:
description: SecretName is the name of the secret.
type: string
type: object
podTemplate:
description: PodTemplate provides customisation options for the Logstash
pods.
Expand Down
3 changes: 3 additions & 0 deletions config/samples/logstash/logstash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ spec:
log.level: info
api.http.host: "0.0.0.0"
queue.type: memory
pipelines:
- pipeline.id: main
config.string: input { exec { command => 'uptime' interval => 10 } } output { stdout{} }
podTemplate:
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ webhooks:
- logstashes
sideEffects: None
- admissionReviewVersions:
- v1alpha1
- v1
- v1beta1
clientConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9277,6 +9277,23 @@ spec:
type: array
type: object
type: object
pipelines:
description: Pipelines holds the Logstash Pipelines. At most one of
[`Pipelines`, `PipelinesRef`] can be specified.
items:
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
pipelinesRef:
description: PipelinesRef contains a reference to an existing Kubernetes
Secret holding the Logstash Pipelines. Logstash pipelines must be
specified as yaml, under a single "pipelines.yml" entry. At most
one of [`Pipelines`, `PipelinesRef`] can be specified.
properties:
secretName:
description: SecretName is the name of the secret.
type: string
type: object
podTemplate:
description: PodTemplate provides customisation options for the Logstash
pods.
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/api-docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,8 @@ LogstashSpec defines the desired state of Logstash
| *`image`* __string__ | Image is the Logstash Docker image to deploy. Version and Type have to match the Logstash in the image.
| *`config`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$]__ | Config holds the Logstash configuration. At most one of [`Config`, `ConfigRef`] can be specified.
| *`configRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | ConfigRef contains a reference to an existing Kubernetes Secret holding the Logstash configuration. Logstash settings must be specified as yaml, under a single "logstash.yml" entry. At most one of [`Config`, `ConfigRef`] can be specified.
| *`pipelines`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-config[$$Config$$] array__ | Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified.
| *`pipelinesRef`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-configsource[$$ConfigSource$$]__ | PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines. Logstash pipelines must be specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`] can be specified.
| *`services`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-logstash-v1alpha1-logstashservice[$$LogstashService$$] array__ | Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to be opened up for other services: beats, TCP, UDP, etc, inputs
| *`monitoring`* __xref:{anchor_prefix}-github-com-elastic-cloud-on-k8s-v2-pkg-apis-common-v1-monitoring[$$Monitoring$$]__ | Monitoring enables you to collect and ship log and monitoring data of this Logstash. Metricbeat and Filebeat are deployed in the same Pod as sidecars and each one sends data to one or two different Elasticsearch monitoring clusters running in the same Kubernetes cluster.
| *`podTemplate`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podtemplatespec-v1-core[$$PodTemplateSpec$$]__ | PodTemplate provides customisation options for the Logstash pods.
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/logstash/v1alpha1/logstash_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ type LogstashSpec struct {
// +kubebuilder:validation:Optional
ConfigRef *commonv1.ConfigSource `json:"configRef,omitempty"`

// Pipelines holds the Logstash Pipelines. At most one of [`Pipelines`, `PipelinesRef`] can be specified.
barkbay marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:validation:Optional
// +kubebuilder:pruning:PreserveUnknownFields
Pipelines []commonv1.Config `json:"pipelines,omitempty"`

// PipelinesRef contains a reference to an existing Kubernetes Secret holding the Logstash Pipelines.
// Logstash pipelines must be specified as yaml, under a single "pipelines.yml" entry. At most one of [`Pipelines`, `PipelinesRef`]
// can be specified.
// +kubebuilder:validation:Optional
PipelinesRef *commonv1.ConfigSource `json:"pipelinesRef,omitempty"`

// Services contains details of services that Logstash should expose - similar to the HTTP layer configuration for the
// rest of the stack, but also applicable for more use cases than the metrics API, as logstash may need to
// be opened up for other services: beats, TCP, UDP, etc, inputs
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/logstash/v1alpha1/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const (
apiServiceSuffix = "api"
configSuffix = "config"
pipelineSuffix = "pipeline"
)

// Namer is a Namer that is configured with the defaults for resources related to a Logstash resource.
Expand All @@ -34,3 +35,7 @@ func APIServiceName(name string) string {
func UserServiceName(deployName string, name string) string {
return Namer.Suffix(deployName, name)
}

func PipelineSecretName(name string) string {
return Namer.Suffix(name, pipelineSuffix)
}
13 changes: 13 additions & 0 deletions pkg/apis/logstash/v1alpha1/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
checkSingleConfigSource,
checkMonitoring,
checkAssociations,
checkSinglePipelineSource,
}

updateChecks = []func(old, curr *Logstash) field.ErrorList{
Expand Down Expand Up @@ -73,3 +74,15 @@ func checkAssociations(l *Logstash) field.ErrorList {
err2 := commonv1.CheckAssociationRefs(monitoringPath.Child("logs"), l.GetMonitoringLogsRefs()...)
return append(err1, err2...)
}

func checkSinglePipelineSource(a *Logstash) field.ErrorList {
if a.Spec.Pipelines != nil && a.Spec.PipelinesRef != nil {
msg := "Specify at most one of [`pipelines`, `pipelinesRef`], not both"
return field.ErrorList{
field.Forbidden(field.NewPath("spec").Child("pipelines"), msg),
field.Forbidden(field.NewPath("spec").Child("pipelinesRef"), msg),
}
}

return nil
}
51 changes: 51 additions & 0 deletions pkg/apis/logstash/v1alpha1/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,57 @@ func Test_checkSingleConfigSource(t *testing.T) {
}
}

func Test_checkSinglePipelineSource(t *testing.T) {
tests := []struct {
name string
logstash Logstash
wantErr bool
}{
{
name: "pipelinesRef absent, pipelines present",
logstash: Logstash{
Spec: LogstashSpec{
Pipelines: []commonv1.Config{},
},
},
wantErr: false,
},
{
name: "pipelines absent, pipelinesRef present",
logstash: Logstash{
Spec: LogstashSpec{
PipelinesRef: &commonv1.ConfigSource{},
},
},
wantErr: false,
},
{
name: "neither present",
logstash: Logstash{
Spec: LogstashSpec{},
},
wantErr: false,
},
{
name: "both present",
logstash: Logstash{
Spec: LogstashSpec{
Pipelines: []commonv1.Config{},
PipelinesRef: &commonv1.ConfigSource{},
},
},
wantErr: true,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := checkSinglePipelineSource(&tc.logstash)
assert.Equal(t, tc.wantErr, len(got) > 0)
})
}
}

func Test_checkSupportedVersion(t *testing.T) {
for _, tt := range []struct {
name string
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/logstash/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions pkg/controller/common/configref.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"context"
"fmt"

"github.com/elastic/go-ucfg"
uyaml "github.com/elastic/go-ucfg/yaml"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -34,6 +37,23 @@ func ParseConfigRef(
configRef *commonv1.ConfigSource,
secretKey string, // retrieve config data from that entry in the secret
) (*settings.CanonicalConfig, error) {
parsed, err := ParseConfigRefToConfig(driver, resource, configRef, secretKey, ConfigRefWatchName, settings.Options)
if err != nil {
return nil, err
}
return (*settings.CanonicalConfig)(parsed), nil
}

// ParseConfigRefToConfig retrieves the content of a secret referenced in `configRef`, sets up dynamic watches for that secret,
// and parses the secret content into ucfg.Config.
func ParseConfigRefToConfig(
driver driver.Interface,
resource runtime.Object, // eg. Beat, EnterpriseSearch
configRef *commonv1.ConfigSource,
secretKey string, // retrieve config data from that entry in the secret
configRefWatchName func(types.NamespacedName) string,
configOptions []ucfg.Option,
) (*ucfg.Config, error) {
resourceMeta, err := meta.Accessor(resource)
if err != nil {
return nil, err
Expand All @@ -46,7 +66,7 @@ func ParseConfigRef(
if configRef != nil && configRef.SecretName != "" {
secretNames = append(secretNames, configRef.SecretName)
}
if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), ConfigRefWatchName(resourceNsn), secretNames); err != nil {
if err := watches.WatchUserProvidedSecrets(resourceNsn, driver.DynamicWatches(), configRefWatchName(resourceNsn), secretNames); err != nil {
return nil, err
}

Expand All @@ -66,7 +86,9 @@ func ParseConfigRef(
driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg)
return nil, errors.New(msg)
}
parsed, err := settings.ParseConfig(data)

parsed, err := uyaml.NewConfig(data, configOptions...)

if err != nil {
msg := fmt.Sprintf("unable to parse %s in configRef secret %s/%s", secretKey, namespace, configRef.SecretName)
driver.Recorder().Event(resource, corev1.EventTypeWarning, events.EventReasonUnexpected, msg)
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/logstash/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log
return results.WithError(err), params.Status
}

if err := reconcilePipeline(params, configHash); err != nil {
return results.WithError(err), params.Status
}

podTemplate := buildPodTemplate(params, configHash)
return reconcileStatefulSet(params, podTemplate)
}
2 changes: 2 additions & 0 deletions pkg/controller/logstash/logstash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"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/common/watches"
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/logstash/pipelines"
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/k8s"
logconf "github.com/elastic/cloud-on-k8s/v2/pkg/utils/log"
)
Expand Down Expand Up @@ -196,5 +197,6 @@ func (r *ReconcileLogstash) validate(ctx context.Context, logstash logstashv1alp
func (r *ReconcileLogstash) onDelete(ctx context.Context, obj types.NamespacedName) error {
r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj))
r.dynamicWatches.Secrets.RemoveHandlerForKey(common.ConfigRefWatchName(obj))
r.dynamicWatches.Secrets.RemoveHandlerForKey(pipelines.RefWatchName(obj))
return reconciler.GarbageCollectSoftOwnedSecrets(ctx, r.Client, obj, logstashv1alpha1.Kind)
}
83 changes: 83 additions & 0 deletions pkg/controller/logstash/pipeline.go
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(&params.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, &params.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, &params.Logstash, params.Logstash.Spec.PipelinesRef, PipelineFileName)
}

var (
defaultPipeline = pipelines.MustFromSpec([]map[string]string{
{
"pipeline.id": "main",
"path.config": "/usr/share/logstash/pipeline",
},
})
)
Loading