Skip to content

Commit f3d43ce

Browse files
committed
Add redis as an option in the chart
1 parent faf5b0c commit f3d43ce

File tree

8 files changed

+160
-11
lines changed

8 files changed

+160
-11
lines changed

.github/actions/setup-helm-repos/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ runs:
99
run: |
1010
helm repo add elasticsearch https://helm.elastic.co
1111
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
12+
helm repo add bitnami https://charts.bitnami.com/bitnami
1213
helm repo update

helm-chart/stac-fastapi/Chart.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ dependencies:
3030
version: 3.2.1
3131
repository: https://opensearch-project.github.io/helm-charts/
3232
condition: opensearch.enabled
33+
- name: redis
34+
version: 19.6.2
35+
repository: https://charts.bitnami.com/bitnami
36+
condition: redis.enabled

helm-chart/stac-fastapi/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ The chart provides a flexible deployment solution for STAC FastAPI with the foll
2020

2121
## Quick Start
2222

23+
### Add Helm repositories
24+
25+
```bash
26+
helm repo add elasticsearch https://helm.elastic.co
27+
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
28+
helm repo add bitnami https://charts.bitnami.com/bitnami
29+
helm repo update
30+
```
31+
2332
### Deploy with Elasticsearch
2433

2534
```bash
26-
# Add dependencies
35+
# Download chart dependencies
2736
helm dependency update ./helm-chart/stac-fastapi
2837

2938
# Install with Elasticsearch backend
@@ -36,7 +45,7 @@ helm install my-stac-api ./helm-chart/stac-fastapi \
3645
### Deploy with OpenSearch
3746

3847
```bash
39-
# Add dependencies
48+
# Download chart dependencies
4049
helm dependency update ./helm-chart/stac-fastapi
4150

4251
# Install with OpenSearch backend

helm-chart/stac-fastapi/templates/_helpers.tpl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,48 @@ Create the database port based on backend selection
165165
{{- end }}
166166
{{- end }}
167167

168+
{{/*
169+
Determine the Redis service name when the bundled chart is enabled
170+
*/}}
171+
{{- define "stac-fastapi.redisServiceName" -}}
172+
{{- if .Values.redis.fullnameOverride }}
173+
{{- printf "%s-master" .Values.redis.fullnameOverride }}
174+
{{- else }}
175+
{{- printf "%s-redis-master" .Release.Name }}
176+
{{- end }}
177+
{{- end }}
178+
179+
{{/*
180+
Compute the Redis host, preferring the bundled deployment when enabled
181+
*/}}
182+
{{- define "stac-fastapi.redisHost" -}}
183+
{{- if and (.Values.redis.enabled) (not (and .Values.redis.external .Values.redis.external.enabled)) -}}
184+
{{- $service := include "stac-fastapi.redisServiceName" . | trim -}}
185+
{{- $namespace := .Release.Namespace | default "default" -}}
186+
{{- $clusterDomain := default "cluster.local" .Values.global.clusterDomain -}}
187+
{{- printf "%s.%s.svc.%s" $service $namespace $clusterDomain -}}
188+
{{- else if and .Values.redis.external .Values.redis.external.enabled -}}
189+
{{- .Values.redis.external.host | default "" -}}
190+
{{- else -}}
191+
{{- "" -}}
192+
{{- end }}
193+
{{- end }}
194+
195+
{{/*
196+
Resolve the Redis port based on the active configuration
197+
*/}}
198+
{{- define "stac-fastapi.redisPort" -}}
199+
{{- if and (.Values.redis.enabled) (not (and .Values.redis.external .Values.redis.external.enabled)) -}}
200+
{{- $ports := default (dict) (dig "master" "service" "ports" (dict) .Values.redis) -}}
201+
{{- $port := default 6379 (index $ports "redis") -}}
202+
{{- $port -}}
203+
{{- else if and .Values.redis.external .Values.redis.external.enabled -}}
204+
{{- .Values.redis.external.port | default 6379 -}}
205+
{{- else -}}
206+
{{- 6379 -}}
207+
{{- end }}
208+
{{- end }}
209+
168210
{{/*
169211
Create the image repository with tag
170212
*/}}
@@ -186,6 +228,9 @@ Create environment variables for the application
186228
{{- $envFromSecret := default (dict) .Values.app.envFromSecret -}}
187229
{{- $dbAuth := deepCopy (default (dict) .Values.app.databaseAuth) -}}
188230
{{- $opensearchSecurity := default (dict) .Values.opensearchSecurity -}}
231+
{{- $redisConfig := default (dict) .Values.redis -}}
232+
{{- $redisExternal := default (dict) (get $redisConfig "external") -}}
233+
{{- $redisEnabled := or ($redisConfig.enabled) (and $redisExternal ($redisExternal.enabled)) -}}
189234
{{- if and (eq .Values.backend "opensearch") (get $opensearchSecurity "generateAdminPassword") }}
190235
{{- $secretName := include "stac-fastapi.opensearchAdminSecretName" . -}}
191236
{{- if or (not (hasKey $dbAuth "existingSecret")) (not $dbAuth.existingSecret) }}

