Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8e52252
Refactor PostgreSQL configuration and remove deprecated database setup
emmanuelmathot Apr 17, 2025
637dc91
Add PostgreSQL host reader and writer environment variables, and incl…
emmanuelmathot Apr 17, 2025
9b6b092
Merge remote-tracking branch 'origin/main' into unified_pg
emmanuelmathot Apr 18, 2025
5f45f50
Merge branch 'main' into unified_pg
emmanuelmathot Apr 28, 2025
ee41f4b
Added a clarifying comment in values.yaml to explain that values in t…
emmanuelmathot Apr 28, 2025
e6e0fed
Refactor: Implement unified ingress configuration for nginx and traef…
emmanuelmathot Apr 28, 2025
b091f48
Remove deprecated ingress backup template from helm chart
emmanuelmathot Apr 28, 2025
d6abec2
Enhance ingress configuration in test values for Traefik with path tr…
emmanuelmathot Apr 28, 2025
d4b5309
Add Traefik middleware for path rewriting and update ingress annotations
emmanuelmathot Apr 28, 2025
6ff372d
Refactor: Update Traefik ingress annotations to use middleware for pa…
emmanuelmathot Apr 28, 2025
149490d
Remove Traefik ingress annotations for entrypoints and middlewares in…
emmanuelmathot Apr 28, 2025
b303394
Add init container for pgstac migration and loading samples in deploy…
emmanuelmathot Apr 28, 2025
0486843
Add command to retrieve and describe Traefik middleware in CI workflow
emmanuelmathot Apr 28, 2025
9e4cb32
Refactor ingress configuration for Traefik and NGINX; add host for TL…
emmanuelmathot Apr 29, 2025
127eb8c
Add Traefik middleware annotation for ingress tests
emmanuelmathot Apr 29, 2025
193334e
Add Traefik entrypoint annotation to ingress configuration
emmanuelmathot Apr 29, 2025
c88a9ab
Add temporary annotation for Traefik to support ASGI prefix handling
emmanuelmathot Apr 29, 2025
6784c9c
Merge branch 'main' into unified_ingress
emmanuelmathot Apr 29, 2025
93cfb90
Remove testing condition from doc-server ConfigMap template
emmanuelmathot Apr 29, 2025
e7c3037
Update Traefik service IP address to use local endpoint in helm-tests…
emmanuelmathot Apr 29, 2025
bca644b
Merge branch 'main' into unified_ingress
emmanuelmathot Apr 29, 2025
91c5fe9
Remove hardcoded service account name from deployment template
emmanuelmathot Apr 29, 2025
4710419
Refactor code structure for improved readability and maintainability
emmanuelmathot Apr 29, 2025
01e1e4f
Refactor service templates and tests for improved organization and cl…
emmanuelmathot Apr 29, 2025
4f537f5
Refactor Helm chart tests: Split service tests into individual files …
emmanuelmathot Apr 29, 2025
e2d38fb
Add template references to service tests for multidim, raster, stac, …
emmanuelmathot Apr 29, 2025
5750974
Refactor Helm chart to support service-specific ingress configuration…
emmanuelmathot Apr 29, 2025
e762a6f
Update helm-chart/eoapi/templates/services/multidim/hpa.yaml
emmanuelmathot Apr 30, 2025
00060e4
Update helm-chart/eoapi/templates/services/raster/hpa.yaml
emmanuelmathot Apr 30, 2025
8103c8b
Update helm-chart/eoapi/templates/services/vector/hpa.yaml
emmanuelmathot Apr 30, 2025
d490e11
Implement STAC Auth Proxy integration with EOAPI-K8S for service-spec…
emmanuelmathot Apr 30, 2025
681028c
Merge branch 'chart_refactor' of https://github.com/developmentseed/e…
emmanuelmathot Apr 30, 2025
ee9b045
Update helm-chart/eoapi/templates/services/stac/hpa.yaml
emmanuelmathot Apr 30, 2025
1baf1b5
Merge branch 'main' into chart_refactor
emmanuelmathot Apr 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .github/workflows/helm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,29 @@ jobs:
kubectl get ingress --all-namespaces -o jsonpath='{range .items[0]}kubectl describe ingress {.metadata.name} -n {.metadata.namespace}{end}' | sh
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

