Skip to content

Commit a0111f1

Browse files
[helm] fix disabling cluster role and service account (#6004)
* fix: allow disabling cluster role creation without needing to specify an existing one * fix: fallback to default service account when creation is disabled and no existing one is specified * fix: update nginx custom integration to disable all k8s agent providers
1 parent d9587c4 commit a0111f1

File tree

7 files changed

+12
-220
lines changed

7 files changed

+12
-220
lines changed

deploy/helm/elastic-agent/examples/nginx-custom-integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example: Nginx Custom Integration
22

3-
In this example we define a `nginx` custom integration alongside a custom agent preset defined in [agent-nginx-values.yaml](agent-nginx-values.yaml).
3+
In this example we define a `nginx` custom integration alongside a custom agent preset defined in [agent-nginx-values.yaml](agent-nginx-values.yaml). Also, we disable all `kubernetes` related providers and creation of cluster role and service account, as they are not required for this example.
44

55
## Prerequisites:
66
1. A k8s secret that contains the connection details to an Elasticsearch cluster such as the URL and the API key ([Kibana - Creating API Keys](https://www.elastic.co/guide/en/kibana/current/api-keys.html)):

deploy/helm/elastic-agent/examples/nginx-custom-integration/agent-nginx-values.yaml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,13 @@ agent:
3434
presets:
3535
nginx:
3636
mode: deployment
37+
automountServiceAccountToken: false # disables all kubernetes providers
3738
securityContext:
3839
runAsUser: 0
3940
serviceAccount:
40-
create: true
41+
create: false # disable creation of service account
4142
clusterRole:
42-
create: true
43-
rules:
44-
# minimum cluster role ruleset required by agent
45-
- apiGroups: [ "" ]
46-
resources:
47-
- nodes
48-
- namespaces
49-
- pods
50-
verbs:
51-
- get
52-
- watch
53-
- list
54-
- apiGroups: [ "apps" ]
55-
resources:
56-
- replicasets
57-
verbs:
58-
- get
59-
- list
60-
- watch
61-
- apiGroups: [ "batch" ]
62-
resources:
63-
- jobs
64-
verbs:
65-
- get
66-
- list
67-
- watch
43+
create: false # disable creation of cluster role account
6844
providers:
6945
kubernetes_leaderelection:
70-
enabled: false
46+
enabled: false # disable leader election

deploy/helm/elastic-agent/examples/nginx-custom-integration/rendered/manifest.yaml

Lines changed: 1 addition & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
---
2-
# Source: elastic-agent/templates/agent/service-account.yaml
3-
apiVersion: v1
4-
kind: ServiceAccount
5-
metadata:
6-
name: agent-nginx-example
7-
namespace: "default"
8-
labels:
9-
helm.sh/chart: elastic-agent-0.0.1
10-
app.kubernetes.io/name: elastic-agent
11-
app.kubernetes.io/instance: example
12-
app.kubernetes.io/version: 9.0.0
13-
app.kubernetes.io/managed-by: Helm
14-
---
152
# Source: elastic-agent/templates/agent/k8s/secret.yaml
163
apiVersion: v1
174
kind: Secret
@@ -68,133 +55,6 @@ stringData:
6855
enabled: false
6956
leader_lease: example-nginx
7057
---
71-
# Source: elastic-agent/templates/agent/cluster-role.yaml
72-
apiVersion: rbac.authorization.k8s.io/v1
73-
kind: ClusterRole
74-
metadata:
75-
name: agent-nginx-example-default
76-
labels:
77-
helm.sh/chart: elastic-agent-0.0.1
78-
app.kubernetes.io/name: elastic-agent
79-
app.kubernetes.io/instance: example
80-
app.kubernetes.io/version: 9.0.0
81-
app.kubernetes.io/managed-by: Helm
82-
rules:
83-
- apiGroups: [ "" ] # "" indicates the core API group
84-
resources:
85-
- nodes
86-
- namespaces
87-
- events
88-
- pods
89-
- services
90-
- configmaps
91-
- persistentvolumes
92-
- persistentvolumeclaims
93-
- persistentvolumeclaims/status
94-
- nodes/metrics
95-
- nodes/proxy
96-
- nodes/stats
97-
verbs:
98-
- get
99-
- watch
100-
- list
101-
- apiGroups:
102-
- storage.k8s.io
103-
resources:
104-
- storageclasses
105-
verbs:
106-
- get
107-
- watch
108-
- list
109-
- nonResourceURLs:
110-
- /metrics
111-
verbs:
112-
- get
113-
- watch
114-
- list
115-
- apiGroups: [ "coordination.k8s.io" ]
116-
resources:
117-
- leases
118-
verbs:
119-
- get
120-
- create
121-
- update
122-
- nonResourceURLs:
123-
- /healthz
124-
- /healthz/*
125-
- /livez
126-
- /livez/*
127-
- /metrics
128-
- /metrics/slis
129-
- /readyz
130-
- /readyz/*
131-
verbs:
132-
- get
133-
- apiGroups: [ "apps" ]
134-
resources:
135-
- replicasets
136-
- deployments
137-
- daemonsets
138-
- statefulsets
139-
verbs:
140-
- get
141-
- list
142-
- watch
143-
- apiGroups: [ "batch" ]
144-
resources:
145-
- jobs
146-
- cronjobs
147-
verbs:
148-
- get
149-
- list
150-
- watch
151-
- apiGroups:
152-
- ""
153-
resources:
154-
- nodes
155-
- namespaces
156-
- pods
157-
verbs:
158-
- get
159-
- watch
160-
- list
161-
- apiGroups:
162-
- apps
163-
resources:
164-
- replicasets
165-
verbs:
166-
- get
167-
- list
168-
- watch
169-
- apiGroups:
170-
- batch
171-
resources:
172-
- jobs
173-
verbs:
174-
- get
175-
- list
176-
- watch
177-
---
178-
# Source: elastic-agent/templates/agent/cluster-role-binding.yaml
179-
apiVersion: rbac.authorization.k8s.io/v1
180-
kind: ClusterRoleBinding
181-
metadata:
182-
name: agent-nginx-example-default
183-
labels:
184-
helm.sh/chart: elastic-agent-0.0.1
185-
app.kubernetes.io/name: elastic-agent
186-
app.kubernetes.io/instance: example
187-
app.kubernetes.io/version: 9.0.0
188-
app.kubernetes.io/managed-by: Helm
189-
subjects:
190-
- kind: ServiceAccount
191-
name: agent-nginx-example
192-
namespace: "default"
193-
roleRef:
194-
kind: ClusterRole
195-
name: agent-nginx-example-default
196-
apiGroup: rbac.authorization.k8s.io
197-
---
19858
# Source: elastic-agent/templates/agent/k8s/deployment.yaml
19959
apiVersion: apps/v1
20060
kind: Deployment
@@ -218,7 +78,7 @@ spec:
21878
annotations:
21979
checksum/config: 99eaac30ab163ab5f4cedbdbf3e6936d34c2b0e2c22dee59947487bab88fcc26
22080
spec:
221-
automountServiceAccountToken: true
81+
automountServiceAccountToken: false
22282
containers:
22383
- args:
22484
- -c
@@ -248,7 +108,6 @@ spec:
248108
readOnly: true
249109
subPath: agent.yml
250110
dnsPolicy: ClusterFirstWithHostNet
251-
serviceAccountName: agent-nginx-example
252111
volumes:
253112
- hostPath:
254113
path: /etc/elastic-agent/default/agent-nginx-example/state

deploy/helm/elastic-agent/templates/agent/cluster-role-binding.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{- include "elasticagent.init" $ -}}
22
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
3-
{{- if or (eq $presetVal.clusterRole.create true) (eq $presetVal.serviceAccount.create true) -}}
3+
{{- if or ($presetVal).clusterRole.create ($presetVal).clusterRole.name -}}
4+
{{- if or ($presetVal).serviceAccount.create ($presetVal).serviceAccount.name -}}
45
{{/* cluster role binding is not namespace bound so let's try to give it a unique enough name */}}
56
{{- $clusterRoleName := printf "agent-%s-%s-%s" $presetName $.Release.Name $.Release.Namespace -}}
67
apiVersion: rbac.authorization.k8s.io/v1
@@ -35,3 +36,4 @@ roleRef:
3536
---
3637
{{- end }}
3738
{{- end }}
39+
{{- end }}

deploy/helm/elastic-agent/templates/agent/eck/_pod_template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template:
2424
{{- end }}
2525
{{- if eq ($presetVal).serviceAccount.create true }}
2626
serviceAccountName: {{ $agentName }}
27-
{{- else }}
27+
{{- else if ($presetVal).serviceAccount.name }}
2828
serviceAccountName: {{ ($presetVal).serviceAccount.name }}
2929
{{- end }}
3030
{{- with ($presetVal).affinity }}

deploy/helm/elastic-agent/templates/agent/k8s/_pod_template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template:
2424
{{- end }}
2525
{{- if eq ($presetVal).serviceAccount.create true }}
2626
serviceAccountName: {{ $agentName }}
27-
{{- else }}
27+
{{- else if ($presetVal).serviceAccount.name }}
2828
serviceAccountName: {{ ($presetVal).serviceAccount.name }}
2929
{{- end }}
3030
{{- with ($presetVal).affinity }}

deploy/helm/elastic-agent/values.schema.json

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,27 +1309,6 @@
13091309
"create"
13101310
],
13111311
"allOf": [
1312-
{
1313-
"if": {
1314-
"properties": {
1315-
"create": {
1316-
"const": false
1317-
}
1318-
}
1319-
},
1320-
"then": {
1321-
"properties": {
1322-
"name": {
1323-
"type": "string",
1324-
"minLength": 1
1325-
}
1326-
},
1327-
"required": [
1328-
"create",
1329-
"name"
1330-
]
1331-
}
1332-
},
13331312
{
13341313
"if": {
13351314
"properties": {
@@ -1344,10 +1323,7 @@
13441323
"type": "string",
13451324
"maxLength": 0
13461325
}
1347-
},
1348-
"required": [
1349-
"create"
1350-
]
1326+
}
13511327
}
13521328
}
13531329
]
@@ -1379,27 +1355,6 @@
13791355
"create"
13801356
],
13811357
"allOf": [
1382-
{
1383-
"if": {
1384-
"properties": {
1385-
"create": {
1386-
"const": false
1387-
}
1388-
}
1389-
},
1390-
"then": {
1391-
"properties": {
1392-
"name": {
1393-
"type": "string",
1394-
"minLength": 1
1395-
}
1396-
},
1397-
"required": [
1398-
"create",
1399-
"name"
1400-
]
1401-
}
1402-
},
14031358
{
14041359
"if": {
14051360
"properties": {

0 commit comments

Comments
 (0)