This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable/minio] fix serviceMonitor authentication (#20896)
Signed-off-by: Bruno Clermont <[email protected]>
- Loading branch information
1 parent
59556e8
commit 5a8cfbe
Showing
7 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
stable/minio/templates/post-install-prometheus-metrics-job.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{{- if .Values.metrics.serviceMonitor.enabled }} | ||
{{- $fullName := include "minio.fullname" . -}} | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ $fullName }}-update-prometheus-secret | ||
labels: | ||
app: {{ template "minio.name" . }}-update-prometheus-secret | ||
chart: {{ template "minio.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
annotations: | ||
"helm.sh/hook": post-install,post-upgrade | ||
"helm.sh/hook-weight": "-5" | ||
"helm.sh/hook-delete-policy": hook-succeeded | ||
{{ toYaml .Values.updatePrometheusJob.annotations | indent 4 }} | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "minio.name" . }}-update-prometheus-secret | ||
release: {{ .Release.Name }} | ||
{{- if .Values.podLabels }} | ||
{{ toYaml .Values.podLabels | indent 8 }} | ||
{{- end }} | ||
spec: | ||
{{- if .Values.serviceAccount.create }} | ||
serviceAccountName: {{ $fullName }}-update-prometheus-secret | ||
{{- end }} | ||
restartPolicy: OnFailure | ||
{{- if .Values.nodeSelector }} | ||
nodeSelector: | ||
{{ toYaml .Values.nodeSelector | indent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{ toYaml . | indent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{ toYaml . | indent 8 }} | ||
{{- end }} | ||
volumes: | ||
- name: workdir | ||
emptyDir: {} | ||
initContainers: | ||
- name: minio-mc | ||
image: "{{ .Values.mcImage.repository }}:{{ .Values.mcImage.tag }}" | ||
imagePullPolicy: {{ .Values.mcImage.pullPolicy }} | ||
command: | ||
- /bin/sh | ||
- "-c" | ||
- mc admin prometheus generate target --json --no-color -q > /workdir/mc.json | ||
env: | ||
# mc admin prometheus generate don't really connect to remote server, TLS cert isn't required | ||
- name: MC_HOST_target | ||
value: http{{ if .Values.tls.enabled }}s{{ end }}://{{ .Values.accessKey }}:{{ .Values.secretKey }}@{{ $fullName }}:{{ .Values.service.port }} | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /workdir | ||
resources: | ||
{{ toYaml .Values.resources | indent 12 }} | ||
# extract bearerToken from mc admin output | ||
- name: jq | ||
image: "{{ .Values.helmKubectlJqImage.repository }}:{{ .Values.helmKubectlJqImage.tag }}" | ||
imagePullPolicy: {{ .Values.helmKubectlJqImage.pullPolicy }} | ||
command: | ||
- /bin/sh | ||
- "-c" | ||
- jq -e -c -j -r .bearerToken < /workdir/mc.json > /workdir/token | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /workdir | ||
resources: | ||
{{ toYaml .Values.resources | indent 12 }} | ||
- name: kubectl-create | ||
image: "{{ .Values.helmKubectlJqImage.repository }}:{{ .Values.helmKubectlJqImage.tag }}" | ||
imagePullPolicy: {{ .Values.helmKubectlJqImage.pullPolicy }} | ||
command: | ||
- /bin/sh | ||
- "-c" | ||
# The following script does: | ||
# - get the servicemonitor that need this secret and copy some metadata and create the ownerreference for the secret file | ||
# - create the secret | ||
# - merge both json | ||
- > | ||
kubectl -n {{ .Release.Namespace }} get servicemonitor {{ $fullName }} -o json | | ||
jq -c '{metadata: {name: "{{ $fullName }}-prometheus", namespace: .metadata.namespace, labels: {app: .metadata.labels.app, release: .metadata.labels.release}, ownerReferences: [{apiVersion: .apiVersion, kind: .kind, blockOwnerDeletion: true, controller: true, uid: .metadata.uid, name: .metadata.name}]}}' > /workdir/metadata.json && | ||
kubectl create secret generic {{ $fullName }}-prometheus --from-file=token=/workdir/token --dry-run -o json > /workdir/secret.json && | ||
cat /workdir/secret.json /workdir/metadata.json | jq -s add > /workdir/object.json | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /workdir | ||
resources: | ||
{{ toYaml .Values.resources | indent 12 }} | ||
containers: | ||
- name: kubectl-apply | ||
image: "{{ .Values.helmKubectlJqImage.repository }}:{{ .Values.helmKubectlJqImage.tag }}" | ||
imagePullPolicy: {{ .Values.helmKubectlJqImage.pullPolicy }} | ||
command: | ||
- kubectl | ||
- apply | ||
- "-f" | ||
- /workdir/object.json | ||
volumeMounts: | ||
- name: workdir | ||
mountPath: /workdir | ||
resources: | ||
{{ toYaml .Values.resources | indent 12 }} | ||
{{- end }} |
38 changes: 38 additions & 0 deletions
38
stable/minio/templates/post-install-prometheus-metrics-role.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{- if .Values.serviceAccount.create -}} | ||
{{- $fullName := include "minio.fullname" . -}} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ $fullName }}-update-prometheus-secret | ||
labels: | ||
app: {{ template "minio.name" . }}-update-prometheus-secret | ||
chart: {{ template "minio.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- secrets | ||
verbs: | ||
- get | ||
- create | ||
- update | ||
- patch | ||
resourceNames: | ||
- {{ $fullName }}-prometheus | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- secrets | ||
verbs: | ||
- create | ||
- apiGroups: | ||
- monitoring.coreos.com | ||
resources: | ||
- servicemonitors | ||
verbs: | ||
- get | ||
resourceNames: | ||
- {{ $fullName }} | ||
{{- end -}} |
20 changes: 20 additions & 0 deletions
20
stable/minio/templates/post-install-prometheus-metrics-rolebinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{- if .Values.serviceAccount.create -}} | ||
{{- $fullName := include "minio.fullname" . -}} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ $fullName }}-update-prometheus-secret | ||
labels: | ||
app: {{ template "minio.name" . }}-update-prometheus-secret | ||
chart: {{ template "minio.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: {{ $fullName }}-update-prometheus-secret | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ $fullName }}-update-prometheus-secret | ||
namespace: {{ .Release.Namespace }} | ||
{{- end -}} |
12 changes: 12 additions & 0 deletions
12
stable/minio/templates/post-install-prometheus-metrics-serviceaccount.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{- if .Values.serviceAccount.create -}} | ||
{{- $fullName := include "minio.fullname" . -}} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ $fullName }}-update-prometheus-secret | ||
labels: | ||
app: {{ template "minio.name" . }}-update-prometheus-secret | ||
chart: {{ template "minio.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters