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

Introduce Beat CRD #3041

Merged
merged 82 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
8a72b79
Introduce Beat CRD
May 12, 2020
b8ee209
Exclude BeatList from doc generation
May 12, 2020
c68cfed
Add autodiscovery rbac flag to manager cmd, fix rbac for the operator
May 12, 2020
3f0f842
Change autodiscover RBAC flag from disable... to enable...
May 14, 2020
69184cc
Improve godoc wording
May 14, 2020
b538333
Rename beat_controller.go to controller.go
May 14, 2020
9ae99a4
Fix comment wording
May 14, 2020
98745b4
Fix update path for autodiscover resources
May 14, 2020
b2f898e
Add image validation if Beat type is not well known
May 14, 2020
469f67c
Regenerate CRDs and api docs
May 14, 2020
be128a2
Add metricbeat driver
May 13, 2020
40a35c5
Expand and improve Beat samples
May 20, 2020
4305780
Refactor config and pod vehicle reconcilation
May 20, 2020
d4c538e
Make new linter happy
May 21, 2020
e88b8c1
Add e2e tests, update smoke test
May 23, 2020
20f2af3
Add UTs
May 23, 2020
df0357c
Move writing derefed secret to hash to common
May 23, 2020
566feb8
Split config.go file
May 24, 2020
897bbfb
Set default replica count for unknown beats
May 24, 2020
66e29ae
Fix setting labels on daemonset
May 24, 2020
fcb8002
Fix not returning error when association secret key isn't found
May 24, 2020
b45481f
Add UTs for beat common and config
May 24, 2020
b2760b1
Fix imports
May 24, 2020
b1c2f96
Make config file mount path the same for all Beats
May 24, 2020
fc9c766
Fix some comments
May 24, 2020
f882293
Make path strings const
May 24, 2020
1b22437
Remove pv for now
May 24, 2020
0c6a132
Fix permissions for the operator
May 24, 2020
e10b7e9
Apply suggestions from code review
david-kow May 24, 2020
df85085
Fix builder security context setting
May 25, 2020
984e9db
Fix syntax errors
May 25, 2020
fb9d5c4
Adhere to testing conventions
May 25, 2020
0493d62
Fix redundant syntax
May 25, 2020
eeefc99
Regenerate docs
May 25, 2020
7d49cd3
Remove unnecessary comment from beat sample
May 25, 2020
c79d07a
Move validation to DriverParams
May 25, 2020
3b4a5be
Fix flag name and value
May 25, 2020
e145e10
Move setting default vehicle to driver constructor
May 25, 2020
728c6a5
Remove unused otherbeat type name
May 25, 2020
586fdd9
Expand comments and rename func for modifying pod template
May 25, 2020
9fe7974
Fix e2e permissions
May 25, 2020
c2c37e0
Support Beat Builder in samples test
May 26, 2020
fc852c3
Add SecurityContext to log generating pod
May 31, 2020
593e282
Fix permissions for the operator, create autodiscover role
May 31, 2020
8fc44d9
Fix Metricbeat e2e test
May 31, 2020
30fe136
PR fixes
Jun 1, 2020
85c0b60
Fix autodiscover cluster role name
Jun 1, 2020
a6d5262
Use empty dict instead of null for values
Jun 3, 2020
6644c7a
Clean up comments
Jun 3, 2020
a45e752
Fix Beat sample
Jun 3, 2020
750d84f
Filter events so that controller sees only the ones relevant for Beats
Jun 3, 2020
286f0c0
Remove watching dynamic secrets as there are none atm
Jun 3, 2020
61035a9
Clean up autodiscover ClusterRoleBinding on delete
Jun 3, 2020
8afb965
Rename default Beat Service Account
Jun 3, 2020
8bb0d21
Change min supported Beat version to 7.0.0
Jun 3, 2020
c454f80
move
Jun 4, 2020
4b832cc
refactor
Jun 4, 2020
0efdd62
Merge branch 'master' into beat_crd
Jun 4, 2020
770579a
Post merge fixes
Jun 4, 2020
dcd3dc4
Add/fix comments
Jun 4, 2020
262cadb
Fix removing comments from yamls
Jun 4, 2020
d1dcf39
Revert accidental comment
Jun 4, 2020
90e37a8
Renames and comments around autodiscover
Jun 4, 2020
ea46765
Refactor to avoid passing state around unnecessarily
Jun 4, 2020
4d303fd
Set security context on pod instead of on container
Jun 4, 2020
2911537
Loosen beat psp
Jun 4, 2020
bdb67b4
Fix adding beats to v1beta1 scheme
Jun 4, 2020
ac1ff77
Clean up comments on Beat type
Jun 4, 2020
328a833
Generated files
Jun 4, 2020
9133ecd
Fixes for OpenShift E2E tests
Jun 5, 2020
ae69269
Set template hash label to ClusterRoleBinding
Jun 5, 2020
ad6f674
Rename roles.yaml to beat-roles.yaml, common.go to driver.go
Jun 5, 2020
8941ce8
Conditionally add empty namespace to cached namespaces
Jun 5, 2020
22b940b
Reword comments, logs
Jun 5, 2020
595610a
Fix comments
Jun 5, 2020
ea57b80
Drop 'operator' from autodiscover resource names
Jun 5, 2020
ae1e37e
Move validating Beat spec to a separate func
Jun 5, 2020
84a6345
Tighten beat PSP, fix comments, regenerate
Jun 6, 2020
eca6654
Unit test derefing secret for config hash
Jun 6, 2020
d793e62
Fix beat-roles.yaml file name in Makefile
Jun 6, 2020
0ce0903
Remove some metricsets from default metricbeat cfg
Jun 6, 2020
4a679c7
PR fixes
Jun 8, 2020
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
31 changes: 1 addition & 30 deletions pkg/controller/beat/metricbeat/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
autodiscover:
providers:
- hints:
default_config: null
default_config: {}
enabled: "true"
node: ${NODE_NAME}
type: kubernetes
Expand All @@ -37,36 +37,7 @@ var (
- module: system
period: 1m
metricsets:
- filesystem
- fsstat
processors:
- drop_event:
when:
regexp:
system:
filesystem:
mount_point: ^/(sys|cgroup|proc|dev|etc|host|lib)($|/)
- module: kubernetes
period: 10s
host: ${NODE_NAME}
hosts:
- https://${HOSTNAME}:10250
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl:
verification_mode: none
metricsets:
- node
- system
- pod
- container
- volume
- module: kubernetes
period: 10s
host: ${NODE_NAME}
hosts:
- https://${HOSTNAME}:10249
metricsets:
- proxy
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify why we remove those? Is it moving us away from https://raw.githubusercontent.com/elastic/beats/7.7/deploy/kubernetes/metricbeat-kubernetes.yaml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filebeat doesn't need any API permissions other than autodiscover provides, but Metricbeat does. Removing the modules/metricsets that need those permissions. This will be addressed by implementation of #3190, but not fixing it here to avoid solving the same problem twice. Those modules/metricsets will be brought back in another PR.

processors:
- add_cloud_metadata: {}
`))
Expand Down
23 changes: 19 additions & 4 deletions test/e2e/beat/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"testing"

v1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1"
"github.com/stretchr/testify/require"

commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
Expand All @@ -29,7 +30,10 @@ func TestFilebeatDefaultConfig(t *testing.T) {

fbBuilder := beat.NewBuilder(name, filebeat.Type).
WithElasticsearchRef(esBuilder.Ref()).
WithESValidations(beat.HasEventFromPod(testPodBuilder.Pod.Name))
WithESValidations(
beat.HasEventFromBeat(filebeat.Type),
beat.HasEventFromPod(testPodBuilder.Pod.Name),
beat.HasMessageContaining(testPodBuilder.Logged))

test.Sequence(nil, test.EmptySteps, esBuilder, fbBuilder, testPodBuilder).RunSequential(t)
}
Expand All @@ -44,7 +48,16 @@ func TestMetricbeatDefaultConfig(t *testing.T) {

mbBuilder := beat.NewBuilder(name, metricbeat.Type).
WithElasticsearchRef(esBuilder.Ref()).
WithESValidations(beat.HasEventFromBeat(metricbeat.Type))
WithESValidations(
beat.HasEventFromBeat(metricbeat.Type),
beat.HasEvent("event.dataset:system.cpu"),
beat.HasEvent("event.dataset:system.load"),
beat.HasEvent("event.dataset:system.memory"),
beat.HasEvent("event.dataset:system.network"),
beat.HasEvent("event.dataset:system.process"),
beat.HasEvent("event.dataset:system.process.summary"),
beat.HasEvent("event.dataset:system.fsstat"),
)

test.Sequence(nil, test.EmptySteps, esBuilder, mbBuilder, testPodBuilder).RunSequential(t)
}
Expand All @@ -58,14 +71,16 @@ func TestHeartbeatConfig(t *testing.T) {
hbBuilder := beat.NewBuilder(name, "heartbeat").
WithElasticsearchRef(esBuilder.Ref()).
WithImage("docker.elastic.co/beats/heartbeat:7.7.0").
WithESValidations(beat.HasEventFromBeat("heartbeat"))
WithESValidations(
beat.HasEventFromBeat("heartbeat"),
beat.HasEvent("monitor.status:up"))

yaml := fmt.Sprintf(`
heartbeat.monitors:
- type: tcp
schedule: '@every 5s'
hosts: ["%s.%s.svc:9200"]
`, esBuilder.Elasticsearch.Name, esBuilder.Elasticsearch.Namespace)
`, v1.HTTPService(esBuilder.Elasticsearch.Name), esBuilder.Elasticsearch.Namespace)
hbBuilder = applyConfigYaml(t, hbBuilder, yaml)

