Skip to content

Commit f25a76f

Browse files
allow deploying helm chart for one namespace with limited permissions (#389)
1 parent 5af8cc2 commit f25a76f

File tree

8 files changed

+139
-30
lines changed

8 files changed

+139
-30
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.5.1
18+
version: 1.6.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.10.13"
24+
appVersion: "2.11.3"

charts/k8s-reporter/README.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Kubernetes Reporter Helm Chart
44

55
# k8s-reporter
66

7-
![Version: 1.5.1](https://img.shields.io/badge/Version-1.5.1-informational?style=flat-square)
7+
![Version: 1.6.0](https://img.shields.io/badge/Version-1.6.0-informational?style=flat-square)
88

99
A Helm chart for installing the Kosli K8S reporter as a cronjob.
1010
The chart allows you to create a Kubernetes cronjob and all its necessary RBAC to report running images to Kosli at a given cron schedule.
@@ -13,30 +13,66 @@ The chart allows you to create a Kubernetes cronjob and all its necessary RBAC t
1313

1414
- A Kubernetes cluster (minimum supported version is `v1.21`)
1515
- Helm v3.0+
16-
- Create a secret for the Kosli API token which will be used for reporting. You can create a secret by running: `kubectl create secret generic <secret-name> --from-literal=<secret-key>=<your-api-key>`
16+
- If you want to report artifacts from just one namespace, you need to have permissions to `get` and `list` pods in that namespace.
17+
- If you want to report artifacts from multiple namespaces or entire cluster, you need to have cluster-wide permissions to `get` and `list` pods.
1718

1819
## Installing the chart
1920

2021
To install this chart via the Helm chart repository:
2122

22-
```shell
23-
helm repo add kosli https://charts.kosli.com/
24-
helm repo update
25-
helm install [RELEASE-NAME] kosli/k8s-reporter -f [VALUES-FILE-PATH]
23+
1. Add the Kosli helm repo
24+
```shell {.command}
25+
helm repo add kosli https://charts.kosli.com/ && helm repo update
26+
```
27+
28+
2. Create a secret for the Kosli API token
29+
```shell {.command}
30+
kubectl create secret generic kosli-api-token --from-literal=key=<your-api-key>
31+
```
32+
33+
3. Install the helm chart
34+
35+
A. To report artifacts running in entire cluster (requires cluster-wide read permissions):
36+
37+
```shell {.command}
38+
helm install kosli-reporter kosli/k8s-reporter \
39+
--set reporterConfig.kosliOrg=<your-org> \
40+
--set reporterConfig.kosliEnvironmentName=<your-env-name>
41+
```
42+
43+
B. To report artifacts running in multiple namespaces (requires cluster-wide read permissions):
44+
45+
```shell {.command}
46+
helm install kosli-reporter kosli/k8s-reporter \
47+
--set reporterConfig.kosliOrg=<your-org> \
48+
--set reporterConfig.kosliEnvironmentName=<your-env-name> \
49+
--set reporterConfig.namespaces=<namespace1,namespace2>
50+
```
51+
52+
C. To report artifacts running in one namespace (requires namespace-scoped read permissions):
53+
54+
```shell {.command}
55+
helm install kosli-reporter kosli/k8s-reporter \
56+
--set reporterConfig.kosliOrg=<your-org> \
57+
--set reporterConfig.kosliEnvironmentName=<your-env-name> \
58+
--set reporterConfig.namespaces=<namespace1> \
59+
--set serviceAccount.permissionScope=namespace
2660
```
2761

2862
> Chart source can be found at https://github.com/kosli-dev/cli/tree/main/charts/k8s-reporter
2963
64+
> See all available [configuration options](#configurations) below.
65+
3066
## Upgrading the chart
3167

32-
```shell
33-
helm upgrade [RELEASE-NAME] kosli/k8s-reporter
68+
```shell {.command}
69+
helm upgrade kosli-reporter kosli/k8s-reporter ...
3470
```
3571

3672
## Uninstalling chart
3773

38-
```shell
39-
helm uninstall [RELEASE-NAME]
74+
```shell {.command}
75+
helm uninstall kosli-reporter
4076
```
4177

4278
## Configurations
@@ -46,23 +82,24 @@ helm uninstall [RELEASE-NAME]
4682
| fullnameOverride | string | `""` | overrides the fullname used for the created k8s resources. It has higher precedence than `nameOverride` |
4783
| image.pullPolicy | string | `"IfNotPresent"` | the kosli reporter image pull policy |
4884
| image.repository | string | `"ghcr.io/kosli-dev/cli"` | the kosli reporter image repository |
49-
| image.tag | string | `"v2.10.13"` | the kosli reporter image tag, overrides the image tag whose default is the chart appVersion. |
85+
| image.tag | string | `"v2.11.3"` | the kosli reporter image tag, overrides the image tag whose default is the chart appVersion. |
5086
| kosliApiToken.secretKey | string | `"key"` | the name of the key in the secret data which contains the Kosli API token |
5187
| kosliApiToken.secretName | string | `"kosli-api-token"` | the name of the secret containing the kosli API token |
5288
| nameOverride | string | `""` | overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one |
53-
| podAnnotations | object | `{}` | |
89+
| podAnnotations | object | `{}` | any custom annotations to be added to the cronjob |
5490
| reporterConfig.dryRun | bool | `false` | 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. |
5591
| reporterConfig.httpProxy | string | `""` | the http proxy url |
5692
| reporterConfig.kosliEnvironmentName | string | `""` | the name of Kosli environment that the k8s cluster/namespace correlates to |
5793
| reporterConfig.kosliOrg | string | `""` | the name of the Kosli org |
58-
| reporterConfig.namespaces | string | `""` | the namespaces which represent the environment. It is a comma separated list of namespace name regex patterns. e.g. `^prod$,^dev-*` reports for the `prod` namespace and any namespace that starts with `dev-` leave this unset if you want to report what is running in the entire cluster |
94+
| reporterConfig.namespaces | string | `""` | the namespaces which represent the environment. It is a comma separated list of namespace names. leave this unset if you want to report what is running in the entire cluster |
5995
| resources.limits.cpu | string | `"100m"` | the cpu limit |
6096
| resources.limits.memory | string | `"256Mi"` | the memory limit |
6197
| resources.requests.memory | string | `"64Mi"` | the memory request |
6298
| serviceAccount.annotations | object | `{}` | annotations to add to the service account |
6399
| serviceAccount.create | bool | `true` | specifies whether a service account should be created |
64100
| serviceAccount.name | string | `""` | the name of the service account to use. If not set and create is true, a name is generated using the fullname template |
101+
| serviceAccount.permissionScope | string | `"cluster"` | specifies whether to create a cluster-wide permissions for the service account or namespace-scoped permissions. allowed values are: [cluster, namespace] |
65102

66103
----------------------------------------------
67-
Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0)
104+
Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0)
68105

charts/k8s-reporter/_templates.gotmpl

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,73 @@ The chart allows you to create a Kubernetes cronjob and all its necessary RBAC t
77

88
- A Kubernetes cluster (minimum supported version is `v1.21`)
99
- Helm v3.0+
10-
- Create a secret for the Kosli API token which will be used for reporting. You can create a secret by running: `kubectl create secret generic <secret-name> --from-literal=<secret-key>=<your-api-key>`
10+
- If you want to report artifacts from just one namespace, you need to have permissions to `get` and `list` pods in that namespace.
11+
- If you want to report artifacts from multiple namespaces or entire cluster, you need to have cluster-wide permissions to `get` and `list` pods.
1112
{{- end }}
1213

1314
{{ define "extra.install" -}}
1415
## Installing the chart
1516

1617
To install this chart via the Helm chart repository:
1718

18-
```shell
19-
helm repo add kosli https://charts.kosli.com/
20-
helm repo update
21-
helm install [RELEASE-NAME] kosli/k8s-reporter -f [VALUES-FILE-PATH]
19+
1. Add the Kosli helm repo
20+
```shell {.command}
21+
helm repo add kosli https://charts.kosli.com/ && helm repo update
22+
```
23+
24+
2. Create a secret for the Kosli API token
25+
```shell {.command}
26+
kubectl create secret generic kosli-api-token --from-literal=key=<your-api-key>
27+
```
28+
29+
3. Install the helm chart
30+
31+
A. To report artifacts running in entire cluster (requires cluster-wide read permissions):
32+
33+
```shell {.command}
34+
helm install kosli-reporter kosli/k8s-reporter \
35+
--set reporterConfig.kosliOrg=<your-org> \
36+
--set reporterConfig.kosliEnvironmentName=<your-env-name>
37+
```
38+
39+
B. To report artifacts running in multiple namespaces (requires cluster-wide read permissions):
40+
41+
```shell {.command}
42+
helm install kosli-reporter kosli/k8s-reporter \
43+
--set reporterConfig.kosliOrg=<your-org> \
44+
--set reporterConfig.kosliEnvironmentName=<your-env-name> \
45+
--set reporterConfig.namespaces=<namespace1,namespace2>
46+
```
47+
48+
C. To report artifacts running in one namespace (requires namespace-scoped read permissions):
49+
50+
```shell {.command}
51+
helm install kosli-reporter kosli/k8s-reporter \
52+
--set reporterConfig.kosliOrg=<your-org> \
53+
--set reporterConfig.kosliEnvironmentName=<your-env-name> \
54+
--set reporterConfig.namespaces=<namespace1> \
55+
--set serviceAccount.permissionScope=namespace
2256
```
2357

2458
> Chart source can be found at https://github.com/kosli-dev/cli/tree/main/charts/k8s-reporter
59+
60+
> See all available [configuration options](#configurations) below.
61+
2562
{{- end }}
2663

2764
{{ define "extra.upgrade" -}}
2865
## Upgrading the chart
2966

30-
```shell
31-
helm upgrade [RELEASE-NAME] kosli/k8s-reporter
67+
```shell {.command}
68+
helm upgrade kosli-reporter kosli/k8s-reporter ...
3269
```
3370
{{- end }}
3471

3572
{{ define "extra.uninstall" -}}
3673
## Uninstalling chart
3774

38-
```shell
39-
helm uninstall [RELEASE-NAME]
75+
```shell {.command}
76+
helm uninstall kosli-reporter
4077
```
4178
{{- end }}
4279

charts/k8s-reporter/templates/clusterrole.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if and .Values.serviceAccount.create (eq .Values.serviceAccount.permissionScope "cluster") -}}
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRole
34
metadata:
@@ -11,4 +12,5 @@ rules:
1112
verbs: ["get", "list"]
1213
- apiGroups: [""]
1314
resources: ["pods"]
14-
verbs: ["get", "list"]
15+
verbs: ["get", "list"]
16+
{{- end }}

charts/k8s-reporter/templates/clusterrolebinding.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if and .Values.serviceAccount.create (eq .Values.serviceAccount.permissionScope "cluster") -}}
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: ClusterRoleBinding
34
metadata:
@@ -12,4 +13,5 @@ subjects:
1213
roleRef:
1314
kind: ClusterRole
1415
name: {{ include "reporter.fullname" . }}
15-
apiGroup: rbac.authorization.k8s.io
16+
apiGroup: rbac.authorization.k8s.io
17+
{{- end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if and .Values.serviceAccount.create (eq .Values.serviceAccount.permissionScope "namespace") -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: {{ include "reporter.fullname" . }}
6+
labels:
7+
{{- include "reporter.labels" . | nindent 4 }}
8+
9+
rules:
10+
- apiGroups: [""]
11+
resources: ["pods"]
12+
verbs: ["get", "list"]
13+
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if and .Values.serviceAccount.create (eq .Values.serviceAccount.permissionScope "namespace") -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ include "reporter.fullname" . }}
6+
labels:
7+
{{- include "reporter.labels" . | nindent 4 }}
8+
9+
subjects:
10+
- kind: ServiceAccount
11+
name: {{ include "reporter.serviceAccountName" . }}
12+
namespace: {{ .Release.Namespace }}
13+
roleRef:
14+
kind: Role
15+
name: {{ include "reporter.fullname" . }}
16+
apiGroup: rbac.authorization.k8s.io
17+
{{- end }}

charts/k8s-reporter/values.yaml

Lines changed: 4 additions & 3 deletions
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.10.13"
11+
tag: "v2.11.3"
1212

1313
# -- overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one
1414
nameOverride: ""
@@ -18,6 +18,8 @@ fullnameOverride: ""
1818
serviceAccount:
1919
# -- specifies whether a service account should be created
2020
create: true
21+
# -- specifies whether to create a cluster-wide permissions for the service account or namespace-scoped permissions. allowed values are: [cluster, namespace]
22+
permissionScope: cluster
2123
# -- annotations to add to the service account
2224
annotations: {}
2325
# -- the name of the service account to use.
@@ -39,8 +41,7 @@ reporterConfig:
3941
# -- the name of Kosli environment that the k8s cluster/namespace correlates to
4042
kosliEnvironmentName: ""
4143
# -- the namespaces which represent the environment.
42-
# It is a comma separated list of namespace name regex patterns.
43-
# e.g. `^prod$,^dev-*` reports for the `prod` namespace and any namespace that starts with `dev-`
44+
# It is a comma separated list of namespace names.
4445
# leave this unset if you want to report what is running in the entire cluster
4546
namespaces: ""
4647
# -- 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.

0 commit comments

Comments
 (0)