Skip to content

Commit 8b00604

Browse files
support excluding namespaces in helm chart (#564)
1 parent 0c409c7 commit 8b00604

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

charts/k8s-reporter/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 1.10.0
18+
version: 1.11.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "2.11.15"
24+
appVersion: "2.11.27"

charts/k8s-reporter/templates/_validations.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@ Validate that namespacesRegex is not used with namespace-scoped permissions
55
{{- if and (eq .Values.serviceAccount.permissionScope "namespace") (ne .Values.reporterConfig.namespacesRegex "") -}}
66
{{- fail "namespacesRegex cannot be used with namespace-scoped permissions (serviceAccount.permissionScope: namespace). namespacesRegex requires cluster-wide permissions." -}}
77
{{- end -}}
8+
{{- end -}}
9+
10+
{{/*
11+
Validate that excludeNamespacesRegex is not used with namespace-scoped permissions
12+
*/}}
13+
{{- define "k8s-reporter.validateExcludeNamespacesRegex" -}}
14+
{{- if and (eq .Values.serviceAccount.permissionScope "namespace") (ne .Values.reporterConfig.excludeNamespacesRegex "") -}}
15+
{{- fail "excludeNamespacesRegex cannot be used with namespace-scoped permissions (serviceAccount.permissionScope: namespace). excludeNamespacesRegex requires cluster-wide permissions." -}}
16+
{{- end -}}
17+
{{- end -}}
18+
19+
{{/*
20+
Validate that exclude options are not combined with include options
21+
*/}}
22+
{{- define "k8s-reporter.validateExcludeOptions" -}}
23+
{{- if and (ne .Values.reporterConfig.namespaces "") (or (ne .Values.reporterConfig.excludeNamespaces "") (ne .Values.reporterConfig.excludeNamespacesRegex "")) -}}
24+
{{- fail "excludeNamespaces and excludeNamespacesRegex cannot be combined with namespaces. Use either include (namespaces/namespacesRegex) or exclude (excludeNamespaces/excludeNamespacesRegex) options, but not both." -}}
25+
{{- end -}}
26+
{{- if and (ne .Values.reporterConfig.namespacesRegex "") (or (ne .Values.reporterConfig.excludeNamespaces "") (ne .Values.reporterConfig.excludeNamespacesRegex "")) -}}
27+
{{- fail "excludeNamespaces and excludeNamespacesRegex cannot be combined with namespacesRegex. Use either include (namespaces/namespacesRegex) or exclude (excludeNamespaces/excludeNamespacesRegex) options, but not both." -}}
28+
{{- end -}}
829
{{- end -}}

charts/k8s-reporter/templates/cronjob.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{{- include "k8s-reporter.validateNamespacesRegex" . -}}
2+
{{- include "k8s-reporter.validateExcludeNamespacesRegex" . -}}
3+
{{- include "k8s-reporter.validateExcludeOptions" . -}}
24
apiVersion: batch/v1
35
kind: CronJob
46
metadata:
@@ -57,6 +59,12 @@ spec:
5759
{{ else if .Values.reporterConfig.namespacesRegex }}
5860
- name: KOSLI_NAMESPACES_REGEX
5961
value: {{ .Values.reporterConfig.namespacesRegex | quote }}
62+
{{ else if .Values.reporterConfig.excludeNamespaces }}
63+
- name: KOSLI_EXCLUDE_NAMESPACES
64+
value: {{ .Values.reporterConfig.excludeNamespaces | quote }}
65+
{{ else if .Values.reporterConfig.excludeNamespacesRegex }}
66+
- name: KOSLI_EXCLUDE_NAMESPACES_REGEX
67+
value: {{ .Values.reporterConfig.excludeNamespacesRegex | quote }}
6068
{{ end }}
6169

6270
{{- range $key, $value := .Values.env }}

charts/k8s-reporter/values.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ image:
88
# -- the kosli reporter image pull policy
99
pullPolicy: IfNotPresent
1010
# -- the kosli reporter image tag, overrides the image tag whose default is the chart appVersion.
11-
tag: "v2.11.17"
11+
tag: "v2.11.27"
1212

1313
# -- overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one
1414
nameOverride: ""
@@ -44,15 +44,29 @@ reporterConfig:
4444
# -- the name of Kosli environment that the k8s cluster/namespace correlates to
4545
kosliEnvironmentName: ""
4646
# -- the namespaces to scan and report.
47+
# Cannot be combined with excludeNamespaces or excludeNamespacesRegex.
4748
# It is a comma separated list of namespace names.
4849
# leave this and namespacesRegex unset if you want to report what is running in the entire cluster
4950
namespaces: ""
5051
# -- the namespaces Regex patterns to scan and report.
5152
# Does not have effect if namespaces is set.
5253
# Requires cluster-wide permissions.
54+
# Cannot be combined with excludeNamespaces or excludeNamespacesRegex.
5355
# It is a comma separated list of namespace regex patterns.
5456
# leave this and namespaces unset if you want to report what is running in the entire cluster
5557
namespacesRegex: ""
58+
# -- the namespaces to exclude from scanning and reporting.
59+
# Cannot be combined with namespaces or namespacesRegex.
60+
# It is a comma separated list of namespace names.
61+
# leave this and excludeNamespacesRegex unset if you want to report what is running in the entire cluster
62+
excludeNamespaces: ""
63+
# -- the namespaces Regex patterns to exclude from scanning and reporting.
64+
# Does not have effect if excludeNamespaces is set.
65+
# Cannot be combined with namespaces or namespacesRegex.
66+
# Requires cluster-wide permissions.
67+
# It is a comma separated list of namespace regex patterns.
68+
# leave this and excludeNamespaces unset if you want to report what is running in the entire cluster
69+
excludeNamespacesRegex: ""
5670
# -- whether the dry run mode is enabled or not. In dry run mode, the reporter logs the reports to stdout and does not send them to kosli.
5771
dryRun: false
5872
# -- the http proxy url

cmd/kosli/archiveEnvironment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func (suite *ArchiveEnvironmentCommandTestSuite) TestArchiveEnvironmentCmd() {
3636
golden: "environment archive-environment was archived\n",
3737
},
3838
{
39-
wantError: true,
40-
name: "archiving non-existing environment fails",
41-
cmd: fmt.Sprintf(`archive environment non-existing %s`, suite.defaultKosliArguments),
42-
golden: "Error: Environment named 'non-existing' does not exist for organization 'docs-cmd-test-user'. \n",
39+
wantError: true,
40+
name: "archiving non-existing environment fails",
41+
cmd: fmt.Sprintf(`archive environment non-existing %s`, suite.defaultKosliArguments),
42+
goldenRegex: "^Error: Environment named 'non-existing' does not exist for organization 'docs-cmd-test-user'",
4343
},
4444
{
4545
wantError: true,

0 commit comments

Comments
 (0)