Skip to content

Commit 0b0f302

Browse files
committed
Handling the uninstallation properly + target allocator fixes
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
1 parent f67ac4b commit 0b0f302

File tree

10 files changed

+163
-36
lines changed

10 files changed

+163
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dist/
88

99
# Helm charts
1010
helmchart/otel-add-on/charts/*.tgz
11+
helmchart/otel-add-on/*.tgz
1112

1213
# generated
1314
/generated/*

helmchart/otel-add-on/.helmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
.idea/
2222
*.tmproj
2323
.vscode/
24+
25+
# Custom
26+
otel-add-on*.tgz
27+
_helm-docs-template.gotmpl

helmchart/otel-add-on/templates/NOTES.txt

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,61 @@
2121
{{- $collectors := include "operatorCrs" . | fromJsonArray }}
2222
Following components were installed:
2323
{{- if .Values.deployScaler }}
24-
- KEDA-OTel add-on
24+
KEDA-OTel add-on - 🐿
2525
{{- end }}
2626
{{- if .Values.otelOperator.enabled }}
27-
- OTel Operator
27+
OTel Operator - 🦑
2828
{{- end }}
2929
{{- range $collectors }}
30-
- OTel Collector with name '{{ .name | default $.Release.Name }}' (using the operator) ✓
30+
✓ OTel Collector with name '{{ .name | default $.Release.Name }}' (using the operator) -
31+
{{- if .targetAllocatorEnabled -}}
32+
{{- printf " target allocator mode watching Prom's CRs 🎯" -}}
33+
{{- else -}}
34+
{{- printf " 🚀" -}}
35+
{{- end -}}
3136
{{- end }}
3237
{{- if .Values.otelCollector.enabled }}
33-
- OTel Collector (using the helm chart)
34-
{{- $collectors = append $collectors .Values.otelCollector -}}
38+
OTel Collector (using the helm chart) - 👷
39+
{{- $collectors = append $collectors (mergeOverwrite .Values.otelCollector (dict "helm" true)) -}}
3540
{{- end }}
3641

3742
Architecture:
43+
{{- $char := "" -}}
44+
{{- $m := "" -}}
45+
{{- if .Values.otelOperator.enabled }}
46+
┏━━━━┓
47+
┃ 🦑 ┃
48+
╭╄┯┯┯┯╃╮
49+
50+
{{- end }}
3851
{{- printf "\n" -}}
3952
{{- if $collectors }}
4053
{{- range $collectors }}
4154
{{- printf " ┌──────────────┐ " -}}
4255
{{- end }}
4356
{{- printf "\n" -}}
4457
{{- range $collectors }}
45-
{{- printf " │ 🚀 │ " -}}
58+
{{- $char = "🚀" -}}
59+
{{- if .helm -}}
60+
{{- $char = "👷" -}}
61+
{{- end -}}
62+
{{- if .targetAllocatorEnabled -}}
63+
{{- $char = "🎯" -}}
64+
{{- end -}}
65+
{{- printf " │ %s │ " $char -}}
4666
{{- end }}
4767
{{- printf "\n" -}}
4868
{{- range $collectors }}
49-
{{- printf " │ %-13s│ " ((.name | default "byHelmChart") | trunc 11) -}}
69+
{{- printf " │ %-13s│ " ((.name | default $.Release.Name) | trunc 11) -}}
5070
{{- end }}
5171
{{- printf " (Collectors)" -}}
5272
{{- printf "\n" -}}
5373
{{- range $collectors }}
54-
{{- printf " │ %-13s│ " (printf "(%s)" (.mode | trunc 11)) -}}
74+
{{- $m = .mode -}}
75+
{{- if and .targetAllocatorEnabled (eq .mode "sidecar") -}}
76+
{{- $m = "statefulset" -}}
77+
{{- end -}}
78+
{{- printf " │ %-13s│ " (printf "•%s" ($m | trunc 11)) -}}
5579
{{- end }}
5680
{{- printf "\n" -}}
5781
{{- range $collectors }}
@@ -72,12 +96,15 @@ Architecture:
7296
{{- if and .Values.deployScaler $collectors }}
7397
{{- printf " ╵ \n ╵ \n ╵ " -}}
7498
{{- end }}
99+
{{- else }}
100+
(No collectors yet)
101+
75102
{{- end }}
76103

77104
{{- if .Values.deployScaler }}
78-
{{- printf " ╭──────────────────╮ ╭╸╸╸╸╸╸╮\n" -}}
105+
{{- printf " ╭─────────────────────╮ ╭╶╶╶╶╶╶╮\n" -}}
79106
{{- if $collectors -}}{{- printf " └╴╴→" -}}{{- end -}}
80-
{{- printf " │ KEDA OTel Scaler │ ←╴╴╴╴╴→ KEDA \n" -}}
107+
{{- printf " │ KEDA OTel Scaler 🐿 │ ←╴╴╴╴╴→ KEDA \n" -}}
81108
{{- if $collectors -}}{{- printf " " -}}{{- end -}}
82-
{{- printf " ╰──────────────────╯ ╰╸╸╸╸╸╸╯\n" -}}
109+
{{- printf " ╰─────────────────────╯ ╰╶╶╶╶╶╶╯\n" -}}
83110
{{- end }}

helmchart/otel-add-on/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Merge the default settings
7070
{{- $merged := dict }}
7171
{{- range .Values.otelOperatorCrs }}
7272
{{- if .enabled }}
73-
{{- $merged = merge . $.Values.otelOperatorCrDefaultTemplate }}
73+
{{- $merged = mergeOverwrite $.Values.otelOperatorCrDefaultTemplate . }}
7474
{{- $allmerged = append $allmerged $merged }}
7575
{{- end }}
7676
{{- end }}

helmchart/otel-add-on/templates/install-otc/otc-additional-rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ metadata:
6969
apiVersion: rbac.authorization.k8s.io/v1
7070
kind: ClusterRoleBinding
7171
metadata:
72-
name: {{ . }}
72+
name: {{ . }}-otc
7373
labels:
7474
{{- include "otel-add-on.labels" $ | nindent 4 }}
7575
roleRef:

helmchart/otel-add-on/templates/install-otc/otc-configmap.yaml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ data:
1515
kind: OpenTelemetryCollector
1616
metadata:
1717
name: {{ .name | default $.Release.Name }}
18+
{{- if .targetAllocatorEnabled }}
19+
namespace: {{ default $.Release.Namespace }}
20+
{{- else }}
1821
namespace: {{ .namespace | default $.Release.Namespace }}
19-
annotations:
22+
{{- end }}
23+
labels:
24+
meta.helm.sh/release-name: {{ $.Release.Name }}
25+
helm.sh/chart: {{ $.Chart.Version }}
2026
spec:
2127
resources:
2228
{{- toYaml .resources | nindent 8 }}
23-
mode: {{ .mode }}
29+
{{- if and .targetAllocatorEnabled (eq .mode "sidecar") }}
30+
mode: statefulset
31+
{{- else }}
32+
mode: {{ .mode }}
33+
{{- end}}
2434
{{- with .serviceAccount.name }}
2535
serviceAccount: {{ . }}
2636
{{- end }}
@@ -63,12 +73,27 @@ data:
6373
{{- toYaml $receiverCfg | nindent 12 }}
6474
{{- end }}
6575
{{- else}}
66-
{{- with .prometheusScrapeConfigs}}
67-
{{- $receivers = append $receivers "prometheus" }}
76+
{{- if or .targetAllocatorEnabled .prometheusScrapeConfigs }}
6877
prometheus:
6978
config:
7079
scrape_configs:
71-
{{- toYaml . | nindent 16 }}
80+
{{- $receivers = append $receivers "prometheus" }}
81+
{{- if .targetAllocatorEnabled }}
82+
- job_name: 'otel-collector'
83+
scrape_interval: 10s
84+
static_configs:
85+
- targets: [ '0.0.0.0:8888' ]
86+
metric_relabel_configs:
87+
- action: labeldrop
88+
regex: (id|name)
89+
- action: labelmap
90+
regex: label_(.+)
91+
replacement: $$1
92+
{{- else }}
93+
{{- with .prometheusScrapeConfigs }}
94+
{{- toYaml . | nindent 14 }}
95+
{{- end }}
96+
{{- end }}
7297
{{- end }}
7398
{{- end }}
7499
{{- $processors := list }}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{{- if (include "atLeastOneOperatorCr" $) -}}
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: delete-otc
6+
namespace: {{ default .Release.Namespace }}
7+
labels:
8+
app: delete-otc
9+
annotations:
10+
helm.sh/hook: pre-delete
11+
helm.sh/hook-weight: "-1"
12+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
13+
spec:
14+
ttlSecondsAfterFinished: 43200 # 12h
15+
backoffLimit: 4
16+
template:
17+
metadata:
18+
annotations:
19+
sidecar.istio.io/inject: "false"
20+
labels:
21+
app: delete-otc
22+
spec:
23+
restartPolicy: Never
24+
serviceAccountName: manipulate-otc
25+
securityContext:
26+
runAsUser: 1000
27+
runAsGroup: 2000
28+
{{- with .Values.kubectlImage.pullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
tolerations:
33+
- key: node-role.kubernetes.io/master
34+
effect: NoSchedule
35+
initContainers:
36+
- name: wait-crds
37+
image: "{{ .Values.kubectlImage.repository }}:{{ .Values.kubectlImage.tag }}"
38+
imagePullPolicy: {{ .Values.kubectlImage.pullPolicy }}
39+
command:
40+
- sh
41+
args:
42+
- -c
43+
- |
44+
set -o nounset
45+
for i in $(seq 20)
46+
do
47+
kubectl get crd opentelemetrycollectors.opentelemetry.io 2>&1 && exit 0
48+
_sec=$(echo "1.5^$i" | bc)
49+
echo "Waiting ${_sec} seconds for CRD opentelemetrycollectors.opentelemetry.io to exist"
50+
sleep ${_sec}
51+
done
52+
containers:
53+
- name: delete-otc
54+
image: "{{ .Values.kubectlImage.repository }}:{{ .Values.kubectlImage.tag }}"
55+
imagePullPolicy: {{ .Values.kubectlImage.pullPolicy }}
56+
securityContext:
57+
readOnlyRootFilesystem: true
58+
command:
59+
- sh
60+
args:
61+
- -c
62+
- |
63+
set -o nounset
64+
for i in $(seq 20)
65+
do
66+
kubectl delete otelcol -A -lmeta.helm.sh/release-name={{.Release.Name}},helm.sh/chart={{.Chart.Version}} 2>&1 && exit 0
67+
_sec=$(echo "1.5^$i" | bc)
68+
echo "Waiting ${_sec} seconds.."
69+
sleep ${_sec}
70+
done
71+
exit 1
72+
{{- end }}

helmchart/otel-add-on/templates/install-otc/otc-job.yaml renamed to helmchart/otel-add-on/templates/install-otc/otc-install-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
app: create-otc
2222
spec:
2323
restartPolicy: Never
24-
serviceAccountName: install-otc
24+
serviceAccountName: manipulate-otc
2525
securityContext:
2626
runAsUser: 1000
2727
runAsGroup: 2000

helmchart/otel-add-on/templates/install-otc/otc-job-rbac.yaml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
apiVersion: v1
44
kind: ServiceAccount
55
metadata:
6-
name: install-otc
6+
name: manipulate-otc
77
namespace: {{ .Release.Namespace }}
88
annotations:
9-
helm.sh/hook: "post-install,post-upgrade"
9+
helm.sh/hook: "post-install,post-upgrade,pre-delete"
1010
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
1111
helm.sh/hook-weight: "-2"
1212
---
1313
apiVersion: rbac.authorization.k8s.io/v1
1414
kind: ClusterRole
1515
metadata:
16-
name: install-otc
16+
name: manipulate-otc
1717
annotations:
18-
helm.sh/hook: "post-install,post-upgrade"
18+
helm.sh/hook: "post-install,post-upgrade,pre-delete"
1919
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
2020
helm.sh/hook-weight: "-2"
2121
rules:
@@ -24,9 +24,7 @@ rules:
2424
resources:
2525
- opentelemetrycollectors
2626
verbs:
27-
- patch
28-
- create
29-
- get
27+
- "*"
3028
- apiGroups:
3129
- apiextensions.k8s.io
3230
resources:
@@ -37,17 +35,17 @@ rules:
3735
apiVersion: rbac.authorization.k8s.io/v1
3836
kind: ClusterRoleBinding
3937
metadata:
40-
name: install-otc
38+
name: manipulate-otc
4139
annotations:
42-
helm.sh/hook: "post-install,post-upgrade"
40+
helm.sh/hook: "post-install,post-upgrade,pre-delete"
4341
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
4442
helm.sh/hook-weight: "-2"
4543
roleRef:
4644
apiGroup: rbac.authorization.k8s.io
4745
kind: ClusterRole
48-
name: install-otc
46+
name: manipulate-otc
4947
subjects:
5048
- kind: ServiceAccount
51-
name: install-otc
49+
name: manipulate-otc
5250
namespace: {{ .Release.Namespace }}
5351
{{- end }}

helmchart/otel-add-on/values.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#otel-add-on:
22
#------------
33
replicaCount: 1
4-
namespace: keda
4+
namespace: ""
55
## -- when rendering/installing/upgrading the helm chart, the schema validation trivially passes
66
#disableSchemaValidation: false
77

@@ -167,6 +167,7 @@ otelOperatorCrDefaultTemplate:
167167
- kube-prometheus-stack-prometheus
168168
targetAllocator:
169169
serviceAccount: otel-prom-reader
170+
enabled: true
170171
prometheusCR:
171172
enabled: true
172173
# -- further narrow the ServiceMonitor CRs
@@ -175,6 +176,8 @@ otelOperatorCrDefaultTemplate:
175176
# foo: bar
176177
# -- further narrow the ServiceMonitor CRs
177178
podMonitorSelector: {}
179+
allowNamespaces: []
180+
denyNamespaces: []
178181
serviceAccount:
179182
create: false
180183
annotations: {}
@@ -268,10 +271,8 @@ otelOperator:
268271
collectorImage:
269272
# repository: otel/opentelemetry-collector-k8s
270273
repository: otel/opentelemetry-collector-contrib
271-
env: {}
272-
extraEnvs:
273-
- name: ENABLE_WEBHOOKS
274-
value: "false"
274+
env:
275+
ENABLE_WEBHOOKS: "false"
275276
serviceAccount:
276277
name: otel-operator
277278

@@ -288,7 +289,6 @@ otelCollector:
288289
image:
289290
repository: otel/opentelemetry-collector-k8s
290291
fullnameOverride: otelcol
291-
292292
ports:
293293
opencensus:
294294
enabled: true

0 commit comments

Comments
 (0)