Skip to content

Commit 3db293a

Browse files
committed
feat(tenants): simplify the logrouting api significantly by reducing options to labelselectors only, simplify problem handling with the tenant
Signed-off-by: Peter Wilcsinszky <[email protected]>
1 parent af7cf25 commit 3db293a

File tree

12 files changed

+152
-226
lines changed

12 files changed

+152
-226
lines changed

charts/logging-operator/crds/logging.banzaicloud.io_fluentbitagents.yaml

+18-27
Original file line numberDiff line numberDiff line change
@@ -1345,38 +1345,29 @@ spec:
13451345
type: string
13461346
logRouting:
13471347
properties:
1348-
enabled:
1349-
type: boolean
13501348
targets:
13511349
items:
13521350
properties:
1353-
logging:
1354-
type: string
1355-
targetSelector:
1356-
properties:
1357-
matchExpressions:
1358-
items:
1359-
properties:
1360-
key:
1361-
type: string
1362-
operator:
1363-
type: string
1364-
values:
1365-
items:
1366-
type: string
1367-
type: array
1368-
required:
1369-
- key
1370-
- operator
1371-
type: object
1372-
type: array
1373-
matchLabels:
1374-
additionalProperties:
1351+
matchExpressions:
1352+
items:
1353+
properties:
1354+
key:
13751355
type: string
1376-
type: object
1356+
operator:
1357+
type: string
1358+
values:
1359+
items:
1360+
type: string
1361+
type: array
1362+
required:
1363+
- key
1364+
- operator
1365+
type: object
1366+
type: array
1367+
matchLabels:
1368+
additionalProperties:
1369+
type: string
13771370
type: object
1378-
required:
1379-
- logging
13801371
type: object
13811372
type: array
13821373
type: object

charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml

+18-27
Original file line numberDiff line numberDiff line change
@@ -2334,38 +2334,29 @@ spec:
23342334
type: string
23352335
logRouting:
23362336
properties:
2337-
enabled:
2338-
type: boolean
23392337
targets:
23402338
items:
23412339
properties:
2342-
logging:
2343-
type: string
2344-
targetSelector:
2345-
properties:
2346-
matchExpressions:
2347-
items:
2348-
properties:
2349-
key:
2350-
type: string
2351-
operator:
2352-
type: string
2353-
values:
2354-
items:
2355-
type: string
2356-
type: array
2357-
required:
2358-
- key
2359-
- operator
2360-
type: object
2361-
type: array
2362-
matchLabels:
2363-
additionalProperties:
2340+
matchExpressions:
2341+
items:
2342+
properties:
2343+
key:
23642344
type: string
2365-
type: object
2345+
operator:
2346+
type: string
2347+
values:
2348+
items:
2349+
type: string
2350+
type: array
2351+
required:
2352+
- key
2353+
- operator
2354+
type: object
2355+
type: array
2356+
matchLabels:
2357+
additionalProperties:
2358+
type: string
23662359
type: object
2367-
required:
2368-
- logging
23692360
type: object
23702361
type: array
23712362
type: object

config/crd/bases/logging.banzaicloud.io_fluentbitagents.yaml

+18-27
Original file line numberDiff line numberDiff line change
@@ -1345,38 +1345,29 @@ spec:
13451345
type: string
13461346
logRouting:
13471347
properties:
1348-
enabled:
1349-
type: boolean
13501348
targets:
13511349
items:
13521350
properties:
1353-
logging:
1354-
type: string
1355-
targetSelector:
1356-
properties:
1357-
matchExpressions:
1358-
items:
1359-
properties:
1360-
key:
1361-
type: string
1362-
operator:
1363-
type: string
1364-
values:
1365-
items:
1366-
type: string
1367-
type: array
1368-
required:
1369-
- key
1370-
- operator
1371-
type: object
1372-
type: array
1373-
matchLabels:
1374-
additionalProperties:
1351+
matchExpressions:
1352+
items:
1353+
properties:
1354+
key:
13751355
type: string
1376-
type: object
1356+
operator:
1357+
type: string
1358+
values:
1359+
items:
1360+
type: string
1361+
type: array
1362+
required:
1363+
- key
1364+
- operator
1365+
type: object
1366+
type: array
1367+
matchLabels:
1368+
additionalProperties:
1369+
type: string
13771370
type: object
1378-
required:
1379-
- logging
13801371
type: object
13811372
type: array
13821373
type: object

