Skip to content

Commit c7176cf

Browse files
Unified Ingress Implementation - Fixes #205 (#219)
* Refactor PostgreSQL configuration and remove deprecated database setup - Introduced a unified PostgreSQL configuration structure in values.yaml, replacing the old db configuration. - Added new helper functions for managing PostgreSQL environment variables and secrets based on the selected configuration type (postgrescluster, external-plaintext, external-secret). - Removed old database-related templates (ConfigMap, Deployment, PVC, Secrets, Service) that are no longer needed. - Updated the pgstacbootstrap job and configmap templates to align with the new PostgreSQL configuration. - Implemented validation for PostgreSQL settings to ensure required fields are set based on the selected type. * Add PostgreSQL host reader and writer environment variables, and include DATABASE_URL for connection string * Added a clarifying comment in values.yaml to explain that values in the external secret (host, port, database) will override the corresponding values defined in external.host, external.port, and external.database. Confirmed that the conditional blocks in deployment.yaml were already consolidated to eliminate redundancy. The file was already using a single include statement for PostgreSQL environment variables: env: {{- include "eoapi.postgresqlEnv" $ | nindent 12 }} Removed the unused eoapi.mapLegacyPostgresql helper function from _helpers.tpl as it wasn't being referenced anywhere in the codebase. * Refactor: Implement unified ingress configuration for nginx and traefik, streamline values.yaml, and update related documentation and tests * Remove deprecated ingress backup template from helm chart * Enhance ingress configuration in test values for Traefik with path transformation annotations * Add Traefik middleware for path rewriting and update ingress annotations * Refactor: Update Traefik ingress annotations to use middleware for path rewriting * Remove Traefik ingress annotations for entrypoints and middlewares in test cases * Add init container for pgstac migration and loading samples in deployment * Add command to retrieve and describe Traefik middleware in CI workflow * Refactor ingress configuration for Traefik and NGINX; add host for TLS support and remove deprecated middleware * Add Traefik middleware annotation for ingress tests * Add Traefik entrypoint annotation to ingress configuration * Add temporary annotation for Traefik to support ASGI prefix handling * Remove testing condition from doc-server ConfigMap template * Update Traefik service IP address to use local endpoint in helm-tests workflow * Remove hardcoded service account name from deployment template * Add comments to clarify proxy settings and ingress pathType requirements * Clarify versioning details in unified ingress documentation
1 parent 9c581c5 commit c7176cf

17 files changed

+373
-471
lines changed

.github/workflows/helm-tests.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,29 @@ jobs:
196196
kubectl get ingress --all-namespaces -o jsonpath='{range .items[0]}kubectl describe ingress {.metadata.name} -n {.metadata.namespace}{end}' | sh
197197
kubectl get middleware.traefik.io --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' --no-headers | while read -r namespace name; do kubectl describe middleware.traefik.io "$name" -n "$namespace"; done
198198
199-
PUBLICIP='http://'$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
200-
export VECTOR_ENDPOINT=$PUBLICIP/vector$RELEASE_NAME
201-
export STAC_ENDPOINT=$PUBLICIP/stac$RELEASE_NAME
202-
export RASTER_ENDPOINT=$PUBLICIP/raster$RELEASE_NAME
199+
# Get the IP address of the Traefik service
200+
PUBLICIP_VALUE=$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
201+
PUBLICIP=http://eoapi.local
202+
export VECTOR_ENDPOINT=$PUBLICIP/vector
203+
export STAC_ENDPOINT=$PUBLICIP/stac
204+
export RASTER_ENDPOINT=$PUBLICIP/raster
205+
206+
# Add entry to /etc/hosts for eoapi.local
207+
echo "Adding eoapi.local to /etc/hosts with IP: $PUBLICIP_VALUE"
208+
echo "$PUBLICIP_VALUE eoapi.local" | sudo tee -a /etc/hosts
203209
204210
echo '#################################'
205211
echo $VECTOR_ENDPOINT
206212
echo $STAC_ENDPOINT
207213
echo $RASTER_ENDPOINT
208214
echo '#################################'
209215
210-
pytest .github/workflows/tests/test_vector.py || kubectl logs svc/vector
211-
pytest .github/workflows/tests/test_stac.py || kubectl logs svc/stac
216+
# Run tests with proper failure propagation
217+
set -e # Make sure any command failure causes the script to exit with error
218+
pytest .github/workflows/tests/test_vector.py || { kubectl logs svc/vector; exit 1; }
219+
pytest .github/workflows/tests/test_stac.py || { kubectl logs svc/stac; exit 1; }
212220
# TODO: fix raster tests
213-
#pytest .github/workflows/tests/test_raster.py || kubectl logs svc/raster
221+
#pytest .github/workflows/tests/test_raster.py || { kubectl logs svc/raster; exit 1; }
214222
215223
- name: error if tests failed
216224
if: steps.testrunner.outcome == 'failure'