test.Sequence(nil, test.EmptySteps, esBuilder, hbBuilder).RunSequential(t)
Expand Down
13 changes: 12 additions & 1 deletion test/e2e/test/beat/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"

beatv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/beat/v1beta1"
commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
Expand All @@ -23,7 +24,15 @@ type Builder struct {
Validations []ValidationFunc
}

func NewBuilderWithoutSuffix(name string, typ beatcommon.Type) Builder {
return newBuilder(name, typ, "")
}

func NewBuilder(name string, typ beatcommon.Type) Builder {
return newBuilder(name, typ, rand.String(4))
}

func newBuilder(name string, typ beatcommon.Type, suffix string) Builder {
meta := metav1.ObjectMeta{
Name: name,
Namespace: test.Ctx().ManagedNamespace(0),
Expand All @@ -38,7 +47,9 @@ func NewBuilder(name string, typ beatcommon.Type) Builder {
Version: test.Ctx().ElasticStackVersion,
},
},
}
}.
WithSuffix(suffix).
WithLabel(run.TestNameLabel, name)
}

type ValidationFunc func(client.Client) error
Expand Down
16 changes: 12 additions & 4 deletions test/e2e/test/beat/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ import (
)

func HasEventFromBeat(name beatcommon.Type) ValidationFunc {
return HasEvent(fmt.Sprintf("/*beat*/_search?q=agent.type:%s", name))
return HasEvent(fmt.Sprintf("agent.type:%s", name))
}

func HasEventFromPod(name string) ValidationFunc {
return HasEvent(fmt.Sprintf("/*beat*/_search?q=kubernetes.pod.name:%s", name))
return HasEvent(fmt.Sprintf("kubernetes.pod.name:%s", name))
}

func HasMessageContaining(message string) ValidationFunc {
return HasEvent(fmt.Sprintf("message:%s", message))
}

func HasEvent(query string) ValidationFunc {
return hasEvent(fmt.Sprintf("/*beat*/_search?q=%s", query))
}

func hasEvent(url string) ValidationFunc {
return func(esClient client.Client) error {
req, err := http.NewRequest(http.MethodGet, query, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
Expand All @@ -45,7 +53,7 @@ func HasEvent(query string) ValidationFunc {
return err
}
if len(results.Hits.Hits) == 0 {
return fmt.Errorf("hit count should be more than 0 for %s", query)
return fmt.Errorf("hit count should be more than 0 for %s", url)
}

return nil
Expand Down
32 changes: 30 additions & 2 deletions test/e2e/test/beat/pod_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"

"github.com/elastic/cloud-on-k8s/pkg/utils/k8s"
"github.com/elastic/cloud-on-k8s/test/e2e/cmd/run"
Expand All @@ -24,16 +25,24 @@ import (

// Builder to create Beats
type PodBuilder struct {
Pod corev1.Pod
Pod corev1.Pod
Logged string
}

func NewPodBuilder(name string) PodBuilder {
return newPodBuilder(name, rand.String(4))
}

func newPodBuilder(name, suffix string) PodBuilder {
meta := metav1.ObjectMeta{
Name: name,
Namespace: test.Ctx().ManagedNamespace(0),
Labels: map[string]string{run.TestNameLabel: name},
}

// inject random string into the logs to allow validating whether they end up in ES easily
loggedString := fmt.Sprintf("_%s_", rand.String(6))

return PodBuilder{
Pod: corev1.Pod{
ObjectMeta: meta,
Expand All @@ -45,14 +54,33 @@ func NewPodBuilder(name string) PodBuilder {
Command: []string{
"bash",
"-c",
"while [ true ]; do echo \"$(date)\"; sleep 5; done",
fmt.Sprintf("while [ true ]; do echo \"$(date) - %s\"; sleep 5; done", loggedString),
},
},
},
SecurityContext: test.DefaultSecurityContext(),
},
},
Logged: loggedString,
}.
WithSuffix(suffix).
WithLabel(run.TestNameLabel, name)
}

func (pb PodBuilder) WithSuffix(suffix string) PodBuilder {
if suffix != "" {
pb.Pod.ObjectMeta.Name = pb.Pod.ObjectMeta.Name + "-" + suffix
}
return pb
}

func (pb PodBuilder) WithLabel(key, value string) PodBuilder {
if pb.Pod.Labels == nil {
pb.Pod.Labels = make(map[string]string)
}
pb.Pod.Labels[key] = value

return pb
}

func (pb PodBuilder) RuntimeObjects() []runtime.Object {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/helper/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (yd *YAMLDecoder) ToBuilders(reader *bufio.Reader, transform BuilderTransfo
b.ApmServer = *decodedObj
builder = transform(b)
case *beatv1beta1.Beat:
b := beat.NewBuilder(decodedObj.Name, beatcommon.Type(decodedObj.Spec.Type))
b := beat.NewBuilderWithoutSuffix(decodedObj.Name, beatcommon.Type(decodedObj.Spec.Type))
b.Beat = *decodedObj
builder = transform(b)
default:
Expand Down