config/crd/bases/logging.banzaicloud.io_loggings.yaml

+18-27
Original file line numberDiff line numberDiff line change
@@ -2334,38 +2334,29 @@ spec:
23342334
type: string
23352335
logRouting:
23362336
properties:
2337-
enabled:
2338-
type: boolean
23392337
targets:
23402338
items:
23412339
properties:
2342-
logging:
2343-
type: string
2344-
targetSelector:
2345-
properties:
2346-
matchExpressions:
2347-
items:
2348-
properties:
2349-
key:
2350-
type: string
2351-
operator:
2352-
type: string
2353-
values:
2354-
items:
2355-
type: string
2356-
type: array
2357-
required:
2358-
- key
2359-
- operator
2360-
type: object
2361-
type: array
2362-
matchLabels:
2363-
additionalProperties:
2340+
matchExpressions:
2341+
items:
2342+
properties:
2343+
key:
23642344
type: string
2365-
type: object
2345+
operator:
2346+
type: string
2347+
values:
2348+
items:
2349+
type: string
2350+
type: array
2351+
required:
2352+
- key
2353+
- operator
2354+
type: object
2355+
type: array
2356+
matchLabels:
2357+
additionalProperties:
2358+
type: string
23662359
type: object
2367-
required:
2368-
- logging
23692360
type: object
23702361
type: array
23712362
type: object

config/samples/fluentbit-ns-routing/logging/tenant-infra-logging.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ apiVersion: logging.banzaicloud.io/v1beta1
77
kind: Logging
88
metadata:
99
name: infra
10+
labels:
11+
tenant: infra
1012
spec:
1113
loggingRef: infra
1214
fluentd: {}
1315
controlNamespace: infra
14-
watchNamespaces:
15-
- infra
1616
---
1717
apiVersion: logging.banzaicloud.io/v1beta1
1818
kind: Flow
@@ -49,8 +49,6 @@ spec:
4949
logRouting:
5050
enabled: true
5151
targets:
52-
- logging: infra
53-
- loggingSelector:
54-
matchExpressions:
55-
- key: tenant
56-
operator: Exists
52+
- matchExpressions:
53+
- key: tenant
54+
operator: Exists

controllers/logging/tenant_test.go

