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

fix service monitor selector #791

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions charts/falco/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
This file documents all notable changes to Falco Helm Chart. The release
numbering uses [semantic versioning](http://semver.org).

## v4.16.1

* fix(falco/serviceMonitor): set service label selector
* new(falco/tests): add unit tests for serviceMonitor label selector

## v4.16.0

* bump falcosidekick dependency to v0.9.* to match with future versions
Expand Down
2 changes: 1 addition & 1 deletion charts/falco/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: falco
version: 4.16.0
version: 4.16.1
appVersion: "0.39.2"
description: Falco
keywords:
Expand Down
2 changes: 1 addition & 1 deletion charts/falco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ If you use a Proxy in your cluster, the requests between `Falco` and `Falcosidek

## Configuration

The following table lists the main configurable parameters of the falco chart v4.16.0 and their default values. See [values.yaml](./values.yaml) for full list.
The following table lists the main configurable parameters of the falco chart v4.16.1 and their default values. See [values.yaml](./values.yaml) for full list.

## Values

Expand Down
3 changes: 3 additions & 0 deletions charts/falco/templates/serviceMonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ spec:
selector:
matchLabels:
{{- include "falco.selectorLabels" . | nindent 6 }}
{{- with .Values.serviceMonitor.selector }}
{{- toYaml . | nindent 6 }}
{{- end }}
type: "falco-metrics"
namespaceSelector:
matchNames:
Expand Down
68 changes: 67 additions & 1 deletion charts/falco/tests/unit/serviceMonitorTemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,77 @@ func (s *serviceMonitorTemplateTest) TestEndpoint() {
}

func (s *serviceMonitorTemplateTest) TestNamespaceSelector() {
options := &helm.Options{SetValues: map[string]string{"serviceMonitor.create": "true"}}
selectorsLabelJson := `{
"app.kubernetes.io/instance": "my-falco",
"foo": "bar"
}`
options := &helm.Options{SetValues: map[string]string{"serviceMonitor.create": "true"},
SetJsonValues: map[string]string{"serviceMonitor.selector": selectorsLabelJson}}
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.releaseName, s.templates)

var svcMonitor monitoringv1.ServiceMonitor
helm.UnmarshalK8SYaml(s.T(), output, &svcMonitor)
s.Len(svcMonitor.Spec.NamespaceSelector.MatchNames, 1)
s.Equal("default", svcMonitor.Spec.NamespaceSelector.MatchNames[0])
}

func (s *serviceMonitorTemplateTest) TestServiceMonitorSelector() {
testCases := []struct {
name string
values string
expected map[string]string
}{
{
"defaultValues",
"",
map[string]string{
"app.kubernetes.io/instance": "falco-test",
"app.kubernetes.io/name": "falco",
"type": "falco-metrics",
},
},
{
"customValues",
`{
"foo": "bar"
}`,
map[string]string{
"app.kubernetes.io/instance": "falco-test",
"app.kubernetes.io/name": "falco",
"foo": "bar",
"type": "falco-metrics",
},
},
{
"overwriteDefaultValues",
`{
"app.kubernetes.io/instance": "falco-overwrite",
"foo": "bar"
}`,
map[string]string{
"app.kubernetes.io/instance": "falco-overwrite",
"app.kubernetes.io/name": "falco",
"foo": "bar",
"type": "falco-metrics",
},
},
}

for _, testCase := range testCases {
testCase := testCase

s.Run(testCase.name, func() {
subT := s.T()
subT.Parallel()

options := &helm.Options{SetValues: map[string]string{"serviceMonitor.create": "true"},
SetJsonValues: map[string]string{"serviceMonitor.selector": testCase.values}}
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.releaseName, s.templates)

var svcMonitor monitoringv1.ServiceMonitor
helm.UnmarshalK8SYaml(s.T(), output, &svcMonitor)

s.Equal(testCase.expected, svcMonitor.Spec.Selector.MatchLabels, "should be the same")
})
}
}
Loading