Skip to content

Commit 0c7c393

Browse files
committed
refactor(postgres): drop null from tls.enabled schema, use kindIs invalid pattern
Remove the jq post-processing patch that widened tls.enabled type to ["boolean","null"] in values.schema.json and the openAPISchema embedded in the cozyrds CRD. Plain "type":"boolean" is emitted directly by cozyvalues-gen and is the correct form. The cozystack-api server unmarshals openAPISchema into apiextv1.JSONSchemaProps whose Type field is a single string; an array value silently zeros the field and disables server-side defaulting for the entire app. Tri-state semantics are preserved on the Helm template side via kindIs "invalid": omitting tls.enabled triggers the external-based fallback; null is no longer a valid input and is rejected by the schema. Remove two helm-unittest cases that injected tls.enabled: null (now intentionally rejected) and update the suite comment to match. Signed-off-by: Arsolitt <[email protected]>
1 parent 272c417 commit 0c7c393

4 files changed

Lines changed: 13 additions & 45 deletions

File tree

‎packages/apps/postgres/Makefile‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ include ../../../hack/package.mk
22

33
generate:
44
cozyvalues-gen -m 'postgresql' -v values.yaml -s values.schema.json -r README.md -g ../../../api/apps/v1alpha1/postgresql/types.go
5-
# Patch tls.enabled to be nullable (cozyvalues-gen emits "type": "boolean" only;
6-
# we need ["boolean","null"] for the tri-state).
7-
jq -e '.properties.tls.properties.enabled.type == "boolean"' values.schema.json > /dev/null || (echo "ERROR: expected cozyvalues-gen to emit tls.enabled.type as \"boolean\" before patching — output may have drifted" && exit 1)
8-
jq '.properties.tls.properties.enabled.type = ["boolean", "null"]' values.schema.json > values.schema.json.tmp && mv values.schema.json.tmp values.schema.json
9-
jq -e '.properties.tls.properties.enabled.type == ["boolean", "null"]' values.schema.json > /dev/null || (echo "ERROR: jq patch for tls.enabled.type failed — cozyvalues-gen output may have drifted" && exit 1)
105
../../../hack/update-crd.sh
116

127
update:

‎packages/apps/postgres/tests/tls_test.yaml‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
suite: postgres TLS configuration
22

3-
# Covers the tri-state tls.enabled field for the operator-managed CNPG TLS mode:
4-
# - external: false, tls.enabled unset → TLS off (default)
5-
# - external: true, tls.enabled unset → TLS auto-on
6-
# - tls.enabled: true (explicit) → TLS on regardless of external
7-
# - tls.enabled: false (explicit) → TLS off regardless of external
3+
# Covers the tri-state tls.enabled field for the operator-managed CNPG TLS mode.
4+
# tls.enabled is a plain boolean; null is NOT a valid input form (schema rejects it).
5+
# Omitting tls.enabled entirely triggers kindIs "invalid" → auto-on when external=true.
6+
#
7+
# - external: false, tls.enabled omitted → TLS off (default)
8+
# - external: true, tls.enabled omitted → TLS auto-on
9+
# - tls.enabled: true (explicit) → TLS on regardless of external
10+
# - tls.enabled: false (explicit) → TLS off regardless of external
811
#
912
# In TLS-on mode the chart sets spec.certificates with serverAltDNSNames so the
1013
# operator's own CA signs server certs. CNPG auto-derives SANs for the three
@@ -101,30 +104,3 @@ tests:
101104
path: spec.certificates.serverAltDNSNames
102105
count: 1
103106

104-
- it: Cluster has no spec.certificates when tls.enabled null and external false
105-
set:
106-
tls:
107-
enabled: null
108-
documentSelector:
109-
path: kind
110-
value: Cluster
111-
asserts:
112-
- isNull:
113-
path: spec.certificates
114-
115-
- it: Cluster has spec.certificates when tls.enabled null and external true
116-
set:
117-
tls:
118-
enabled: null
119-
external: true
120-
_namespace:
121-
host: example.cozy.local
122-
documentSelector:
123-
path: kind
124-
value: Cluster
125-
asserts:
126-
- exists:
127-
path: spec.certificates
128-
- contains:
129-
path: spec.certificates.serverAltDNSNames
130-
content: pg-test.example.cozy.local

‎packages/apps/postgres/values.schema.json‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@
131131
"properties": {
132132
"enabled": {
133133
"description": "Tri-state switch controlling whether the chart injects the external hostname into the operator-managed CNPG cert via spec.certificates.serverAltDNSNames. When omitted (null), the chart injects the SAN if `external: true` and skips it otherwise. Set explicitly to `true` to inject regardless of `external` (no-op when `external: false` since there is no external hostname to add). Set to `false` to skip injection. Note that CNPG keeps its built-in TLS on the wire regardless of this flag — this toggle only controls the chart-side SAN injection; to disable PostgreSQL TLS entirely set `postgresql.parameters.ssl = \"off\"` at the CNPG layer.",
134-
"type": [
135-
"boolean",
136-
"null"
137-
]
134+
"type": "boolean"
138135
}
139136
}
140137
},
@@ -300,7 +297,7 @@
300297
"s3AccessKey": {
301298
"description": "Access key for S3 authentication. Ignored when `s3CredentialsSecret.name` is set.",
302299
"type": "string",
303-
"default": "<your-access-key>"
300+
"default": "\u003cyour-access-key\u003e"
304301
},
305302
"s3CredentialsSecret": {
306303
"description": "Pre-existing Secret with S3 credentials. When set, the chart references this Secret directly instead of materialising one from `s3AccessKey`/`s3SecretKey`. The CNPG backup driver writes this field on restore so credentials never land in the CR `.spec`.",
@@ -313,7 +310,7 @@
313310
"default": ""
314311
},
315312
"name": {
316-
"description": "Name of the Secret in the application namespace. Empty means the chart materialises `<release>-s3-creds` from `s3AccessKey`/`s3SecretKey`.",
313+
"description": "Name of the Secret in the application namespace. Empty means the chart materialises `\u003crelease\u003e-s3-creds` from `s3AccessKey`/`s3SecretKey`.",
317314
"type": "string",
318315
"default": ""
319316
},
@@ -327,7 +324,7 @@
327324
"s3SecretKey": {
328325
"description": "Secret key for S3 authentication. Ignored when `s3CredentialsSecret.name` is set.",
329326
"type": "string",
330-
"default": "<your-secret-key>"
327+
"default": "\u003cyour-secret-key\u003e"
331328
},
332329
"schedule": {
333330
"description": "Legacy. Cron schedule (CNPG 6-field format) for the chart-emitted ScheduledBackup. Empty means no chart-managed schedule, which is the recommended setup when a `BackupClass` from `backups.cozystack.io` already drives backup orchestration. The chart still emits `spec.backup.barmanObjectStore` whenever `backup.enabled=true`, so `archive_command` runs and the BackupClass driver can take ad-hoc / Plan-driven backups against a live WAL archive.",

0 commit comments

Comments
 (0)