diff --git a/CHANGELOG.md b/CHANGELOG.md index 255a9e7e..48dc43f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Consistent naming of behavior field - Made all python tests comply with mypy strict validation - Improved documentation about access to grafana +- Reorganized the helm chart templates files [#352](https://github.com/developmentseed/eoapi-k8s/pull/352) ## [0.7.13] - 2025-11-04 diff --git a/charts/eoapi/README.md b/charts/eoapi/README.md index 7e5fb588..14a81dc8 100644 --- a/charts/eoapi/README.md +++ b/charts/eoapi/README.md @@ -159,6 +159,27 @@ For detailed configuration and usage: - [Data Management](https://github.com/developmentseed/eoapi-k8s/blob/main/docs/manage-data.md) - [Autoscaling Guide](https://github.com/developmentseed/eoapi-k8s/blob/main/docs/autoscaling.md) +## Template Structure + +The Helm templates are organized into logical modules: + +``` +templates/ +├── core/ # ServiceAccount, RBAC, Knative resources +├── database/ # PostgreSQL and pgstac bootstrap +├── networking/ # Ingress and middleware +├── monitoring/ # Prometheus and Grafana +├── services/ # API deployments (stac, raster, vector, multidim) +└── _helpers/ # Reusable template functions +``` + +Helper functions are organized by domain in `_helpers/`: +- `core.tpl` - Naming, labels, service account +- `database.tpl` - PostgreSQL configuration +- `services.tpl` - Service helpers and init containers +- `validation.tpl` - Chart validation +- `_resources.tpl` - Resource presets + ## License [MIT License](https://github.com/developmentseed/eoapi-k8s/blob/main/LICENSE) diff --git a/charts/eoapi/templates/_resources.yaml b/charts/eoapi/templates/_helpers/_resources.tpl similarity index 100% rename from charts/eoapi/templates/_resources.yaml rename to charts/eoapi/templates/_helpers/_resources.tpl diff --git a/charts/eoapi/templates/_helpers/core.tpl b/charts/eoapi/templates/_helpers/core.tpl new file mode 100644 index 00000000..0030d7c3 --- /dev/null +++ b/charts/eoapi/templates/_helpers/core.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "eoapi.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "eoapi.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "eoapi.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "eoapi.labels" -}} +helm.sh/chart: {{ include "eoapi.chart" . }} +{{ include "eoapi.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "eoapi.selectorLabels" -}} +app.kubernetes.io/name: {{ include "eoapi.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "eoapi.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "eoapi.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/eoapi/templates/_helpers.tpl b/charts/eoapi/templates/_helpers/database.tpl similarity index 79% rename from charts/eoapi/templates/_helpers.tpl rename to charts/eoapi/templates/_helpers/database.tpl index eff300bb..ed1374c1 100644 --- a/charts/eoapi/templates/_helpers.tpl +++ b/charts/eoapi/templates/_helpers/database.tpl @@ -1,66 +1,3 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "eoapi.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "eoapi.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "eoapi.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "eoapi.labels" -}} -helm.sh/chart: {{ include "eoapi.chart" . }} -{{ include "eoapi.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "eoapi.selectorLabels" -}} -app.kubernetes.io/name: {{ include "eoapi.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "eoapi.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "eoapi.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} - {{/* PostgreSQL environment variables based on the configured type */}} @@ -350,35 +287,6 @@ Validate PostgreSQL configuration {{- end }} {{- end }} -{{/* -values.schema.json doesn't play nice combined value checks -so we use this helper function to check autoscaling rules -*/}} -{{- define "eoapi.validateAutoscaleRules" -}} -{{- if and .Values.ingress.enabled (ne .Values.ingress.className "nginx") }} -{{/* "requestRate" cannot be enabled for any service if not "nginx" so give feedback and fail */}} -{{- $requestRateEnabled := false }} -{{- range .Values.apiServices }} -{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "requestRate") }} -{{- $requestRateEnabled = true }} -{{- end }} -{{- end }} -{{- if $requestRateEnabled }} -{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'requestRate' at this time b/c it's solely an nginx metric" }} -{{- end }} -{{/* "both" cannot be enabled for any service if not "nginx" so give feedback and fail */}} -{{- $bothEnabled := false }} -{{- range .Values.apiServices }} -{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "both") }} -{{- $bothEnabled = true }} -{{- end }} -{{- end }} -{{- if $bothEnabled }} -{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'both' at this time b/c 'requestRate' is solely an nginx metric" }} -{{- end }} -{{- end }} -{{- end -}} - {{/* validate: 1. the .Values.postgrescluster.users array does not have more than two elements. diff --git a/charts/eoapi/templates/services/_common.tpl b/charts/eoapi/templates/_helpers/services.tpl similarity index 100% rename from charts/eoapi/templates/services/_common.tpl rename to charts/eoapi/templates/_helpers/services.tpl diff --git a/charts/eoapi/templates/_helpers/validation.tpl b/charts/eoapi/templates/_helpers/validation.tpl new file mode 100644 index 00000000..dc795e33 --- /dev/null +++ b/charts/eoapi/templates/_helpers/validation.tpl @@ -0,0 +1,28 @@ +{{/* +values.schema.json doesn't play nice combined value checks +so we use this helper function to check autoscaling rules +*/}} +{{- define "eoapi.validateAutoscaleRules" -}} +{{- if and .Values.ingress.enabled (ne .Values.ingress.className "nginx") }} +{{/* "requestRate" cannot be enabled for any service if not "nginx" so give feedback and fail */}} +{{- $requestRateEnabled := false }} +{{- range .Values.apiServices }} +{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "requestRate") }} +{{- $requestRateEnabled = true }} +{{- end }} +{{- end }} +{{- if $requestRateEnabled }} +{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'requestRate' at this time b/c it's solely an nginx metric" }} +{{- end }} +{{/* "both" cannot be enabled for any service if not "nginx" so give feedback and fail */}} +{{- $bothEnabled := false }} +{{- range .Values.apiServices }} +{{- if and (index $.Values . "autoscaling" "enabled") (eq (index $.Values . "autoscaling" "type") "both") }} +{{- $bothEnabled = true }} +{{- end }} +{{- end }} +{{- if $bothEnabled }} +{{- fail "When using an 'ingress.className' other than 'nginx' you cannot enable autoscaling by 'both' at this time b/c 'requestRate' is solely an nginx metric" }} +{{- end }} +{{- end }} +{{- end -}} diff --git a/charts/eoapi/templates/cloudevents-sink.yaml b/charts/eoapi/templates/core/cloudevents-sink.yaml similarity index 100% rename from charts/eoapi/templates/cloudevents-sink.yaml rename to charts/eoapi/templates/core/cloudevents-sink.yaml diff --git a/charts/eoapi/templates/knative-init.yaml b/charts/eoapi/templates/core/knative-init.yaml similarity index 100% rename from charts/eoapi/templates/knative-init.yaml rename to charts/eoapi/templates/core/knative-init.yaml diff --git a/charts/eoapi/templates/services/rbac.yaml b/charts/eoapi/templates/core/rbac.yaml similarity index 100% rename from charts/eoapi/templates/services/rbac.yaml rename to charts/eoapi/templates/core/rbac.yaml diff --git a/charts/eoapi/templates/service-account.yaml b/charts/eoapi/templates/core/service-account.yaml similarity index 100% rename from charts/eoapi/templates/service-account.yaml rename to charts/eoapi/templates/core/service-account.yaml diff --git a/charts/eoapi/templates/sink-binding.yaml b/charts/eoapi/templates/core/sink-binding.yaml similarity index 100% rename from charts/eoapi/templates/sink-binding.yaml rename to charts/eoapi/templates/core/sink-binding.yaml diff --git a/charts/eoapi/templates/validation.yaml b/charts/eoapi/templates/core/validation.yaml similarity index 100% rename from charts/eoapi/templates/validation.yaml rename to charts/eoapi/templates/core/validation.yaml diff --git a/charts/eoapi/templates/pgstacbootstrap/configmap.yaml b/charts/eoapi/templates/database/pgstacbootstrap/configmap.yaml similarity index 100% rename from charts/eoapi/templates/pgstacbootstrap/configmap.yaml rename to charts/eoapi/templates/database/pgstacbootstrap/configmap.yaml diff --git a/charts/eoapi/templates/pgstacbootstrap/eoap-superuser-initdb.yaml b/charts/eoapi/templates/database/pgstacbootstrap/eoap-superuser-initdb.yaml similarity index 100% rename from charts/eoapi/templates/pgstacbootstrap/eoap-superuser-initdb.yaml rename to charts/eoapi/templates/database/pgstacbootstrap/eoap-superuser-initdb.yaml diff --git a/charts/eoapi/templates/pgstacbootstrap/extent-updater.yaml b/charts/eoapi/templates/database/pgstacbootstrap/extent-updater.yaml similarity index 100% rename from charts/eoapi/templates/pgstacbootstrap/extent-updater.yaml rename to charts/eoapi/templates/database/pgstacbootstrap/extent-updater.yaml diff --git a/charts/eoapi/templates/pgstacbootstrap/job.yaml b/charts/eoapi/templates/database/pgstacbootstrap/job.yaml similarity index 100% rename from charts/eoapi/templates/pgstacbootstrap/job.yaml rename to charts/eoapi/templates/database/pgstacbootstrap/job.yaml diff --git a/charts/eoapi/templates/pgstacbootstrap/queue-processor.yaml b/charts/eoapi/templates/database/pgstacbootstrap/queue-processor.yaml similarity index 100% rename from charts/eoapi/templates/pgstacbootstrap/queue-processor.yaml rename to charts/eoapi/templates/database/pgstacbootstrap/queue-processor.yaml diff --git a/charts/eoapi/templates/_monitoring.yaml b/charts/eoapi/templates/monitoring/_monitoring.yaml similarity index 100% rename from charts/eoapi/templates/_monitoring.yaml rename to charts/eoapi/templates/monitoring/_monitoring.yaml diff --git a/charts/eoapi/templates/observability.yaml b/charts/eoapi/templates/monitoring/observability.yaml similarity index 100% rename from charts/eoapi/templates/observability.yaml rename to charts/eoapi/templates/monitoring/observability.yaml diff --git a/charts/eoapi/templates/services/ingress-browser.yaml b/charts/eoapi/templates/networking/ingress-browser.yaml similarity index 100% rename from charts/eoapi/templates/services/ingress-browser.yaml rename to charts/eoapi/templates/networking/ingress-browser.yaml diff --git a/charts/eoapi/templates/services/ingress.yaml b/charts/eoapi/templates/networking/ingress.yaml similarity index 100% rename from charts/eoapi/templates/services/ingress.yaml rename to charts/eoapi/templates/networking/ingress.yaml diff --git a/charts/eoapi/templates/services/traefik-middleware.yaml b/charts/eoapi/templates/networking/traefik-middleware.yaml similarity index 100% rename from charts/eoapi/templates/services/traefik-middleware.yaml rename to charts/eoapi/templates/networking/traefik-middleware.yaml diff --git a/charts/eoapi/templates/services/README.md b/charts/eoapi/templates/services/README.md deleted file mode 100644 index 2d8cce11..00000000 --- a/charts/eoapi/templates/services/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Service-Specific Templates - -This directory contains service-specific templates organized to improve readability, maintainability, and flexibility. - -## Directory Structure - -``` -services/ -├── _common.tpl # Limited common helper functions -├── ingress.yaml # Single shared ingress for all services -├── raster/ # Raster service templates -│ ├── deployment.yaml # Deployment definition -│ ├── service.yaml # Service definition -│ ├── configmap.yaml # ConfigMap definition -│ └── hpa.yaml # HorizontalPodAutoscaler definition -├── stac/ # STAC service templates -│ ├── deployment.yaml -│ ├── service.yaml -│ ├── configmap.yaml -│ └── hpa.yaml -├── vector/ # Vector service templates -│ ├── deployment.yaml -│ ├── service.yaml -│ ├── configmap.yaml -│ └── hpa.yaml -└── multidim/ # Multidimensional service templates - ├── deployment.yaml - ├── service.yaml - ├── configmap.yaml - └── hpa.yaml -``` - -## Common Helpers - -The `_common.tpl` file provides limited helper functions for truly common elements: - -- `eoapi.mountServiceSecrets`: For mounting service secrets -- `eoapi.commonEnvVars`: For common environment variables like SERVICE_NAME, RELEASE_NAME, GIT_SHA -- `eoapi.pgstacInitContainers`: For init containers that wait for pgstac jobs - -For database environment variables, we leverage the existing `eoapi.postgresqlEnv` helper from the main `_helpers.tpl` file. - -## Usage - -No changes to `values.yaml` structure were required. The chart maintains full backward compatibility with existing deployments.