docs/unified-ingress.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Unified Ingress Configuration
2+
3+
This document describes the unified ingress approach implemented in the eoAPI Helm chart.
4+
5+
## Overview
6+
7+
As of version 0.7.0, eoAPI uses a consolidated, controller-agnostic ingress configuration. This approach:
8+
9+
- Eliminates code duplication between different ingress controller implementations
10+
- Provides consistent behavior across controllers
11+
- Simplifies testing and maintainability
12+
- Removes artificial restrictions on using certain ingress controllers in specific environments
13+
- Makes it easier to add support for additional ingress controllers in the future
14+
15+
## Configuration
16+
17+
The ingress configuration has been streamlined and generalized in the `values.yaml` file:
18+
19+
```yaml
20+
ingress:
21+
# Unified ingress configuration for both nginx and traefik
22+
enabled: true
23+
# ingressClassName: "nginx" or "traefik"
24+
className: "nginx"
25+
# Path configuration
26+
pathType: "Prefix" # Can be "Prefix" or "ImplementationSpecific" based on controller
27+
pathSuffix: "" # Add a suffix to service paths (e.g. "(/|$)(.*)" for nginx regex)
28+
rootPath: "" # Root path for doc server
29+
# Host configuration
30+
host: ""
31+
# Custom annotations to add to the ingress
32+
annotations: {}
33+
# TLS configuration
34+
tls:
35+
enabled: false
36+
secretName: eoapi-tls
37+
certManager: false
38+
certManagerIssuer: letsencrypt-prod
39+
certManagerEmail: ""
40+
```
41+
42+
## Controller-Specific Configurations
43+
44+
### NGINX Ingress Controller
45+
46+
For NGINX, use the following configuration:
47+
48+
```yaml
49+
ingress:
50+
enabled: true
51+
className: "nginx"
52+
pathType: "Prefix"
53+
annotations:
54+
nginx.ingress.kubernetes.io/use-regex: "true"
55+
nginx.ingress.kubernetes.io/enable-cors: "true"
56+
nginx.ingress.kubernetes.io/enable-access-log: "true"
57+
```
58+
59+
### Traefik Ingress Controller
60+
61+
When using Traefik, the system automatically includes the Traefik middleware to strip prefixes (e.g., `/stac`, `/raster`) from requests before forwarding them to services. This is handled by the `traefik-middleware.yaml` template.
62+
63+
For basic Traefik configuration:
64+
65+
```yaml
66+
ingress:
67+
enabled: true
68+
className: "traefik"
69+
pathType: "Prefix"
70+
# When using TLS, setting host is required to avoid "No domain found" warnings
71+
host: "example.domain.com" # Required to work properly with TLS
72+
annotations:
73+
traefik.ingress.kubernetes.io/router.entrypoints: web
74+
```
75+
76+
For Traefik with TLS:
77+
78+
```yaml
79+
ingress:
80+
enabled: true
81+
className: "traefik"
82+
pathType: "Prefix"
83+
# Host is required when using TLS with Traefik
84+
host: "example.domain.com"
85+
annotations:
86+
traefik.ingress.kubernetes.io/router.entrypoints: websecure
87+
tls:
88+
enabled: true
89+
secretName: eoapi-tls
90+
```
91+
92+
## Migration
93+
94+
If you're migrating from a version 0.6.0 or earlier, follow these guidelines:
95+
96+
1. Update your values to use the new unified configuration
97+
2. Ensure your ingress controller-specific annotations are set correctly
98+
3. Set the appropriate `pathType` for your controller
99+
4. Test the configuration before deploying to production
100+
101+
## Note for Traefik Users
102+
103+
Traefik is now fully supported in all environments, including production. The previous restriction limiting Traefik to testing environments has been removed.
104+
105+
## Document Server
106+
107+
The document server implementation has also been unified. It now works with both NGINX and Traefik controllers using the same configuration.

helm-chart/eoapi/ingress.bkup

Lines changed: 0 additions & 62 deletions
This file was deleted.

helm-chart/eoapi/templates/_helpers.tpl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,3 @@ validate:
397397
{{- end -}}
398398
399399
{{- end -}}
400-
401-
{{/*
402-
validate:
403-
that you can only use traefik as ingress when `testing=true`
404-
*/}}
405-
{{- define "eoapi.validateTraefik" -}}
406-
{{- if and (not .Values.testing) (eq .Values.ingress.className "traefik") $ -}}
407-
{{- fail "you cannot use traefik yet outside of testing" -}}
408-
{{- end -}}
409-
410-
{{- end -}}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{- define "eoapi.pgstacInitContainer" -}}
2+
{{- if .Values.pgstacBootstrap.enabled }}
3+
- name: wait-for-pgstac-migrate
4+
image: bitnami/kubectl:latest
5+
command:
6+
- /bin/sh
7+
- -c
8+
- |
9+
echo "Waiting for pgstac-migrate job to complete..."
10+
until kubectl get job pgstac-migrate -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
11+
echo "pgstac-migrate job not complete yet, waiting..."
12+
sleep 5
13+
done
14+
echo "pgstac-migrate job completed successfully."
15+
{{- if .Values.pgstacBootstrap.settings.loadSamples }}
16+
- name: wait-for-pgstac-load-samples
17+
image: bitnami/kubectl:latest
18+
command:
19+
- /bin/sh
20+
- -c
21+
- |
22+
echo "Waiting for pgstac-load-samples job to complete..."
23+
until kubectl get job pgstac-load-samples -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
24+
echo "pgstac-load-samples job not complete yet, waiting..."
25+
sleep 5
26+
done
27+
echo "pgstac-load-samples job completed successfully."
28+
{{- end }}
29+
{{- end }}
30+
{{- end -}}

