Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

[kibana] Fix helm pre-upgrade and pre-install hooks #1781

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions kibana/templates/configmap-helm-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade,post-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down Expand Up @@ -114,31 +114,35 @@ data:
console.log('Cleaning previous token');
// 404 status code is accepted if there is no previous token to clean
return requestPromise(esUrl, esTokenDeleteOptions, {extraStatusCode: 404}).then(() => {
console.log('Creating new token');
return requestPromise(esUrl, esTokenCreateOptions).then(response => {
const body = JSON.parse(response);
const token = body.token.value

// Encode the token in base64
const base64Token = Buffer.from(token, 'utf8').toString('base64');

// Prepare the k8s secret
const secretData = JSON.stringify({
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"namespace": "{{ .Release.Namespace }}",
"name": "{{ template "kibana.fullname" . }}-es-token",
},
"type": "Opaque",
"data": {
"token": base64Token,
}
})

// Create the k8s secret
console.log('Creating K8S secret');
return requestPromise(k8sPostSecretUrl, secretCreateOptions, {payload: secretData})
console.log('Deleting previous K8S secret');
// 404 status code is accepted if there is no previous k8s secret to delete
return requestPromise(k8sDeleteSecretUrl, secretDeleteOptions, {extraStatusCode: 404}).then(() => {
console.log('Creating new token');
return requestPromise(esUrl, esTokenCreateOptions).then(response => {
const body = JSON.parse(response);
const token = body.token.value

// Encode the token in base64
const base64Token = Buffer.from(token, 'utf8').toString('base64');

// Prepare the k8s secret
const secretData = JSON.stringify({
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"namespace": "{{ .Release.Namespace }}",
"name": "{{ template "kibana.fullname" . }}-es-token",
},
"type": "Opaque",
"data": {
"token": base64Token,
}
})

// Create the k8s secret
console.log('Creating K8S secret');
return requestPromise(k8sPostSecretUrl, secretCreateOptions, {payload: secretData})
});
});
});
}
Expand All @@ -147,7 +151,7 @@ data:
// Chaining requests
console.log('Cleaning token');
return requestPromise(esUrl, esTokenDeleteOptions).then(() => {
// Create the k8s secret
// Delete the k8s secret
console.log('Delete K8S secret');
return requestPromise(k8sDeleteSecretUrl, secretDeleteOptions)
});
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/post-delete-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/post-delete-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/post-delete-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/post-delete-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/pre-install-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
3 changes: 2 additions & 1 deletion kibana/templates/pre-install-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand All @@ -19,3 +19,4 @@ rules:
verbs:
- create
- update
- delete
2 changes: 1 addition & 1 deletion kibana/templates/pre-install-rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion kibana/templates/pre-install-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels: {{ include "kibana.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
{{- if .Values.annotations }}
{{- range $key, $value := .Values.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down