PUBLICIP='http://'$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export VECTOR_ENDPOINT=$PUBLICIP/vector$RELEASE_NAME
export STAC_ENDPOINT=$PUBLICIP/stac$RELEASE_NAME
export RASTER_ENDPOINT=$PUBLICIP/raster$RELEASE_NAME
# Get the IP address of the Traefik service
PUBLICIP_VALUE=$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
PUBLICIP=http://eoapi.local
export VECTOR_ENDPOINT=$PUBLICIP/vector
export STAC_ENDPOINT=$PUBLICIP/stac
export RASTER_ENDPOINT=$PUBLICIP/raster

# Add entry to /etc/hosts for eoapi.local
echo "Adding eoapi.local to /etc/hosts with IP: $PUBLICIP_VALUE"
echo "$PUBLICIP_VALUE eoapi.local" | sudo tee -a /etc/hosts

echo '#################################'
echo $VECTOR_ENDPOINT
echo $STAC_ENDPOINT
echo $RASTER_ENDPOINT
echo '#################################'

pytest .github/workflows/tests/test_vector.py || kubectl logs svc/vector
pytest .github/workflows/tests/test_stac.py || kubectl logs svc/stac
# Run tests with proper failure propagation
set -e # Make sure any command failure causes the script to exit with error
pytest .github/workflows/tests/test_vector.py || { kubectl logs svc/vector; exit 1; }
pytest .github/workflows/tests/test_stac.py || { kubectl logs svc/stac; exit 1; }
# TODO: fix raster tests
#pytest .github/workflows/tests/test_raster.py || kubectl logs svc/raster
#pytest .github/workflows/tests/test_raster.py || { kubectl logs svc/raster; exit 1; }

- name: error if tests failed
if: steps.testrunner.outcome == 'failure'
Expand Down
105 changes: 105 additions & 0 deletions PR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Refactor Helm Chart to Service-Specific Templates

## Overview

This PR refactors our Helm chart structure from a loop-based approach to service-specific templates. The primary goal is to improve readability, maintainability, and flexibility of our Kubernetes resource definitions.

## Problem Statement

The previous approach of looping over API services to generate Kubernetes resources created several challenges:

1. **Poor Readability**: Templates contained complex nested conditionals and loops
2. **Difficult Maintenance**: Changes to template structure affected all services
3. **Limited Flexibility**: Assumed all services followed the same pattern
4. **Debugging Challenges**: Hard to trace issues to specific services
5. **Upgrade Complexity**: Difficult to update individual services independently

## Changes Made

1. **Service-Specific Directory Structure**:
- Created dedicated directories for each service (`raster`, `stac`, `vector`, `multidim`)
- Each service directory contains its own templates (`deployment.yaml`, `service.yaml`, `configmap.yaml`, `hpa.yaml`)

2. **Common Helper Functions**:
- Created a minimal `_common.tpl` with focused helper functions:
- `eoapi.mountServiceSecrets` - For mounting service secrets
- `eoapi.commonEnvVars` - For common environment variables
- `eoapi.pgstacInitContainers` - For init containers that wait for pgstac jobs

3. **Service-Specific Configuration**:
- Added ability to control ingress per service:
```yaml
stac:
enabled: true
ingress:
enabled: false # Disable ingress for STAC only
```
- Supports use cases like stac-auth-proxy where STAC API needs internal-only access
- Maintains backward compatibility with existing configurations

4. **Integration with Existing Helpers**:
- Used existing `eoapi.postgresqlEnv` helper for database environment variables
- Maintained compatibility with other system helpers

5. **Documentation**:
- Added a comprehensive README.md in the services directory explaining the refactoring approach
- Documented the new directory structure and helper functions

## Benefits

1. **Improved Readability**: Service configurations are explicit and clearly visible
2. **Better Maintainability**: Changes to one service don't affect others
3. **Enhanced Flexibility**:
- Each service can evolve independently
- Can enable/disable features per service (like ingress)
4. **Easier Debugging**: Errors are isolated to specific service files
5. **Safer Changes**: Template modifications can be tested on individual services
6. **Reduced Cognitive Load**: Developers can understand one service at a time

## Example Use Cases

1. **STAC with Auth Proxy**:
```yaml
# values.yaml
stac:
enabled: true
ingress:
enabled: false # No external ingress for STAC
```
This allows stac-auth-proxy to handle external access while STAC API remains internal.

2. **Mixed Access Patterns**:
```yaml
stac:
ingress:
enabled: false # Internal only
raster:
ingress:
enabled: true # External access
```
Different services can have different access patterns.

## Testing

The refactored templates have been tested using:

1. `helm template` validation to ensure proper YAML generation
2. Installation testing in a development environment
3. Verification that all services deploy and function correctly
4. Running the updated test suite to ensure all tests pass
5. Comparison of the generated resources with the previous approach to ensure no functional changes

