From 18428a3cd6c6566e08de7baa2c2da3071240fd52 Mon Sep 17 00:00:00 2001 From: James Gregory Date: Tue, 17 Sep 2024 15:43:06 +1000 Subject: [PATCH] feat: template uri secret --- charts/openfga/templates/_helpers.tpl | 16 ++++++++++++++++ charts/openfga/templates/deployment.yaml | 11 +---------- charts/openfga/templates/job.yaml | 11 +---------- charts/openfga/values.schema.json | 10 +++++++++- charts/openfga/values.yaml | 1 + 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/charts/openfga/templates/_helpers.tpl b/charts/openfga/templates/_helpers.tpl index 6abf573..0e3ec20 100644 --- a/charts/openfga/templates/_helpers.tpl +++ b/charts/openfga/templates/_helpers.tpl @@ -77,3 +77,19 @@ Return true if a secret object should be created {{- true -}} {{- end -}} {{- end -}} + +{{/* +Generate an environment variable for the datastore URI +*/}} +{{- define "openfga.datastoreURIEnvVar" -}} +{{- if .Values.datastore.uri -}} +- name: OPENFGA_DATASTORE_URI + value: "{{ .Values.datastore.uri }}" +{{- else if .Values.datastore.uriSecret -}} +- name: OPENFGA_DATASTORE_URI + valueFrom: + secretKeyRef: + name: "{{ tpl .Values.datastore.uriSecret . }}" + key: "{{ tpl (.Values.datastore.uriSecretKey | default "uri") . }}" +{{- end -}} +{{- end -}} diff --git a/charts/openfga/templates/deployment.yaml b/charts/openfga/templates/deployment.yaml index 5af7dfb..7445bd7 100644 --- a/charts/openfga/templates/deployment.yaml +++ b/charts/openfga/templates/deployment.yaml @@ -85,16 +85,7 @@ spec: value: "{{ .Values.datastore.engine }}" {{- end }} - {{- if .Values.datastore.uri }} - - name: OPENFGA_DATASTORE_URI - value: "{{ .Values.datastore.uri }}" - {{- else if .Values.datastore.uriSecret }} - - name: OPENFGA_DATASTORE_URI - valueFrom: - secretKeyRef: - name: "{{ .Values.datastore.uriSecret }}" - key: "uri" - {{- end }} + {{- include "openfga.datastoreURIEnvVar" . | nindent 12 }} {{- if .Values.datastore.maxCacheSize }} - name: OPENFGA_DATASTORE_MAX_CACHE_SIZE diff --git a/charts/openfga/templates/job.yaml b/charts/openfga/templates/job.yaml index 3ec2595..d699b62 100644 --- a/charts/openfga/templates/job.yaml +++ b/charts/openfga/templates/job.yaml @@ -41,16 +41,7 @@ spec: value: "{{ .Values.datastore.engine }}" {{- end }} - {{- if .Values.datastore.uri }} - - name: OPENFGA_DATASTORE_URI - value: "{{ .Values.datastore.uri }}" - {{- else if .Values.datastore.uriSecret }} - - name: OPENFGA_DATASTORE_URI - valueFrom: - secretKeyRef: - name: "{{ .Values.datastore.uriSecret }}" - key: "uri" - {{- end }} + {{- include "openfga.datastoreURIEnvVar" . | nindent 12 }} {{- if .Values.migrate.timeout }} - name: OPENFGA_TIMEOUT diff --git a/charts/openfga/values.schema.json b/charts/openfga/values.schema.json index d002147..6b3c8d5 100644 --- a/charts/openfga/values.schema.json +++ b/charts/openfga/values.schema.json @@ -278,7 +278,15 @@ "string", "null" ], - "description": "the secret name where to get the datastore URI, it expects a key named uri to exist in the secret" + "description": "the secret name where to get the datastore URI, it expects the key in `uriSecretKey` to exist in the secret" + }, + "uriSecretKey": { + "type": [ + "string", + "null" + ], + "default": "uri", + "description": "the key in the secret where to get the datastore URI, defaults to uri" }, "maxCacheSize": { "type": [ diff --git a/charts/openfga/values.yaml b/charts/openfga/values.yaml index 686a1eb..b651d44 100644 --- a/charts/openfga/values.yaml +++ b/charts/openfga/values.yaml @@ -190,6 +190,7 @@ datastore: engine: memory uri: uriSecret: + uriSecretKey: maxCacheSize: maxOpenConns: maxIdleConns: