Skip to content

Commit c92ad31

Browse files
authored
Merge pull request #2011 from joseacl/issue-2010
Adapt LoggingOperator to use namespaces_regex defined in fluent-plugi…
2 parents ceda38e + a7c97bf commit c92ad31

File tree

11 files changed

+121
-3
lines changed

11 files changed

+121
-3
lines changed

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_clusterflows.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,10 @@ spec:
845845
items:
846846
type: string
847847
type: array
848+
namespaces_regex:
849+
items:
850+
type: string
851+
type: array
848852
type: object
849853
select:
850854
properties:
@@ -868,6 +872,10 @@ spec:
868872
items:
869873
type: string
870874
type: array
875+
namespaces_regex:
876+
items:
877+
type: string
878+
type: array
871879
type: object
872880
type: object
873881
type: array
@@ -1722,6 +1730,10 @@ spec:
17221730
items:
17231731
type: string
17241732
type: array
1733+
namespaces_regex:
1734+
items:
1735+
type: string
1736+
type: array
17251737
type: object
17261738
select:
17271739
properties:
@@ -1745,6 +1757,10 @@ spec:
17451757
items:
17461758
type: string
17471759
type: array
1760+
namespaces_regex:
1761+
items:
1762+
type: string
1763+
type: array
17481764
type: object
17491765
type: object
17501766
type: array

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ spec:
842842
items:
843843
type: string
844844
type: array
845+
namespaces_regex:
846+
items:
847+
type: string
848+
type: array
845849
type: object
846850
select:
847851
properties:
@@ -865,6 +869,10 @@ spec:
865869
items:
866870
type: string
867871
type: array
872+
namespaces_regex:
873+
items:
874+
type: string
875+
type: array
868876
type: object
869877
type: object
870878
type: array
@@ -1719,6 +1727,10 @@ spec:
17191727
items:
17201728
type: string
17211729
type: array
1730+
namespaces_regex:
1731+
items:
1732+
type: string
1733+
type: array
17221734
type: object
17231735
select:
17241736
properties:
@@ -1742,6 +1754,10 @@ spec:
17421754
items:
17431755
type: string
17441756
type: array
1757+
namespaces_regex:
1758+
items:
1759+
type: string
1760+
type: array
17451761
type: object
17461762
type: object
17471763
type: array

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ spec:
842842
items:
843843
type: string
844844
type: array
845+
namespaces_regex:
846+
items:
847+
type: string
848+
type: array
845849
type: object
846850
select:
847851
properties:
@@ -865,6 +869,10 @@ spec:
865869
items:
866870
type: string
867871
type: array
872+
namespaces_regex:
873+
items:
874+
type: string
875+
type: array
868876
type: object
869877
type: object
870878
type: array
@@ -1719,6 +1727,10 @@ spec:
17191727
items:
17201728
type: string
17211729
type: array
1730+
namespaces_regex:
1731+
items:
1732+
type: string
1733+
type: array
17221734
type: object
17231735
select:
17241736
properties:
@@ -1742,6 +1754,10 @@ spec:
17421754
items:
17431755
type: string
17441756
type: array
1757+
namespaces_regex:
1758+
items:
1759+
type: string
1760+
type: array
17451761
type: object
17461762
type: object
17471763
type: array

