Skip to content

Commit

Permalink
[TT-5906] Add a pre-hook to validate Dashboard license (#112)
Browse files Browse the repository at this point in the history
* add pre-install hook that verifies dashboard licenses

Signed-off-by: Burak Sekili <[email protected]>

* Add hook annotations to serviceaccounts and update command of job pod

Signed-off-by: Burak Sekili <[email protected]>

* Add temporary image registeries for bootstrap

Signed-off-by: Burak Sekili <[email protected]>

* change image repositories to official one

Signed-off-by: Burak Sekili <[email protected]>

---------

Signed-off-by: Burak Sekili <[email protected]>
Co-authored-by: andrei-tyk <[email protected]>
Co-authored-by: Pranshu <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2023
1 parent b90aa15 commit 6dc091f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ spec:
{{- end }}
- name: TYK_DB_LISTENPORT
value: "{{ .Values.global.servicePorts.dashboard }}"
- name: TYK_DB_LICENSEKEY
value: {{ .Values.global.license.dashboard | quote }}
- name: TYK_ADMIN_SECRET
{{- if not .Values.global.secrets.useSecretName }}
value: {{ .Values.global.secrets.AdminSecret | quote }}
Expand Down
40 changes: 40 additions & 0 deletions components/tyk-bootstrap/templates/bootstrap-pre-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if .Values.bootstrap.dashboard.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.bootstrap.jobs.bootstrapPreInstallJobName }}
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}

# Removed the use of appVersion since it's not accurate. We'll put it back in v1.0
# when every app will have its own a chart
# app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
backoffLimit: 1
template:
metadata:
annotations:
{{- if .Values.bootstrap.podAnnotations.preInstallPodAnnotations }}
{{ toYaml .Values.bootstrap.podAnnotations.preInstallPodAnnotations | nindent 8 }}
{{- end }}
spec:
serviceAccountName: k8s-bootstrap-role
containers:
- name: bootstrap-tyk-pre-install
image: tykio/tyk-k8s-bootstrap-pre-install:latest
command: ['/app/bin/bootstrap-app-pre-install']
imagePullPolicy: IfNotPresent
env:
- name: TYK_DB_LICENSEKEY
value: {{ .Values.global.license.dashboard | quote }}
restartPolicy: Never
terminationGracePeriodSeconds: 0
{{- end }}

4 changes: 4 additions & 0 deletions components/tyk-bootstrap/templates/bootstrap-role-binding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: k8s-bootstrap-role
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "-10"
subjects:
- kind: ServiceAccount
name: k8s-bootstrap-role
Expand Down
4 changes: 4 additions & 0 deletions components/tyk-bootstrap/templates/bootstrap-role.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: k8s-bootstrap-role
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "-10"
rules:
#
# Give here only the privileges you need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: k8s-bootstrap-role
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: before-hook-creation
helm.sh/hook-weight: "-10"
{{- end }}
4 changes: 2 additions & 2 deletions components/tyk-bootstrap/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ bootstrap:
jobs:
# Name of bootstrap job created when running the tyk-bootstrap chart. (needed for cleanup)
bootstrapJobName: bootstrap-post-install


bootstrapPreInstallJobName: bootstrap-pre-install

org:
# The name for your organization inside Tyk
Expand Down Expand Up @@ -99,5 +98,6 @@ bootstrap:
# key: value
# post: install
podAnnotations:
preInstallPodAnnotations: {}
postInstallPodAnnotations: {}
preDeletePodAnnotations: {}

0 comments on commit 6dc091f

Please sign in to comment.