Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(chart): render whole-number env values without exponent notation
Yudhi Armyndharisf42210ab3d1b
diff --git a/charts/openwa/templates/_helpers.tpl b/charts/openwa/templates/_helpers.tplindex e5fa5a019..03fcb9116 100644--- a/charts/openwa/templates/_helpers.tpl+++ b/charts/openwa/templates/_helpers.tpl@@ -43,3 +43,16 @@ app.kubernetes.io/instance: {{ .Release.Name }}{{- include "openwa.fullname" . }}{{- end }}{{- end }}++{{/*+An env/secretEnv value as a quoted string. A values file hands an unquoted number to the template as+a float64, and `quote` prints one of a million or more in exponent form ("5.24288e+07"), which the app+rejects or misreads. Whole numbers are printed as integers; anything else is quoted as given.+*/}}+{{- define "openwa.envValue" -}}+{{- if and (kindIs "float64" .) (eq . (floor .)) -}}+{{- . | int64 | quote -}}+{{- else -}}+{{- . | quote -}}+{{- end -}}+{{- end }}diff --git a/charts/openwa/templates/configmap.yaml b/charts/openwa/templates/configmap.yamlindex c62728741..767c41c0e 100644--- a/charts/openwa/templates/configmap.yaml+++ b/charts/openwa/templates/configmap.yaml@@ -6,5 +6,5 @@ metadata:{{- include "openwa.labels" . | nindent 4 }}data:{{- range $key, $value := .Values.env }}- {{ $key }}: {{ $value | quote }}+ {{ $key }}: {{ include "openwa.envValue" $value }}{{- end }}diff --git a/charts/openwa/templates/secret.yaml b/charts/openwa/templates/secret.yamlindex 279f3db33..1e44c0a32 100644--- a/charts/openwa/templates/secret.yaml+++ b/charts/openwa/templates/secret.yaml@@ -8,6 +8,6 @@ metadata:type: OpaquestringData:{{- range $key, $value := .Values.secretEnv }}- {{ $key }}: {{ $value | quote }}+ {{ $key }}: {{ include "openwa.envValue" $value }}{{- end }}{{- end }}diff --git a/scripts/check-chart-behaviour.mjs b/scripts/check-chart-behaviour.mjsindex 6fbbcdd86..d9d1af0d0 100644--- a/scripts/check-chart-behaviour.mjs+++ b/scripts/check-chart-behaviour.mjs@@ -34,6 +34,14 @@ const render = (...setArgs) =>maxBuffer: 1 << 24,});+/** Render with `valuesYaml` as a values file (`-f -`), which parses numbers unlike `--set`. */+const renderValues = valuesYaml =>+ execFileSync('docker', ['run', '-i', '--rm', '-v', `${CHARTS}:/charts:ro`, HELM_IMAGE, 'template', 'ci', '/charts/openwa', '-f', '-'], {+ encoding: 'utf8',+ input: valuesYaml,+ maxBuffer: 1 << 24,+ });+const documents = out => out.split('\n---\n');const kindOf = doc => /^kind:\s*(\S+)/m.exec(doc)?.[1];const nameOf = doc => /^\s{2}name:\s*(\S+)/m.exec(doc)?.[1];@@ -166,6 +174,34 @@ const check = (id, ok, detail) => results.push({ id, ok, detail }););}+// A values file is parsed as YAML, so an unquoted number reaches the templates as a float64, and+// `quote` prints one of a million or more in exponent form. The app then reads "5.24288e+07" for a+// byte limit (and refuses to boot) or "1.2345678e+07" for a password. `--set` parses integers as+// int64, so the renders above never see it. Fractions and booleans must still pass through as written.+{+ const out = renderValues(+ 'env:\n MEDIA_DOWNLOAD_MAX_BYTES: 52428800\n CHECK_RATIO: 1.5\n CHECK_FLAG: true\n' ++ 'secretEnv:\n DATABASE_PASSWORD: 12345678\n',+ );+ const data = mapAt(byKind(out, 'ConfigMap')[0] ?? '', ['data']) ?? {};+ const secret = mapAt(byKind(out, 'Secret')[0] ?? '', ['stringData']) ?? {};+ const got = {+ MEDIA_DOWNLOAD_MAX_BYTES: data.MEDIA_DOWNLOAD_MAX_BYTES,+ CHECK_RATIO: data.CHECK_RATIO,+ CHECK_FLAG: data.CHECK_FLAG,+ DATABASE_PASSWORD: secret.DATABASE_PASSWORD,+ };+ const want = { MEDIA_DOWNLOAD_MAX_BYTES: '52428800', CHECK_RATIO: '1.5', CHECK_FLAG: 'true', DATABASE_PASSWORD: '12345678' };+ const wrong = Object.keys(want).filter(k => got[k] !== want[k]);+ check(+ 'values-file-numbers-render-as-written',+ wrong.length === 0,+ wrong.length+ ? `values-file entries rendered differently from how they were written: ${wrong.map(k => `${k}=${JSON.stringify(got[k])}`).join(', ')}`+ : 'unquoted numbers in a values file reach the ConfigMap and Secret as written',+ );+}+const failed = results.filter(r => !r.ok);if (failed.length) {console.error('\n✖ Chart behaviour check failed:');