Skip to content

Commit e1304af

Browse files
committed
feat: adds support for multiple watches, namespace filters, updated metadata fields, controller log forwarding
1 parent 95550de commit e1304af

40 files changed

+16497
-162
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# benthos-kubernetes-input
2-
a [benthos](https://github.com/Jeffail/benthos) kubernetes input plugin
2+
a [benthos](https://github.com/Jeffail/benthos) kubernetes input plugin that streams resource messages based on one or more configured watches.
33

44
## Installing
55
- with Docker
@@ -15,15 +15,44 @@ Sample benthos stream config:
1515
input:
1616
type: kubernetes
1717
plugin:
18-
group: ""
19-
version: v1
20-
kind: Pod
18+
watches:
19+
# watch pods in all namespaces
20+
- group: ""
21+
version: v1
22+
kind: Pod
23+
# watch custom resources in specified namespaces
24+
- group: example.com
25+
version: v1alpha1
26+
kind: Foo
27+
namespaces: [default, kube-system]
28+
# watch custom resources that match a label selector
29+
- group: example.com
30+
version: v1apha1
31+
kind: Bar
32+
selector:
33+
matchLabels:
34+
color: blue
35+
matchExpressions:
36+
- key: color
37+
operator: NotIn
38+
values: [green, yellow]
2139

2240
output:
2341
stdout: {}
2442
```
2543
Or see [examples](./example)
2644
45+
## Metadata
46+
This input adds the following metadata fields to each message:
47+
```
48+
- deleted (present only if object has been deleted)
49+
- group
50+
- kind
51+
- name
52+
- namespace
53+
- version
54+
```
55+
2756
## License
2857
Licensed under the [MIT License](LICENSE.md)
2958
Copyright (c) 2020 Chris Ludden

example/benthos.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
11
input:
22
type: kubernetes
33
plugin:
4-
group: example.com
5-
version: v1
6-
kind: Foo
4+
watches:
5+
- group: example.com
6+
version: v1
7+
kind: Foo
8+
- group: example.com
9+
version: v1
10+
kind: Bar
711

812
pipeline:
913
processors:
1014
- bloblang: |
1115
object = this
16+
metadata = meta()
1217
action = match {
13-
metadata.exists("deletionTimestamp") && metadata.get("finalizers").or([]).join(",") == "finalizer.foos.example.com" => "deprovision"
18+
meta().exists("deleted") => "deleted"
19+
metadata.exists("deletionTimestamp") && metadata.get("finalizers").or([]).join(",") == "finalizer.%ss.example.com".format(meta("kind").lowercase()) => "deprovision"
1420
metadata.exists("deletionTimestamp") => "deleting"
1521
_ => "provision"
1622
}
1723
24+
- conditional:
25+
condition:
26+
bloblang: action != "deleted"
27+
processors:
28+
- cache:
29+
cache: objects
30+
operator: set
31+
key: ${!meta("kind")}/${!meta("namespace")}/${!meta("name")}
32+
value: ${!json("object").string()}
33+
else_processors:
34+
- branch:
35+
request_map: 'root = ""'
36+
processors:
37+
- cache:
38+
cache: objects
39+
operator: get
40+
key: ${!meta("kind")}/${!meta("namespace")}/${!meta("name")}
41+
result_map: root.object = this
42+
1843
output:
1944
stdout: {}
45+
46+
resources:
47+
caches:
48+
objects:
49+
memory: {}

example/cr.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

example/crd.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

example/crds.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: foos.example.com
6+
spec:
7+
group: example.com
8+
names:
9+
kind: Foo
10+
listKind: FooList
11+
plural: foos
12+
singular: foo
13+
scope: Namespaced
14+
versions:
15+
- name: v1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
21+
properties:
22+
spec:
23+
type: object
24+
properties:
25+
size:
26+
type: number
27+
subresources:
28+
status: {}
29+
additionalPrinterColumns:
30+
- name: Status
31+
type: string
32+
description: resource status
33+
jsonPath: .status.status
34+
- name: Age
35+
type: date
36+
description: resource creation timestamp
37+
format: date-time
38+
jsonPath: .metadata.creationTimestamp
39+
40+
---
41+
apiVersion: apiextensions.k8s.io/v1
42+
kind: CustomResourceDefinition
43+
metadata:
44+
name: bars.example.com
45+
spec:
46+
group: example.com
47+
names:
48+
kind: Bar
49+
listKind: BarList
50+
plural: bars
51+
singular: bar
52+
scope: Namespaced
53+
versions:
54+
- name: v1
55+
served: true
56+
storage: true
57+
schema:
58+
openAPIV3Schema:
59+
type: object
60+
properties:
61+
spec:
62+
type: object
63+
properties:
64+
size:
65+
type: number
66+
subresources:
67+
status: {}
68+
additionalPrinterColumns:
69+
- name: Status
70+
type: string
71+
description: resource status
72+
jsonPath: .status.status
73+
- name: Age
74+
type: date
75+
description: resource creation timestamp
76+
format: date-time
77+
jsonPath: .metadata.creationTimestamp

example/manifest.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
apiVersion: example.com/v1
3+
kind: Foo
4+
metadata:
5+
name: one
6+
labels:
7+
color: green
8+
finalizers:
9+
- finalizer.foos.example.com
10+
spec:
11+
size: 1
12+
13+
---
14+
apiVersion: example.com/v1
15+
kind: Foo
16+
metadata:
17+
name: two
18+
namespace: kube-system
19+
labels:
20+
color: yellow
21+
finalizers:
22+
- finalizer.foos.example.com
23+
spec:
24+
size: 2
25+
26+
---
27+
apiVersion: example.com/v1
28+
kind: Bar
29+
metadata:
30+
name: three
31+
labels:
32+
color: blue
33+
finalizers:
34+
- finalizer.bars.example.com
35+
spec:
36+
size: 3
37+
38+
---
39+
apiVersion: example.com/v1
40+
kind: Bar
41+
metadata:
42+
name: four
43+
namespace: kube-system
44+
labels:
45+
color: purple
46+
finalizers:
47+
- finalizer.bars.example.com
48+
spec:
49+
size: 4

0 commit comments

Comments
 (0)