+33-15
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,32 @@ func TestFindTenants(t *testing.T) {
3333

3434
testData := []struct {
3535
name string
36-
targets []v1beta1.Target
36+
targets []v1.LabelSelector
3737
loggings []*v1beta1.Logging
3838
wantErr bool
3939
satisfy func([]fluentbit.Tenant) bool
4040
}{
4141
{
4242
name: "static logging target with a static watch namespace list",
43-
targets: []v1beta1.Target{
43+
targets: []v1.LabelSelector{
4444
{
45-
LoggingName: "a",
45+
MatchLabels: map[string]string{
46+
"name": "a",
47+
},
4648
},
4749
{
48-
LoggingName: "b",
50+
MatchLabels: map[string]string{
51+
"name": "b",
52+
},
4953
},
5054
},
5155
loggings: []*v1beta1.Logging{
5256
{
5357
ObjectMeta: v1.ObjectMeta{
5458
Name: "a",
59+
Labels: map[string]string{
60+
"name": "a",
61+
},
5562
},
5663
Spec: v1beta1.LoggingSpec{
5764
WatchNamespaces: []string{"asd"},
@@ -60,6 +67,9 @@ func TestFindTenants(t *testing.T) {
6067
{
6168
ObjectMeta: v1.ObjectMeta{
6269
Name: "b",
70+
Labels: map[string]string{
71+
"name": "b",
72+
},
6373
},
6474
Spec: v1beta1.LoggingSpec{
6575
WatchNamespaces: []string{"bsd"},
@@ -78,15 +88,20 @@ func TestFindTenants(t *testing.T) {
7888
},
7989
{
8090
name: "static logging target with an empty watch namespace will be omitted",
81-
targets: []v1beta1.Target{
91+
targets: []v1.LabelSelector{
8292
{
83-
LoggingName: "a",
93+
MatchLabels: map[string]string{
94+
"name": currentLoggingName,
95+
},
8496
},
8597
},
8698
loggings: []*v1beta1.Logging{
8799
{
88100
ObjectMeta: v1.ObjectMeta{
89101
Name: "a",
102+
Labels: map[string]string{
103+
"name": "a",
104+
},
90105
},
91106
},
92107
},
@@ -96,14 +111,12 @@ func TestFindTenants(t *testing.T) {
96111
},
97112
{
98113
name: "dynamic logging targets with a static watch namespace list",
99-
targets: []v1beta1.Target{
114+
targets: []v1.LabelSelector{
100115
{
101-
LoggingSelector: &v1.LabelSelector{
102-
MatchExpressions: []v1.LabelSelectorRequirement{
103-
{
104-
Key: "tenant",
105-
Operator: v1.LabelSelectorOpExists,
106-
},
116+
MatchExpressions: []v1.LabelSelectorRequirement{
117+
{
118+
Key: "tenant",
119+
Operator: v1.LabelSelectorOpExists,
107120
},
108121
},
109122
},
@@ -144,15 +157,20 @@ func TestFindTenants(t *testing.T) {
144157
},
145158
{
146159
name: "allNamespace allowed for self referencing target",
147-
targets: []v1beta1.Target{
160+
targets: []v1.LabelSelector{
148161
{
149-
LoggingName: currentLoggingName,
162+
MatchLabels: map[string]string{
163+
"name": currentLoggingName,
164+
},
150165
},
151166
},
152167
loggings: []*v1beta1.Logging{
153168
{
154169
ObjectMeta: v1.ObjectMeta{
155170
Name: currentLoggingName,
171+
Labels: map[string]string{
172+
"name": currentLoggingName,
173+
},
156174
},
157175
},
158176
},

docs/configuration/crds/v1beta1/fluentbit_types.md

+3-18
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,11 @@ Default: -
281281

282282
## LogRouting
283283

284-
### enabled (bool, optional) {#logrouting-enabled}
284+
LogRouting defines alternative log destinations
285285

286-
Default: -
287-
288-
### targets ([]Target, optional) {#logrouting-targets}
289-
290-
Default: -
291-
292-
293-
## Target
294-
295-
### logging (string, required) {#target-logging}
296-
297-
Name of the remote logging resource to use as an output The namespaces will be selected based on the remote logging's `watchNamespaces` and `watchNamespaceSelector` fields. An empty set means all namespaces, but that is only allowed if the logging target matches the actual logging this agent belongs to.
298-
299-
Default: -
300-
301-
### targetSelector (*metav1.LabelSelector, optional) {#target-targetselector}
286+
### targets ([]metav1.LabelSelector, optional) {#logrouting-targets}
302287

303-
LabelSelector to identify the remote logging resource to use as an output The namespaces will be selected based on the remote logging's `watchNamespaces` and `watchNamespaceSelector` fields. An empty set means all namespaces, but that is only allowed if the logging target matches the actual logging this agent belongs to.
288+
Targets define the selectors to identify Logging resources where logs should be sent Logs are filtered based on the target Logging's watchNamespaces and watchNamespaceSelector
304289

305290
Default: -
306291

0 commit comments

Comments
 (0)