diff --git a/charts/falco/CHANGELOG.md b/charts/falco/CHANGELOG.md index 39c40db59..116575517 100644 --- a/charts/falco/CHANGELOG.md +++ b/charts/falco/CHANGELOG.md @@ -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 diff --git a/charts/falco/Chart.yaml b/charts/falco/Chart.yaml index 3400a4cfd..ff7962299 100644 --- a/charts/falco/Chart.yaml +++ b/charts/falco/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: falco -version: 4.16.0 +version: 4.16.1 appVersion: "0.39.2" description: Falco keywords: diff --git a/charts/falco/README.md b/charts/falco/README.md index b7af9856a..e606cedc2 100644 --- a/charts/falco/README.md +++ b/charts/falco/README.md @@ -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 diff --git a/charts/falco/templates/serviceMonitor.yaml b/charts/falco/templates/serviceMonitor.yaml index 0dea6dd6e..6a80b7137 100644 --- a/charts/falco/templates/serviceMonitor.yaml +++ b/charts/falco/templates/serviceMonitor.yaml @@ -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: diff --git a/charts/falco/tests/unit/serviceMonitorTemplate_test.go b/charts/falco/tests/unit/serviceMonitorTemplate_test.go index b2fcb3745..ea914e281 100644 --- a/charts/falco/tests/unit/serviceMonitorTemplate_test.go +++ b/charts/falco/tests/unit/serviceMonitorTemplate_test.go @@ -83,7 +83,12 @@ 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 @@ -91,3 +96,64 @@ func (s *serviceMonitorTemplateTest) TestNamespaceSelector() { 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") + }) + } +}