controllers/logging/logging_controller_match_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,49 @@ func TestClusterFlowMatchWithNamespaces(t *testing.T) {
154154
`))))
155155
}
156156

157+
func TestClusterFlowMatchWithNamespacesRegex(t *testing.T) {
158+
g := gomega.NewGomegaWithT(t)
159+
defer beforeEach(t)()
160+
161+
logging := testLogging()
162+
output := testClusterOutput()
163+
164+
flow := &v1beta1.ClusterFlow{
165+
ObjectMeta: v1.ObjectMeta{
166+
Name: "test-flow",
167+
Namespace: logging.Spec.ControlNamespace,
168+
},
169+
Spec: v1beta1.ClusterFlowSpec{
170+
Match: []v1beta1.ClusterMatch{
171+
{
172+
ClusterSelect: &v1beta1.ClusterSelect{
173+
Labels: map[string]string{
174+
"c": "d",
175+
},
176+
NamespacesRegex: []string{".*-system$", "^kube-.*"},
177+
},
178+
},
179+
},
180+
GlobalOutputRefs: []string{output.Name},
181+
},
182+
}
183+
184+
defer ensureCreated(t, logging)()
185+
defer ensureCreated(t, output)()
186+
defer ensureCreated(t, flow)()
187+
188+
secret := &corev1.Secret{}
189+
defer ensureCreatedEventually(t, controlNamespace, logging.QualifiedName(fluentd.AppSecretConfigName), secret)()
190+
191+
g.Expect(diff.TrimLinesInString(string(secret.Data[fluentd.AppConfigKey]))).Should(gomega.ContainSubstring(diff.TrimLinesInString(heredoc.Docf(`
192+
<match>
193+
labels c:d
194+
namespaces_regex .*-system$,^kube-.*
195+
negate false
196+
</match>
197+
`))))
198+
}
199+
157200
func TestInvalidFlowIfMatchAndSelectorBothSet(t *testing.T) {
158201
errors := make(chan error)
159202
defer beforeEachWithError(t, errors)()

docs/configuration/crds/v1beta1/clusterflow_types.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Name of the logging cluster to be attached
4949
### namespaces ([]string, optional) {#clusterselect-namespaces}
5050

5151

52+
### namespaces_regex ([]string, optional) {#clusterselect-namespaces_regex}
53+
54+
5255

5356
## ClusterExclude
5457

@@ -67,6 +70,9 @@ Name of the logging cluster to be attached
6770
### namespaces ([]string, optional) {#clusterexclude-namespaces}
6871

6972

73+
### namespaces_regex ([]string, optional) {#clusterexclude-namespaces_regex}
74+
75+
7076

7177
## ClusterFlowSpec
7278

images/fluentd/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ruby:3.4.2-alpine3.20 AS base
33
ARG BUILD_DEPS=" \
44
make gcc g++ libc-dev \
55
wget bzip2 zlib-dev git linux-headers \
6-
automake autoconf libtool build-base \
6+
automake autoconf libtool build-base \
77
ruby-dev libc6-compat geoip-dev \
88
snappy-dev gnupg bash openssl-dev \
99
ruby-bigdecimal \
@@ -25,7 +25,7 @@ RUN addgroup -S -g 101 fluent && adduser -S -G fluent -u 100 fluent \
2525
&& echo 'gem: --no-document' >> /etc/gemrc \
2626
&& gem install fluentd -v 1.17.1 \
2727
&& fluent-gem install specific_install -v 0.3.8 \
28-
&& fluent-gem install fluent-plugin-label-router -v 0.4.0 \
28+
&& fluent-gem install fluent-plugin-label-router -v 0.5.0 \
2929
&& find /usr/local/bundle/gems/ -newer /etc/gemrc -exec chown fluent:fluent {} \; \
3030
&& apk del $BUILD_DEPS \
3131
&& rm -rf /usr/local/bundle/cache/* && find /usr/local/bundle -name '*.o' -delete

pkg/resources/model/system.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ func FlowForClusterFlow(flow v1beta1.ClusterFlow, clusterOutputs ClusterOutputs,
328328
ContainerNames: match.ClusterSelect.ContainerNames,
329329
Hosts: match.ClusterSelect.Hosts,
330330
Namespaces: match.ClusterSelect.Namespaces,
331+
NamespacesRegex: match.ClusterSelect.NamespacesRegex,
331332
Negate: false,
332333
})
333334
}
@@ -338,6 +339,7 @@ func FlowForClusterFlow(flow v1beta1.ClusterFlow, clusterOutputs ClusterOutputs,
338339
ContainerNames: match.ClusterExclude.ContainerNames,
339340
Hosts: match.ClusterExclude.Hosts,
340341
Namespaces: match.ClusterExclude.Namespaces,
342+
NamespacesRegex: match.ClusterExclude.NamespacesRegex,
341343
Negate: true,
342344
})
343345
}

pkg/sdk/logging/api/v1beta1/clusterflow_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ClusterMatch struct {
5151

5252
type ClusterSelect struct {
5353
Namespaces []string `json:"namespaces,omitempty"`
54+
NamespacesRegex []string `json:"namespaces_regex,omitempty"`
5455
Labels map[string]string `json:"labels,omitempty"`
5556
NamespaceLabels map[string]string `json:"namespace_labels,omitempty"`
5657
Hosts []string `json:"hosts,omitempty"`
@@ -59,6 +60,7 @@ type ClusterSelect struct {
5960

6061
type ClusterExclude struct {
6162
Namespaces []string `json:"namespaces,omitempty"`
63+
NamespacesRegex []string `json:"namespaces_regex,omitempty"`
6264
Labels map[string]string `json:"labels,omitempty"`
6365
NamespaceLabels map[string]string `json:"namespace_labels,omitempty"`
6466
Hosts []string `json:"hosts,omitempty"`

pkg/sdk/logging/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sdk/logging/model/render/fluent_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ func TestRenderFullFluentConfig(t *testing.T) {
394394
"key1": "val1",
395395
"key2": "val2",
396396
},
397-
Namespaces: []string{"ns-test"},
397+
Namespaces: []string{"ns-test"},
398+
NamespacesRegex: []string{".*-system$"},
398399
NamespaceLabels: map[string]string{
399400
"ns_label_key": "ns_label_value",
400401
},
@@ -442,6 +443,7 @@ func TestRenderFullFluentConfig(t *testing.T) {
442443
labels key1:val1,key2:val2
443444
namespace_labels ns_label_key:ns_label_value
444445
namespaces ns-test
446+
namespaces_regex .*-system$
445447
negate false
446448
</match>
447449
</route>

pkg/sdk/logging/model/types/router.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type FlowMatch struct {
4949
NamespaceLabels map[string]string `json:"namespace_labels,omitempty"`
5050
// Optional namespace
5151
Namespaces []string `json:"namespaces,omitempty"`
52+
// Optional regex list for matching namespace
53+
NamespacesRegex []string `json:"namespaces_regex,omitempty"`
5254
// ContainerNames
5355
ContainerNames []string `json:"container_names,omitempty"`
5456
// Hosts
@@ -69,6 +71,9 @@ func (f FlowMatch) GetParams() Params {
6971
if len(f.Namespaces) > 0 {
7072
params["namespaces"] = strings.Join(f.Namespaces, ",")
7173
}
74+
if len(f.NamespacesRegex) > 0 {
75+
params["namespaces_regex"] = strings.Join(f.NamespacesRegex, ",")
76+
}
7277
if len(f.ContainerNames) > 0 {
7378
params["container_names"] = strings.Join(f.ContainerNames, ",")
7479
}

0 commit comments

Comments
 (0)