helm-chart/stac-fastapi/values-elasticsearch.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ app:
6464
STAC_FASTAPI_DESCRIPTION: "High-performance STAC API for geospatial data discovery"
6565
ENVIRONMENT: "production"
6666
WEB_CONCURRENCY: "4"
67-
ENABLE_DIRECT_RESPONSE: "true" # Enable for maximum performance
67+
ENABLE_DIRECT_RESPONSE: "false"
6868
DATABASE_REFRESH: "false" # Better performance for bulk operations
6969
ENABLE_DATETIME_INDEX_FILTERING: "true" # Enable for large datasets
7070
DATETIME_INDEX_MAX_SIZE_GB: "50"
@@ -130,6 +130,25 @@ opensearch:
130130
externalDatabase:
131131
enabled: false
132132

133+
# Redis cache configuration for API response caching
134+
redis:
135+
enabled: true
136+
architecture: standalone
137+
database: 0
138+
master:
139+
persistence:
140+
enabled: true
141+
size: 8Gi
142+
resources:
143+
requests:
144+
cpu: 100m
145+
memory: 256Mi
146+
limits:
147+
cpu: 500m
148+
memory: 512Mi
149+
auth:
150+
enabled: false
151+
133152
# Monitoring configuration
134153
monitoring:
135154
enabled: true

helm-chart/stac-fastapi/values-opensearch.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ app:
6464
STAC_FASTAPI_DESCRIPTION: "High-performance STAC API for geospatial data discovery with OpenSearch"
6565
ENVIRONMENT: "production"
6666
WEB_CONCURRENCY: "4"
67-
ENABLE_DIRECT_RESPONSE: "true" # Enable for maximum performance
67+
ENABLE_DIRECT_RESPONSE: "false"
6868
DATABASE_REFRESH: "false" # Better performance for bulk operations
6969
ENABLE_DATETIME_INDEX_FILTERING: "true" # Enable for large datasets
7070
DATETIME_INDEX_MAX_SIZE_GB: "50"
@@ -75,7 +75,7 @@ app:
7575
# Optional: pull connection credentials from a secret managed by the
7676
# OpenSearch chart (or provide plain values via username/password).
7777
databaseAuth:
78-
existingSecret: ""
78+
existingSecret: "stac-opensearch-admin"
7979
usernameKey: "username"
8080
passwordKey: "password"
8181

@@ -165,6 +165,25 @@ opensearch:
165165
externalDatabase:
166166
enabled: false
167167

168+
# Redis cache configuration for API response caching
169+
redis:
170+
enabled: true
171+
architecture: standalone
172+
database: 0
173+
master:
174+
persistence:
175+
enabled: true
176+
size: 8Gi
177+
resources:
178+
requests:
179+
cpu: 100m
180+
memory: 256Mi
181+
limits:
182+
cpu: 500m
183+
memory: 512Mi
184+
auth:
185+
enabled: false
186+
168187
# Monitoring configuration
169188
monitoring:
170189
enabled: true

