Skip to content

Commit 4710419

Browse files
Refactor code structure for improved readability and maintainability
1 parent 91c5fe9 commit 4710419

28 files changed

+2673
-291
lines changed

helm-chart/eoapi/.helmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
*.tmproj
2323
.vscode/
2424
tests/
25+
# Ignore all README.md in all subdirectories
26+
README.md

helm-chart/eoapi/templates/_pgstac_init.tpl

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Helm Chart Structure Refactoring
2+
3+
This directory contains the refactored Helm chart templates for the EOAPI services.
4+
5+
## Overview
6+
7+
The templates have been refactored from a loop-based approach to a service-specific approach where each service has its own dedicated template files. This improves readability, maintainability, and flexibility.
8+
9+
## Directory Structure
10+
11+
```
12+
services/
13+
├── _common.tpl # Limited common helper functions
14+
├── ingress.yaml # Single ingress for all services
15+
├── traefik-middleware.yaml # Traefik middleware for path stripping
16+
├── raster/ # One directory per service
17+
│ ├── deployment.yaml
18+
│ ├── service.yaml
19+
│ ├── configmap.yaml
20+
│ └── hpa.yaml
21+
├── stac/
22+
│ ├── deployment.yaml
23+
│ ├── service.yaml
24+
│ ├── configmap.yaml
25+
│ └── hpa.yaml
26+
├── vector/
27+
│ ├── deployment.yaml
28+
│ ├── service.yaml
29+
│ ├── configmap.yaml
30+
│ └── hpa.yaml
31+
└── multidim/
32+
├── deployment.yaml
33+
├── service.yaml
34+
├── configmap.yaml
35+
└── hpa.yaml
36+
```
37+
38+
## Key Improvements
39+
40+
1. **Enhanced Readability**: Each service's configuration is explicitly defined in its own files, making it easier to understand.
41+
2. **Improved Debugging**: Errors are isolated to specific service files, making troubleshooting simpler.
42+
3. **Lower Risk Changes**: Changes intended for one service are contained within its files, reducing the risk of affecting other services.
43+
4. **True Flexibility**: Each service can evolve independently, and new services can be added by copying and modifying existing patterns.
44+
5. **Limited Helper Functions**: Common logic is extracted into the `_common.tpl` file but only for the most mechanical, repetitive parts.
45+
46+
## How to Use
47+
48+
The chart maintains the same values.yaml structure but templates are now organized by service. The original looping templates have been preserved with `.old` extensions for reference.
49+
50+
For adding a new service:
51+
1. Create a new directory with the service name
52+
2. Copy and adapt the deployment, service, configmap, and hpa templates
53+
3. Add an entry to ingress.yaml and traefik-middleware.yaml if needed
54+
4. Update values.yaml with the new service configuration
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{{/*
2+
Helper function for mounting service secrets
3+
Only extract truly common elements that are mechanical and don't need customization
4+
*/}}
5+
{{- define "eoapi.mountServiceSecrets" -}}
6+
{{- $service := .service -}}
7+
{{- $root := .root -}}
8+
{{- if index $root.Values $service "settings" "envSecrets" }}
9+
{{- range $secret := index $root.Values $service "settings" "envSecrets" }}
10+
- secretRef:
11+
name: {{ $secret }}
12+
{{- end }}
13+
{{- end }}
14+
{{- end -}}
15+
16+
{{/*
17+
Helper function for common environment variables
18+
*/}}
19+
{{- define "eoapi.commonEnvVars" -}}
20+
{{- $service := .service -}}
21+
{{- $root := .root -}}
22+
- name: SERVICE_NAME
23+
value: {{ $service | quote }}
24+
- name: RELEASE_NAME
25+
value: {{ $root.Release.Name | quote }}
26+
- name: GIT_SHA
27+
value: {{ $root.Values.gitSha | quote }}
28+
{{- end -}}
29+
30+
{{/*
31+
Helper function for common init containers to wait for pgstac jobs
32+
*/}}
33+
{{- define "eoapi.pgstacInitContainers" -}}
34+
{{- if .Values.pgstacBootstrap.enabled }}
35+
initContainers:
36+
- name: wait-for-pgstac-jobs
37+
image: bitnami/kubectl:latest
38+
command:
39+
- /bin/sh
40+
- -c
41+
- |
42+
echo "Waiting for pgstac-migrate job to complete..."
43+
until kubectl get job pgstac-migrate -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
44+
echo "pgstac-migrate job not complete yet, waiting..."
45+
sleep 5
46+
done
47+
echo "pgstac-migrate job completed successfully."
48+
49+
{{- if .Values.pgstacBootstrap.settings.loadSamples }}
50+
echo "Waiting for pgstac-load-samples job to complete..."
51+
until kubectl get job pgstac-load-samples -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
52+
echo "pgstac-load-samples job not complete yet, waiting..."
53+
sleep 5
54+
done
55+
echo "pgstac-load-samples job completed successfully."
56+
{{- end }}
57+
{{- end }}
58+
{{- end -}}

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

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

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

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

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

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

0 commit comments

Comments
 (0)