helm-chart/eoapi/templates/pgstacbootstrap/job.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ metadata:
2929
annotations:
3030
helm.sh/hook: "post-install,post-upgrade"
3131
helm.sh/hook-weight: "-5"
32-
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
32+
helm.sh/hook-delete-policy: "before-hook-creation"
3333
spec:
3434
template:
3535
metadata:
@@ -97,7 +97,7 @@ metadata:
9797
annotations:
9898
helm.sh/hook: "post-install,post-upgrade"
9999
helm.sh/hook-weight: "-4"
100-
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
100+
helm.sh/hook-delete-policy: "before-hook-creation"
101101
spec:
102102
template:
103103
metadata:

helm-chart/eoapi/templates/services/deployment.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,38 @@ spec:
3434
{{- toYaml . | nindent 8 }}
3535
{{- end }}
3636
spec:
37+
{{- if $.Values.pgstacBootstrap.enabled }}
38+
initContainers:
39+
- name: wait-for-pgstac-jobs
40+
image: bitnami/kubectl:latest
41+
command:
42+
- /bin/sh
43+
- -c
44+
- |
45+
echo "Waiting for pgstac-migrate job to complete..."
46+
until kubectl get job pgstac-migrate -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
47+
echo "pgstac-migrate job not complete yet, waiting..."
48+
sleep 5
49+
done
50+
echo "pgstac-migrate job completed successfully."
51+
52+
{{- if $.Values.pgstacBootstrap.settings.loadSamples }}
53+
echo "Waiting for pgstac-load-samples job to complete..."
54+
until kubectl get job pgstac-load-samples -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
55+
echo "pgstac-load-samples job not complete yet, waiting..."
56+
sleep 5
57+
done
58+
echo "pgstac-load-samples job completed successfully."
59+
{{- end }}
60+
{{- end }}
3761
containers:
3862
- image: {{ index $v "image" "name" }}:{{ index $v "image" "tag" }}
3963
name: {{ $serviceName }}
4064
command:
4165
{{- toYaml (index $v "command") | nindent 10 }}
4266
{{- if (and ($.Values.ingress.className) (or (eq $.Values.ingress.className "nginx") (eq $.Values.ingress.className "traefik"))) }}
67+
- "--proxy-headers" # Needed when using reverse proxy
68+
- "--forwarded-allow-ips=*" # Needed when using reverse proxy
4369
- "--root-path=/{{ $serviceName }}"
4470
{{- end }}{{/* needed for proxies and path rewrites on NLB */}}
4571
livenessProbe:

helm-chart/eoapi/templates/services/nginx-doc-server.yaml renamed to helm-chart/eoapi/templates/services/doc-server.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{{- if (and (.Values.ingress.className) (eq .Values.ingress.className "nginx") (not .Values.testing) (.Values.docServer.enabled))}}
1+
{{- if .Values.docServer.enabled}}
22
apiVersion: v1
33
kind: ConfigMap
44
metadata:
5-
name: nginx-root-html-{{ .Release.Name }}
5+
name: doc-server-html-{{ .Release.Name }}
66
data:
77
index.html: |
88
<html>
@@ -11,7 +11,7 @@ data:
1111
</head>
1212
<body>
1313
<h2>This is the root path /</h2>
14-
<p>Your service configuration is using ingress-nginx with path rewrites. So use these paths for each service:</p>
14+
<p>Your service configuration is using path rewrites. So use these paths for each service:</p>
1515
<ul>
1616
<li><a href="/raster" target="_blank" rel="noopener noreferrer">/raster</a></li>
1717
<li><a href="/vector" target="_blank" rel="noopener noreferrer">/vector</a></li>
@@ -48,7 +48,7 @@ spec:
4848
volumes:
4949
- name: doc-html-{{ .Release.Name }}
5050
configMap:
51-
name: nginx-root-html-{{ .Release.Name }}
51+
name: doc-server-html-{{ .Release.Name }}
5252
{{- if .Values.docServer.settings }}
5353
{{- with .Values.docServer.settings.affinity }}
5454
affinity:

0 commit comments

Comments
 (0)