helm-chart/stac-fastapi/values.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,33 @@ externalDatabase:
358358
# API key field in the secret
359359
apiKeySecretKey: "api-key"
360360

361+
# Redis cache configuration
362+
redis:
363+
# Deploy an in-cluster Redis when enabled
364+
enabled: false
365+
# Optional override for the generated Redis fullname
366+
fullnameOverride: ""
367+
# Default Redis database index used by the application
368+
database: 0
369+
architecture: standalone
370+
master:
371+
service:
372+
ports:
373+
redis: 6379
374+
auth:
375+
enabled: false
376+
# Provide an existing secret containing the Redis password when auth is enabled
377+
existingSecret: ""
378+
existingSecretPasswordKey: "redis-password"
379+
# Configure connection details for an externally managed Redis instance
380+
external:
381+
enabled: false
382+
host: ""
383+
port: 6379
384+
# Optional secret that stores the Redis password for the external instance
385+
passwordSecret: ""
386+
passwordKey: "redis-password"
387+
361388
# Configuration for monitoring and observability
362389
monitoring:
363390
# Enable monitoring

helm-chart/test-chart.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ maybe_collect_backend_logs() {
9595
fi
9696
}
9797

98+
ensure_helm_repo() {
99+
local name="$1"
100+
local url="$2"
101+
102+
local existing_repos
103+
existing_repos=$(helm repo list 2>/dev/null | awk 'NR>1 {print $1}' || true)
104+
105+
if ! grep -qx "$name" <<<"$existing_repos"; then
106+
log_info "Adding Helm repository: $name ($url)"
107+
helm repo add "$name" "$url"
108+
fi
109+
}
110+
111+
ensure_chart_dependencies() {
112+
log_info "Ensuring required Helm repositories are configured..."
113+
ensure_helm_repo elasticsearch https://helm.elastic.co
114+
ensure_helm_repo opensearch https://opensearch-project.github.io/helm-charts/
115+
ensure_helm_repo bitnami https://charts.bitnami.com/bitnami
116+
117+
log_info "Updating Helm repositories..."
118+
helm repo update
119+
120+
log_info "Updating chart dependencies..."
121+
helm dependency update "$CHART_PATH"
122+
}
123+
98124
get_desired_app_replicas() {
99125
local values_path="$1"
100126
local default_count="${APP_REPLICA_COUNT:-}"
@@ -287,9 +313,7 @@ lint_chart() {
287313
exit 1
288314
fi
289315

290-
# Update dependencies
291-
log_info "Updating chart dependencies..."
292-
helm dependency update "$CHART_PATH"
316+
ensure_chart_dependencies
293317

294318
# Lint the chart
295319
helm lint "$CHART_PATH"
@@ -310,6 +334,8 @@ lint_chart() {
310334
# Run Helm chart tests
311335
test_chart() {
312336
log_info "Running Helm chart tests..."
337+
338+
ensure_chart_dependencies
313339

314340
# Dry run installation
315341
log_info "Testing chart installation (dry run)..."
@@ -331,8 +357,7 @@ install_chart() {
331357
# Create namespace if it doesn't exist
332358
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
333359

334-
# Update dependencies
335-
helm dependency update "$CHART_PATH"
360+
ensure_chart_dependencies
336361

337362
# Select appropriate values file for backend
338363
local values_file=""
@@ -412,7 +437,7 @@ install_chart() {
412437
upgrade_chart() {
413438
log_info "Upgrading STAC FastAPI chart..."
414439

415-
helm dependency update "$CHART_PATH"
440+
ensure_chart_dependencies
416441

417442
# Select appropriate values file for backend
418443
local values_file=""

0 commit comments

Comments
 (0)