Skip to content

Commit

Permalink
User pre-upgrade hook instead ttlSecondsAfterFinished (#407)
Browse files Browse the repository at this point in the history
* Change ttlSecondsAfterFinished with pre-upgrade hook

* chore: Update service account permissions for service-manager role
  • Loading branch information
raikbitters authored Jul 26, 2024
1 parent d370972 commit 4c94b32
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
8 changes: 6 additions & 2 deletions reportportal/templates/authorization/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "reportportal.fullname" . }}-service-reader
name: {{ include "reportportal.fullname" . }}-service-manager
namespace: {{ .Release.Namespace }}
rules:
{{- if .Values.rbac.rules }}
{{- toYaml .Values.rbac.rules | nindent 4 }}
{{- else }}
# Allow the service account to get and list pods, services, and jobs
- apiGroups: ["", "batch"]
resources: ["pods","services", "jobs"]
verbs: ["get", "list", "watch"]
# Allow the service account to delete jobs
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["delete"]
{{- end}}

{{- end }}
16 changes: 8 additions & 8 deletions reportportal/templates/authorization/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "reportportal.fullname" . }}-user-binding
namespace: {{ .Release.Namespace }}
name: {{ include "reportportal.fullname" . }}-user-binding
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "reportportal.fullname" . }}-service-reader
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "reportportal.fullname" . }}-service-manager
subjects:
- kind: ServiceAccount
name: {{ template "reportportal.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
- kind: ServiceAccount
name: {{ template "reportportal.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
28 changes: 28 additions & 0 deletions reportportal/templates/hooks/pre-upgrade-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "reportportal.fullname" . }}-pre-upgrade-delete-job
labels:
{{ include "labels" . | indent 4 }}
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
labels:
{{- range $key, $value := .Values.migrations.podLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
component: {{ include "reportportal.fullname" . }}-pre-upgrade-delete-job
spec:
serviceAccountName: {{ template "reportportal.serviceAccountName" . }}
restartPolicy: OnFailure
containers:
- name: delete-job
image: bitnami/kubectl:latest
command:
- /bin/sh
- -c
- |
kubectl delete job {{ include "reportportal.fullname" . }}-migrations --ignore-not-found=true
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
name: {{ include "reportportal.fullname" . }}-migrations
labels: {{ include "labels" . | indent 4 }}
spec:
ttlSecondsAfterFinished: {{ .Values.migrations.ttlSecondsAfterFinished }}
template:
metadata:
labels:
Expand Down
1 change: 0 additions & 1 deletion reportportal/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ migrations:
cpu: 100m
memory: 128Mi
pullPolicy: Always
ttlSecondsAfterFinished: 600
podLabels: {}
podAnnotations: {}
securityContext: {}
Expand Down

0 comments on commit 4c94b32

Please sign in to comment.