Skip to content

Commit 212f0c9

Browse files
feat: Add queryables configuration support in pgstac bootstrap (#323)
Co-authored-by: xıʃǝɟ <felix@developmentseed.org>
1 parent 1f7842d commit 212f0c9

File tree

7 files changed

+166
-1
lines changed

7 files changed

+166
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
12+
- Add queryables configuration support using pypgstac load-queryables [#323](https://github.com/developmentseed/eoapi-k8s/pull/323)
1113
- Added local testing with k3s and minikube
1214
- Base local development values file (`local-base-values.yaml`)
1315
- Unified local cluster management with `CLUSTER_TYPE` variable

charts/eoapi/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ annotations:
3939
# This is the chart version. This version number should be incremented each time you make changes
4040
# to the chart and its templates, including the app version.
4141
# Versions are expected to follow Semantic Versioning (https://semver.org/)
42-
version: "0.7.12"
42+
version: "0.8.0"
4343

4444
# This is the version number of the application being deployed. This version number should be
4545
# incremented each time you make changes to the application. Versions are not expected to
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "https://stac-extensions.github.io/item-search/v1.0.0/schema.json",
4+
"title": "Test Queryables",
5+
"description": "Test queryables for eoapi",
6+
"type": "object",
7+
"properties": {
8+
"eo:cloud_cover": {
9+
"description": "Estimate of cloud cover as a percentage (0-100) of the entire scene",
10+
"type": "number",
11+
"title": "Cloud Cover",
12+
"minimum": 0,
13+
"maximum": 100
14+
},
15+
"view:sun_azimuth": {
16+
"description": "Sun azimuth angle in degrees",
17+
"type": "number",
18+
"title": "Sun Azimuth",
19+
"minimum": 0,
20+
"maximum": 360
21+
},
22+
"view:sun_elevation": {
23+
"description": "Sun elevation angle in degrees",
24+
"type": "number",
25+
"title": "Sun Elevation",
26+
"minimum": -90,
27+
"maximum": 90
28+
},
29+
"platform": {
30+
"description": "Platform or satellite name",
31+
"type": "string",
32+
"title": "Platform"
33+
},
34+
"instruments": {
35+
"description": "Instrument(s) used",
36+
"type": "array",
37+
"title": "Instruments",
38+
"items": {
39+
"type": "string"
40+
}
41+
}
42+
},
43+
"additionalProperties": true
44+
}

charts/eoapi/local-base-values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ database:
1414
pgstacBootstrap:
1515
enabled: true
1616
settings:
17+
# Queryables configuration for testing
18+
queryables:
19+
- file: "initdb-data/queryables/test-queryables.json"
20+
indexFields: ["platform", "instruments"]
21+
deleteMissing: true
1722
resources:
1823
requests:
1924
cpu: "256m"

charts/eoapi/templates/pgstacbootstrap/configmap.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ data:
4646
{{- base $path | nindent 2 -}}: | {{- $.Files.Get $path | nindent 4 -}}
4747
{{- end }}
4848
{{- end }}
49+
---
50+
{{- if .Values.pgstacBootstrap.settings.queryables }}
51+
apiVersion: v1
52+
kind: ConfigMap
53+
metadata:
54+
name: {{ $.Release.Name }}-pgstac-queryables-config
55+
annotations:
56+
helm.sh/hook: "post-install,post-upgrade"
57+
helm.sh/hook-weight: "-7"
58+
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
59+
data:
60+
{{- range $config := .Values.pgstacBootstrap.settings.queryables }}
61+
{{- $filename := splitList "/" $config.file | last }}
62+
{{ $filename }}: |
63+
{{- $.Files.Get $config.file | nindent 4 }}
64+
{{- end }}
65+
{{- end }}
4966
{{- end }}
5067
---
5168
{{- if .Values.postgrescluster.enabled }}

charts/eoapi/templates/pgstacbootstrap/job.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,86 @@ spec:
156156
{{- end }}
157157
backoffLimit: 3
158158
{{- end }}
159+
160+
{{- if and .Values.pgstacBootstrap.enabled .Values.pgstacBootstrap.settings.queryables }}
161+
---
162+
apiVersion: batch/v1
163+
kind: Job
164+
metadata:
165+
name: {{ .Release.Name }}-pgstac-load-queryables
166+
labels:
167+
app: {{ .Release.Name }}-pgstac-load-queryables
168+
annotations:
169+
helm.sh/hook: "post-install,post-upgrade"
170+
helm.sh/hook-weight: "-3"
171+
helm.sh/hook-delete-policy: "before-hook-creation"
172+
spec:
173+
template:
174+
metadata:
175+
labels:
176+
app: {{ .Release.Name }}-pgstac-load-queryables
177+
spec:
178+
restartPolicy: Never
179+
containers:
180+
- name: pgstac-load-queryables
181+
image: {{ .Values.pgstacBootstrap.image.name }}:{{ .Values.pgstacBootstrap.image.tag }}
182+
command:
183+
- "/bin/sh"
184+
- "-c"
185+
args:
186+
- |
187+
# Exit immediately if a command exits with a non-zero status
188+
set -e
189+
190+
# Database connection configured through standard PG* environment variables
191+
# Environment variables are already set by the container
192+
193+
# Wait for the database to be ready
194+
echo "Waiting for database to be ready..."
195+
pypgstac pgready
196+
197+
# Load queryables configurations
198+
echo "Loading queryables configurations..."
199+
{{- range $idx, $config := .Values.pgstacBootstrap.settings.queryables }}
200+
{{- $filename := splitList "/" $config.file | last }}
201+
echo "Processing queryables file: {{ $filename }}"
202+
pypgstac load-queryables \
203+
{{- if $config.deleteMissing }}
204+
--delete-missing \
205+
{{- end }}
206+
{{- if $config.collections }}
207+
# Complex escaping needed due to multiple interpretation layers:
208+
# 1. Helm processes the template: \\\" becomes \" in the rendered YAML
209+
# 2. YAML processes the string: \" becomes " in the shell script
210+
# 3. Shell receives: --collection-ids '["collection1","collection2"]'
211+
# 4. pypgstac gets a proper JSON array string as expected
212+
--collection-ids "[\\\"{{ join "\\\",\\\"" $config.collections }}\\\"]" \
213+
{{- end }}
214+
{{- if $config.indexFields }}
215+
--index-fields {{ join "," $config.indexFields }} \
216+
{{- end }}
217+
"/opt/queryables/{{ $filename }}"
218+
{{- end }}
219+
220+
echo "Queryables loading complete"
221+
resources:
222+
{{- toYaml .Values.pgstacBootstrap.settings.resources | nindent 12 }}
223+
volumeMounts:
224+
- mountPath: /opt/queryables
225+
name: {{ .Release.Name }}-queryables-volume
226+
env:
227+
{{- include "eoapi.postgresqlEnv" . | nindent 12 }}
228+
volumes:
229+
- name: {{ .Release.Name }}-queryables-volume
230+
configMap:
231+
name: {{ .Release.Name }}-pgstac-queryables-config
232+
{{- with .Values.pgstacBootstrap.settings.affinity }}
233+
affinity:
234+
{{- toYaml . | nindent 8 }}
235+
{{- end }}
236+
{{- with .Values.pgstacBootstrap.settings.tolerations }}
237+
tolerations:
238+
{{- toYaml . | nindent 8 }}
239+
{{- end }}
240+
backoffLimit: 3
241+
{{- end }}

charts/eoapi/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ pgstacBootstrap:
163163
# General configuration options
164164
loadSamples: true # Set to false to disable sample data loading
165165

166+
# Queryables configuration
167+
# List of queryables configurations to load using pypgstac load-queryables
168+
# Each item specifies a file path and optional parameters
169+
# Example:
170+
# queryables:
171+
# - file: "initdb-data/queryables/common-queryables.json"
172+
# indexFields: ["platform", "instruments"]
173+
# deleteMissing: true
174+
# - file: "initdb-data/queryables/collection-specific.json"
175+
# collections: ["my-collection-1", "my-collection-2"]
176+
# indexFields: ["custom:field1", "custom:field2"]
177+
# deleteMissing: true
178+
queryables: []
179+
166180
# Wait configuration for init containers waiting for pgstac jobs
167181
# These parameters control how long services wait for pgstac migration jobs to complete
168182
waitConfig:

0 commit comments

Comments
 (0)