## Backward Compatibility

This refactoring maintains full backward compatibility with existing values files and deployments. No changes to values.yaml structure were required, and the chart can be upgraded in-place without disruption.

## Next Steps

Future improvements could include:

1. Further service-specific customizations (e.g., annotations, labels)
2. Enhanced documentation of service-specific options
3. Schema validation for service-specific values
4. Additional common helpers as patterns emerge

Closes #211
107 changes: 107 additions & 0 deletions docs/unified-ingress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Unified Ingress Configuration

This document describes the unified ingress approach implemented in the eoAPI Helm chart.

## Overview

eoAPI now uses a consolidated, controller-agnostic ingress configuration. This approach:

- Eliminates code duplication between different ingress controller implementations
- Provides consistent behavior across controllers
- Simplifies testing and maintainability
- Removes artificial restrictions on using certain ingress controllers in specific environments
- Makes it easier to add support for additional ingress controllers in the future

## Configuration

The ingress configuration has been streamlined and generalized in the `values.yaml` file:

```yaml
ingress:
# Unified ingress configuration for both nginx and traefik
enabled: true
# ingressClassName: "nginx" or "traefik"
className: "nginx"
# Path configuration
pathType: "Prefix" # Can be "Prefix" or "ImplementationSpecific" based on controller
pathSuffix: "" # Add a suffix to service paths (e.g. "(/|$)(.*)" for nginx regex)
rootPath: "" # Root path for doc server
# Host configuration
host: ""
# Custom annotations to add to the ingress
annotations: {}
# TLS configuration
tls:
enabled: false
secretName: eoapi-tls
certManager: false
certManagerIssuer: letsencrypt-prod
certManagerEmail: ""
```

## Controller-Specific Configurations

### NGINX Ingress Controller

For NGINX, use the following configuration:

```yaml
ingress:
enabled: true
className: "nginx"
pathType: "Prefix"
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/enable-access-log: "true"
```

### Traefik Ingress Controller

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.

For basic Traefik configuration:

```yaml
ingress:
enabled: true
className: "traefik"
pathType: "Prefix"
# When using TLS, setting host is required to avoid "No domain found" warnings
host: "example.domain.com" # Required to work properly with TLS
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
```

For Traefik with TLS:

```yaml
ingress:
enabled: true
className: "traefik"
pathType: "Prefix"
# Host is required when using TLS with Traefik
host: "example.domain.com"
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
tls:
enabled: true
secretName: eoapi-tls
```

## Migration

If you're migrating from a previous version, follow these guidelines:

1. Update your values to use the new unified configuration
2. Ensure your ingress controller-specific annotations are set correctly
3. Set the appropriate `pathType` for your controller
4. Test the configuration before deploying to production

## Note for Traefik Users

Traefik is now fully supported in all environments, including production. The previous restriction limiting Traefik to testing environments has been removed.

## Document Server

The document server implementation has also been unified. It now works with both NGINX and Traefik controllers using the same configuration.
2 changes: 2 additions & 0 deletions helm-chart/eoapi/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
*.tmproj
.vscode/
tests/
# Ignore all README.md in all subdirectories
README.md
62 changes: 0 additions & 62 deletions helm-chart/eoapi/ingress.bkup

This file was deleted.

11 changes: 0 additions & 11 deletions helm-chart/eoapi/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,3 @@ validate:
{{- end -}}

{{- end -}}

{{/*
validate:
that you can only use traefik as ingress when `testing=true`
*/}}
{{- define "eoapi.validateTraefik" -}}
{{- if and (not .Values.testing) (eq .Values.ingress.className "traefik") $ -}}
{{- fail "you cannot use traefik yet outside of testing" -}}
{{- end -}}

{{- end -}}
4 changes: 2 additions & 2 deletions helm-chart/eoapi/templates/pgstacbootstrap/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ metadata:
annotations:
helm.sh/hook: "post-install,post-upgrade"
helm.sh/hook-weight: "-5"
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
helm.sh/hook-delete-policy: "before-hook-creation"
spec:
template:
metadata:
Expand Down Expand Up @@ -97,7 +97,7 @@ metadata:
annotations:
helm.sh/hook: "post-install,post-upgrade"
helm.sh/hook-weight: "-4"
helm.sh/hook-delete-policy: "before-hook-creation,hook-succeeded"
helm.sh/hook-delete-policy: "before-hook-creation"
spec:
template:
metadata:
Expand Down
Loading