From 6543b7aac0327dd308b59e07379f725e3951d738 Mon Sep 17 00:00:00 2001 From: xBlaz3kx Date: Thu, 15 Oct 2026 09:23:39 +0200 Subject: [PATCH 1/2] feat: add openev-data-mcp chart with PostgreSQL and Qdrant semantic search - Deploy the openev-data-mcp server, with app settings grouped under mcp.config and the image tag defaulting to appVersion 1.0.0. - Provision PostgreSQL through a CloudNativePG Cluster, or point at an external database, and seed it with migrations/001_initial.sql via a post-install Job fetched at the release matching the image. - Install the official Qdrant chart as an optional dependency, with a generated API key kept across upgrades, or point at an external Qdrant. - Configure Gemini embeddings (API key inline or from an existing Secret) and search settings, shared by the server and the sync jobs through a single env helper. - Run `openev-data-mcp migrate` as a post-install/post-upgrade hook Job after the database migration, plus an optional CronJob to finish an index cut short by the Gemini free-tier daily quota. - Give job pods their own name label so the Service never routes MCP traffic to them. - Build the Qdrant dependency in CI and release, and lint the chart with its ci/*-values.yaml examples since the Gemini key is required. --- .github/workflows/openev-data-mcp.yml | 41 +++ .github/workflows/release.yml | 31 +- .gitignore | 2 + README.md | 10 +- charts/openev-data-mcp/.helmignore | 7 + charts/openev-data-mcp/Chart.lock | 6 + charts/openev-data-mcp/Chart.yaml | 25 ++ charts/openev-data-mcp/README.md | 143 +++++++++ .../ci/external-db-values.yaml | 42 +++ .../ci/external-qdrant-values.yaml | 31 ++ charts/openev-data-mcp/templates/NOTES.txt | 43 +++ charts/openev-data-mcp/templates/_helpers.tpl | 289 ++++++++++++++++++ .../openev-data-mcp/templates/deployment.yaml | 68 +++++ .../templates/embedding-secret.yaml | 11 + charts/openev-data-mcp/templates/hpa.yaml | 30 ++ charts/openev-data-mcp/templates/ingress.yaml | 35 +++ .../templates/migration-configmap.yaml | 38 +++ .../templates/migration-job.yaml | 55 ++++ .../templates/postgres-cluster.yaml | 30 ++ charts/openev-data-mcp/templates/service.yaml | 19 ++ .../templates/serviceaccount.yaml | 12 + .../templates/vector-sync-cronjob.yaml | 27 ++ .../templates/vector-sync-job.yaml | 26 ++ charts/openev-data-mcp/values.yaml | 244 +++++++++++++++ 24 files changed, 1257 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/openev-data-mcp.yml create mode 100644 .gitignore create mode 100644 charts/openev-data-mcp/.helmignore create mode 100644 charts/openev-data-mcp/Chart.lock create mode 100644 charts/openev-data-mcp/Chart.yaml create mode 100644 charts/openev-data-mcp/README.md create mode 100644 charts/openev-data-mcp/ci/external-db-values.yaml create mode 100644 charts/openev-data-mcp/ci/external-qdrant-values.yaml create mode 100644 charts/openev-data-mcp/templates/NOTES.txt create mode 100644 charts/openev-data-mcp/templates/_helpers.tpl create mode 100644 charts/openev-data-mcp/templates/deployment.yaml create mode 100644 charts/openev-data-mcp/templates/embedding-secret.yaml create mode 100644 charts/openev-data-mcp/templates/hpa.yaml create mode 100644 charts/openev-data-mcp/templates/ingress.yaml create mode 100644 charts/openev-data-mcp/templates/migration-configmap.yaml create mode 100644 charts/openev-data-mcp/templates/migration-job.yaml create mode 100644 charts/openev-data-mcp/templates/postgres-cluster.yaml create mode 100644 charts/openev-data-mcp/templates/service.yaml create mode 100644 charts/openev-data-mcp/templates/serviceaccount.yaml create mode 100644 charts/openev-data-mcp/templates/vector-sync-cronjob.yaml create mode 100644 charts/openev-data-mcp/templates/vector-sync-job.yaml create mode 100644 charts/openev-data-mcp/values.yaml diff --git a/.github/workflows/openev-data-mcp.yml b/.github/workflows/openev-data-mcp.yml new file mode 100644 index 0000000..a670e97 --- /dev/null +++ b/.github/workflows/openev-data-mcp.yml @@ -0,0 +1,41 @@ +name: openev-data-mcp chart + +on: + pull_request: + paths: + - "charts/openev-data-mcp/**" + - ".github/workflows/openev-data-mcp.yml" + - ".github/workflows/chart-test.yml" + push: + branches: [main] + paths: + - "charts/openev-data-mcp/**" + - ".github/workflows/openev-data-mcp.yml" + - ".github/workflows/chart-test.yml" + workflow_dispatch: {} + +permissions: + contents: read + +jobs: + test: + uses: ./.github/workflows/chart-test.yml + with: + chart: openev-data-mcp + chart-repos: qdrant=https://qdrant.github.io/qdrant-helm + # Default values (bundled CNPG cluster and Qdrant), external database, + # and external Qdrant with the scheduled vector sync. + template-args: | + --set mcp.config.embedding.apiKey=dummy + -f charts/openev-data-mcp/ci/external-db-values.yaml + -f charts/openev-data-mcp/ci/external-qdrant-values.yaml + install-cnpg: true + release: mcp-mock + # There is no Gemini key in CI: the server only needs one to answer + # searches, but the vector sync would fail embedding the dataset. + install-args: --set mcp.config.embedding.apiKey=dummy --set vectorSync.enabled=false + install-timeout: 8m + rollouts: | + deployment/mcp-mock-mcp + statefulset/mcp-mock-qdrant + smoke-test: kubectl -n "$RELEASE" exec deploy/mcp-mock-mcp -- /usr/local/bin/grpc_health_probe -addr=:9090 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c17f68a..1df2e1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,14 +15,18 @@ permissions: packages: write env: - CHART_PATH: charts/open-ev-data REGISTRY: ghcr.io - # Charts are published as oci://ghcr.io//open-ev-data-helm/open-ev-data + # Charts are published as oci://ghcr.io//open-ev-data-helm/ REPO_OWNER: chargepi jobs: release: runs-on: ubuntu-latest + strategy: + matrix: + chart: + - open-ev-data + - openev-data-mcp steps: - uses: actions/checkout@v4 @@ -40,12 +44,27 @@ jobs: fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + - name: Build chart dependencies + run: | + helm repo add qdrant https://qdrant.github.io/qdrant-helm + helm dependency build "charts/${{ matrix.chart }}" + + # Charts with required values (e.g. openev-data-mcp's Gemini API key) are + # linted with their ci/*-values.yaml examples instead of the defaults. - name: Lint chart - run: helm lint "${{ env.CHART_PATH }}" + run: | + CHART="charts/${{ matrix.chart }}" + if ls "${CHART}"/ci/*-values.yaml >/dev/null 2>&1; then + for values in "${CHART}"/ci/*-values.yaml; do + helm lint "${CHART}" -f "${values}" + done + else + helm lint "${CHART}" + fi - name: Package chart run: | - helm package "${{ env.CHART_PATH }}" \ + helm package "charts/${{ matrix.chart }}" \ --version "${{ steps.version.outputs.version }}" \ --app-version "${{ steps.version.outputs.version }}" \ --destination .cr-release-packages @@ -58,9 +77,9 @@ jobs: - name: Push chart to GHCR (OCI) run: | helm push \ - ".cr-release-packages/open-ev-data-${{ steps.version.outputs.version }}.tgz" \ + ".cr-release-packages/${{ matrix.chart }}-${{ steps.version.outputs.version }}.tgz" \ "oci://${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/open-ev-data-helm" - name: Summary run: | - echo "Published oci://${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/open-ev-data-helm/open-ev-data:${{ steps.version.outputs.version }}" >> "$GITHUB_STEP_SUMMARY" + echo "Published oci://${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/open-ev-data-helm/${{ matrix.chart }}:${{ steps.version.outputs.version }}" >> "$GITHUB_STEP_SUMMARY" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7af5c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Chart dependencies, fetched with `helm dependency build` (pinned by Chart.lock). +charts/*/charts/ diff --git a/README.md b/README.md index 7d28e0b..dfb645d 100644 --- a/README.md +++ b/README.md @@ -8,18 +8,24 @@ as OCI artifacts to GHCR. | Chart | Description | |---|---| | [`open-ev-data`](charts/open-ev-data) | Deploys the [API](https://github.com/open-ev-data/open-ev-data-api) (`ev-server`), which fetches the [dataset](https://github.com/open-ev-data/open-ev-data-dataset)'s sqlite release at pod startup. A single chart, no chart dependencies. | +| [`openev-data-mcp`](charts/openev-data-mcp) | Deploys [openev-data-mcp](https://github.com/ChargePi/openev-data-mcp), an MCP server exposing EV specs over the Model Context Protocol, backed by PostgreSQL provisioned via the [CloudNativePG](https://cloudnative-pg.io) operator. | ## Installing ```console helm install my-release oci://ghcr.io/chargepi/open-ev-data-helm/open-ev-data --version +helm install my-release oci://ghcr.io/chargepi/open-ev-data-helm/openev-data-mcp --version ``` -See [`charts/open-ev-data/README.md`](charts/open-ev-data/README.md) for full configuration docs, including -how to source the sqlite database file from somewhere other than GitHub Releases. +See [`charts/open-ev-data/README.md`](charts/open-ev-data/README.md) and +[`charts/openev-data-mcp/README.md`](charts/openev-data-mcp/README.md) for full configuration docs. + ## Development ```console helm lint charts/open-ev-data helm template test charts/open-ev-data + +helm lint charts/openev-data-mcp +helm template test charts/openev-data-mcp ``` diff --git a/charts/openev-data-mcp/.helmignore b/charts/openev-data-mcp/.helmignore new file mode 100644 index 0000000..1c819b5 --- /dev/null +++ b/charts/openev-data-mcp/.helmignore @@ -0,0 +1,7 @@ +# Patterns to ignore when building packages. +.git/ +.gitignore +.DS_Store +.vscode/ +.idea/ +*.md diff --git a/charts/openev-data-mcp/Chart.lock b/charts/openev-data-mcp/Chart.lock new file mode 100644 index 0000000..b25dfae --- /dev/null +++ b/charts/openev-data-mcp/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: qdrant + repository: https://qdrant.github.io/qdrant-helm + version: 1.19.2 +digest: sha256:ba790ce755bdac57afbe702728e97c3faba182e3c892e85f5c151de1a3a5e752 +generated: "2026-10-15T09:17:58.734896692+02:00" diff --git a/charts/openev-data-mcp/Chart.yaml b/charts/openev-data-mcp/Chart.yaml new file mode 100644 index 0000000..6f01f1e --- /dev/null +++ b/charts/openev-data-mcp/Chart.yaml @@ -0,0 +1,25 @@ +apiVersion: v2 +name: openev-data-mcp +description: Helm chart for the OpenEV Data MCP server, exposing EV specifications to AI assistants over the Model Context Protocol, backed by PostgreSQL and Qdrant semantic search +type: application +version: 0.2.0 +appVersion: "1.0.0" +home: https://github.com/ChargePi/openev-data-mcp +sources: + - https://github.com/ChargePi/openev-data-mcp +maintainers: + - name: open-ev-data +keywords: + - electric-vehicle + - ev + - mcp + - model-context-protocol + - postgresql + - cloudnative-pg + - qdrant + - semantic-search +dependencies: + - name: qdrant + version: 1.19.2 + repository: https://qdrant.github.io/qdrant-helm + condition: qdrant.enabled diff --git a/charts/openev-data-mcp/README.md b/charts/openev-data-mcp/README.md new file mode 100644 index 0000000..080154f --- /dev/null +++ b/charts/openev-data-mcp/README.md @@ -0,0 +1,143 @@ +# openev-data-mcp + +Helm chart for [openev-data-mcp](https://github.com/ChargePi/openev-data-mcp), an MCP (Model Context +Protocol) server that exposes EV specifications (battery capacity, range ratings, charging capabilities, +etc) to AI assistants over streamable HTTP, backed by PostgreSQL, with semantic vehicle search +(the `search_vehicles` tool) backed by Qdrant and Gemini embeddings. + +## Prerequisites + +- Kubernetes 1.23+ +- Helm 3.8+ +- The [CloudNativePG](https://cloudnative-pg.io) operator, if you want this chart to provision its own + Postgres cluster (the default — see below for using an external database instead). +- A [Gemini API key](https://aistudio.google.com/apikey), used to embed vehicles and search queries. + +## Why no bundled PostgreSQL chart dependency? + +The usual default (Bitnami's `postgresql` chart) had its free OCI images frozen in 2025 — no more +updates unless you pay for Bitnami Secure Images. A Helm subchart also isn't a great fit for a Postgres +*operator* anyway: its CRDs are cluster-scoped and normally installed once per cluster by a platform +team, not tied to an individual application release's install/uninstall lifecycle. + +Instead, this chart targets [CloudNativePG](https://cloudnative-pg.io): install the operator once per +cluster, + +```console +helm repo add cnpg https://cloudnative-pg.github.io/charts +helm upgrade --install cnpg-operator cnpg/cloudnative-pg --namespace cnpg-system --create-namespace +``` + +and this chart's own `Cluster` resource (`postgresql.cnpg.enabled: true`, the default) provisions a +dedicated Postgres instance per release on top of it. Set `postgresql.cnpg.enabled: false` and configure +`postgresql.external` instead to point at any Postgres you already manage (a CNPG cluster in another +namespace, RDS, etc) without provisioning a new one — see +[`ci/external-db-values.yaml`](ci/external-db-values.yaml) for a worked example: + +```console +helm install my-release charts/openev-data-mcp -f charts/openev-data-mcp/ci/external-db-values.yaml +``` + +## Installing + +```console +kubectl create secret generic openev-mcp-gemini --from-literal=api-key='' +helm install my-release oci://ghcr.io/chargepi/open-ev-data-helm/openev-data-mcp --version \ + --set mcp.config.embedding.existingSecret=openev-mcp-gemini +``` + +Or from a local checkout of this repository (fetch the Qdrant dependency first): + +```console +helm dependency build charts/openev-data-mcp +helm install my-release charts/openev-data-mcp --set mcp.config.embedding.existingSecret=openev-mcp-gemini +``` + +`mcp.config.embedding.apiKey` can be set instead of `existingSecret`, in which case the chart stores the +key in a Secret of its own. + +## Database schema and seed data + +`openev-data-mcp` does not run its schema migration on startup — it just connects. This chart applies +the upstream project's `migrations/001_initial.sql` (schema + seed data) via a **post-install-only** Job +that fetches the file from `raw.githubusercontent.com/ChargePi/openev-data-mcp` at the release tag +matching the deployed image (`v`, defaulting to the chart's `appVersion`), the same way +`api.database.fetch` in the sibling `open-ev-data` chart fetches its dataset — rather than vendoring the +SQL into this chart, so the schema always matches the server version. + +It only runs on install (not on every upgrade) because the migration isn't idempotent — re-running it +against an already-migrated database would fail on "relation already exists". To pick up a newer +migration after bumping `mcp.image.tag`, apply it yourself: + +```console +kubectl get configmap my-release-mcp-migrate -o jsonpath='{.data.migrate\.sh}' | kubectl exec -i -- sh +``` + +or run `helm template ... | kubectl apply -f -` targeting just the Job after deleting the old one. + +Set `migration.enabled: false` to skip this entirely (e.g. if you're pointing at a database that's +already migrated some other way). + +## Semantic search + +The `search_vehicles` tool embeds a natural language query with Gemini and matches it against a Qdrant +collection holding one embedded document per vehicle. + +**Qdrant.** By default the official [Qdrant chart](https://github.com/qdrant/qdrant-helm) is installed as +a dependency, with an API key generated on install and kept across upgrades. Everything under `qdrant` +other than `external` is passed through to it (persistence, resources, replicas, etc). Set +`qdrant.enabled: false` and configure `qdrant.external` to use a Qdrant you manage yourself, e.g. Qdrant +Cloud — see [`ci/external-qdrant-values.yaml`](ci/external-qdrant-values.yaml). + +**Vector sync.** The collection is filled by `openev-data-mcp migrate`, which provisions the collection, +embeds new or changed vehicles, deletes removed ones and skips unchanged ones, so re-running it is cheap. +The chart runs it as a Helm hook Job on install (after the database migration) and on every upgrade. +The MCP server does not wait for it: searches work over whatever is already indexed. + +Helm waits for the hook, so a failed sync fails the install or upgrade. On the Gemini **free tier** the +first sync of the full dataset (~1200 vehicles) exceeds the daily embedding quota (~1000 requests); the +sync stops when Gemini reports the daily quota is exhausted and picks up where it left off on the next +run. Either use a paid key, or set `vectorSync.enabled: false` and enable `vectorSync.cronJob` so the +index completes over consecutive days. The CronJob is also useful on its own, to pick up dataset changes +without a Helm upgrade. + +## Values + +| Key | Description | Default | +|---|---|---| +| `mcp.replicaCount` | Replica count | `1` | +| `mcp.image.repository` / `mcp.image.tag` | MCP server image; `tag` defaults to the chart's `appVersion` | `ghcr.io/chargepi/openev-data-mcp` / `""` | +| `mcp.service.port` | MCP (streamable HTTP) port | `8080` | +| `mcp.service.healthPort` | gRPC health-check port (probed via the `grpc_health_probe` binary baked into the image) | `9090` | +| `mcp.config.refreshInterval` | How often the in-memory resource cache refreshes from the database | `5m` | +| `mcp.config.observability.enabled` / `mcp.config.observability.otlpEndpoint` | OpenTelemetry OTLP export | `false` / `""` | +| `mcp.ingress.enabled` | Expose the MCP endpoint via Ingress | `false` | +| `mcp.autoscaling.enabled` | Enable a HorizontalPodAutoscaler | `false` | +| `postgresql.cnpg.enabled` | Provision a dedicated Postgres cluster via CloudNativePG | `true` | +| `postgresql.cnpg.database` | Application database (and owner role) name | `openevdata` | +| `postgresql.cnpg.storage.size` | PVC size for the CNPG cluster | `1Gi` | +| `postgresql.external.*` | Connection details for a database you manage yourself, used when `postgresql.cnpg.enabled: false` | — | +| `migration.enabled` | Run the post-install schema/seed Job | `true` | +| `migration.gitRef` | Override the git ref to fetch `migrations/001_initial.sql` from; required if `mcp.image.tag` isn't a semver release | `""` (`v`) | +| `mcp.config.embedding.apiKey` / `mcp.config.embedding.existingSecret` | Gemini API key, inline or from an existing Secret (key `existingSecretKey`); one is required | `""` / `""` | +| `mcp.config.embedding.model` / `mcp.config.embedding.dimensions` | Embedding model and vector size; changing the size requires deleting the collection | `gemini-embedding-001` / `768` | +| `mcp.config.search.collection` | Qdrant collection name | `ev_vehicles` | +| `mcp.config.search.limit` / `mcp.config.search.minScore` | Maximum results per search and the minimum cosine similarity for a match | `10` / `0.6` | +| `qdrant.enabled` | Install the bundled Qdrant chart | `true` | +| `qdrant.apiKey` | Generate an API key for the bundled Qdrant | `true` | +| `qdrant.persistence.size` | PVC size for the bundled Qdrant | `1Gi` | +| `qdrant.external.*` | Connection details (host, gRPC port, TLS, API key Secret) for a Qdrant you manage yourself, used when `qdrant.enabled: false` | — | +| `vectorSync.enabled` | Run the vector sync as a post-install/post-upgrade hook Job | `true` | +| `vectorSync.activeDeadlineSeconds` | Time limit for one sync run | `3600` | +| `vectorSync.cronJob.enabled` / `vectorSync.cronJob.schedule` | Also run the sync on a schedule | `false` / `"0 3 * * *"` | + +See `values.yaml` for the full set of options (resources, security contexts, node selectors, etc). + +## Upgrading the MCP server + +```console +helm upgrade my-release charts/openev-data-mcp --set mcp.image.tag=1.0.0 +``` + +The database migration Job does not re-run on upgrade (see above); the `mcp` Deployment rolls and the +vector sync re-runs, re-embedding only vehicles whose indexed document changed. diff --git a/charts/openev-data-mcp/ci/external-db-values.yaml b/charts/openev-data-mcp/ci/external-db-values.yaml new file mode 100644 index 0000000..016fc69 --- /dev/null +++ b/charts/openev-data-mcp/ci/external-db-values.yaml @@ -0,0 +1,42 @@ +# Example values for pointing openev-data-mcp at a PostgreSQL database you +# already manage yourself (RDS, a shared on-prem instance, a CNPG cluster in +# another namespace, etc), instead of having this chart provision a dedicated +# CNPG Cluster. +# +# The referenced Secret is NOT created by this chart — create it yourself +# first, e.g.: +# +# kubectl create secret generic openev-mcp-db-credentials \ +# --from-literal=username=openevdata \ +# --from-literal=password='' +# +# Then apply the schema once against that database (this chart's migration +# Job will do it automatically on install if migration.enabled stays true — +# see the chart README for details on its post-install-only semantics), or +# run migrations/001_initial.sql yourself and set migration.enabled: false. +# +# The Gemini API key for semantic search is read from an existing Secret too: +# +# kubectl create secret generic openev-mcp-gemini --from-literal=api-key='' +# +# Usage: +# helm install my-release charts/openev-data-mcp -f ci/external-db-values.yaml + +mcp: + config: + embedding: + existingSecret: openev-mcp-gemini + +postgresql: + sslMode: require + + cnpg: + enabled: false + + external: + host: my-postgres.example.internal + port: 5432 + database: openevdata + existingSecret: openev-mcp-db-credentials + userKey: username + passwordKey: password diff --git a/charts/openev-data-mcp/ci/external-qdrant-values.yaml b/charts/openev-data-mcp/ci/external-qdrant-values.yaml new file mode 100644 index 0000000..842015a --- /dev/null +++ b/charts/openev-data-mcp/ci/external-qdrant-values.yaml @@ -0,0 +1,31 @@ +# Example values for pointing openev-data-mcp at a Qdrant you already manage +# yourself (e.g. Qdrant Cloud), instead of installing the bundled Qdrant chart. +# +# The referenced Secrets are NOT created by this chart, create them first: +# +# kubectl create secret generic openev-mcp-qdrant --from-literal=api-key='' +# kubectl create secret generic openev-mcp-gemini --from-literal=api-key='' +# +# Usage: +# helm install my-release charts/openev-data-mcp -f ci/external-qdrant-values.yaml + +mcp: + config: + embedding: + existingSecret: openev-mcp-gemini + +qdrant: + enabled: false + external: + host: xyz-example.eu-central.aws.cloud.qdrant.io + port: 6334 + useTls: true + existingSecret: openev-mcp-qdrant + apiKeyKey: api-key + +vectorSync: + # Re-run the sync nightly to finish an index cut short by the Gemini + # free-tier daily quota, and to pick up dataset changes. + cronJob: + enabled: true + schedule: "0 3 * * *" diff --git a/charts/openev-data-mcp/templates/NOTES.txt b/charts/openev-data-mcp/templates/NOTES.txt new file mode 100644 index 0000000..846242c --- /dev/null +++ b/charts/openev-data-mcp/templates/NOTES.txt @@ -0,0 +1,43 @@ +OpenEV Data MCP server has been deployed. + +MCP endpoint (streamable HTTP): +{{- if .Values.mcp.ingress.enabled }} +{{- range .Values.mcp.ingress.hosts }} + http{{ if $.Values.mcp.ingress.tls }}s{{ end }}://{{ .host }}{{ (first .paths).path }} +{{- end }} +{{- else }} + kubectl -n {{ .Release.Namespace }} port-forward svc/{{ include "mcp.fullname" . }} {{ .Values.mcp.service.port }}:{{ .Values.mcp.service.port }} +{{- end }} + +Database: +{{- if .Values.postgresql.cnpg.enabled }} + A dedicated PostgreSQL cluster is managed by CloudNativePG (Cluster/{{ include "mcp.postgresClusterName" . }}). + This requires the CloudNativePG operator's CRDs to already be installed in the cluster: + helm repo add cnpg https://cloudnative-pg.github.io/charts + helm upgrade --install cnpg-operator cnpg/cloudnative-pg --namespace cnpg-system --create-namespace +{{- else }} + Using the external database at {{ .Values.postgresql.external.host }}:{{ .Values.postgresql.external.port }}, + credentials from Secret/{{ .Values.postgresql.external.existingSecret }}. +{{- end }} +{{- if .Values.migration.enabled }} + Schema + seed data were applied by a post-install Job that fetched + migrations/001_initial.sql from ChargePi/openev-data-mcp@{{ include "mcp.migrationGitRef" . }}. + This only runs once, on install — bump mcp.image.tag and re-run manually + (kubectl apply / helm template | kubectl apply -f -) to pick up a newer migration. +{{- end }} + +Semantic search (search_vehicles tool): +{{- if .Values.qdrant.enabled }} + Qdrant is installed alongside this release (Service/{{ include "mcp.qdrantFullname" . }}). +{{- else }} + Using the external Qdrant at {{ .Values.qdrant.external.host }}:{{ .Values.qdrant.external.port }}. +{{- end }} +{{- if .Values.vectorSync.enabled }} + The collection "{{ .Values.mcp.config.search.collection }}" was synced by a hook Job, which re-runs on every upgrade. +{{- end }} +{{- if .Values.vectorSync.cronJob.enabled }} + CronJob/{{ include "mcp.fullname" . }}-vector-sync also re-syncs it on schedule "{{ .Values.vectorSync.cronJob.schedule }}". +{{- end }} +{{- if not (or .Values.vectorSync.enabled .Values.vectorSync.cronJob.enabled) }} + WARNING: vectorSync is disabled, so nothing fills the collection and searches return no results. +{{- end }} diff --git a/charts/openev-data-mcp/templates/_helpers.tpl b/charts/openev-data-mcp/templates/_helpers.tpl new file mode 100644 index 0000000..4d0142b --- /dev/null +++ b/charts/openev-data-mcp/templates/_helpers.tpl @@ -0,0 +1,289 @@ +{{- define "mcp.fullname" -}} +{{- printf "%s-mcp" .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "mcp.labels" -}} +app.kubernetes.io/name: mcp +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/part-of: openev-data-mcp +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{- define "mcp.selectorLabels" -}} +app.kubernetes.io/name: mcp +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{- define "mcp.serviceAccountName" -}} +{{- if .Values.mcp.serviceAccount.create -}} +{{- default (include "mcp.fullname" .) .Values.mcp.serviceAccount.name -}} +{{- else -}} +{{- default "default" .Values.mcp.serviceAccount.name -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.version" -}} +{{- .Values.mcp.image.tag | default .Chart.AppVersion -}} +{{- end -}} + +{{- define "mcp.image" -}} +{{- printf "%s:%s" .Values.mcp.image.repository (include "mcp.version" .) -}} +{{- end -}} + +{{/* +Upstream tags releases as v and publishes the image as , so the +migration matching the deployed image lives at v. +*/}} +{{- define "mcp.migrationGitRef" -}} +{{- if .Values.migration.gitRef -}} +{{- .Values.migration.gitRef -}} +{{- else -}} +{{- $version := include "mcp.version" . -}} +{{- if not (regexMatch "^[0-9]+\\.[0-9]+\\.[0-9]+" $version) -}} +{{- fail (printf "migration.gitRef is required when mcp.image.tag (%q) is not a semver release" $version) -}} +{{- end -}} +{{- printf "v%s" $version -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresClusterName" -}} +{{- default (printf "%s-postgres" .Release.Name) .Values.postgresql.cnpg.clusterName -}} +{{- end -}} + +{{/* +Connection details resolve either to the bundled CNPG Cluster's generated +"-rw" service and "-app" secret, or to postgresql.external. +*/}} +{{- define "mcp.postgresHost" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +{{- printf "%s-rw" (include "mcp.postgresClusterName" .) -}} +{{- else -}} +{{- required "postgresql.external.host is required when postgresql.cnpg.enabled is false" .Values.postgresql.external.host -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresPort" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +5432 +{{- else -}} +{{- .Values.postgresql.external.port -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresDatabase" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +{{- .Values.postgresql.cnpg.database -}} +{{- else -}} +{{- .Values.postgresql.external.database -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresSecretName" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +{{- printf "%s-app" (include "mcp.postgresClusterName" .) -}} +{{- else -}} +{{- required "postgresql.external.existingSecret is required when postgresql.cnpg.enabled is false" .Values.postgresql.external.existingSecret -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresUserKey" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +username +{{- else -}} +{{- .Values.postgresql.external.userKey -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.postgresPasswordKey" -}} +{{- if .Values.postgresql.cnpg.enabled -}} +password +{{- else -}} +{{- .Values.postgresql.external.passwordKey -}} +{{- end -}} +{{- end -}} + +{{/* +Mirrors the Qdrant subchart's own fullname logic, which its Service and API key +Secret are named after. +*/}} +{{- define "mcp.qdrantFullname" -}} +{{- if .Values.qdrant.fullnameOverride -}} +{{- .Values.qdrant.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default "qdrant" .Values.qdrant.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Connection details resolve either to the bundled Qdrant subchart's Service and +generated API key Secret, or to qdrant.external. +*/}} +{{- define "mcp.qdrantHost" -}} +{{- if .Values.qdrant.enabled -}} +{{- include "mcp.qdrantFullname" . -}} +{{- else -}} +{{- required "qdrant.external.host is required when qdrant.enabled is false" .Values.qdrant.external.host -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.qdrantPort" -}} +{{- if .Values.qdrant.enabled -}} +6334 +{{- else -}} +{{- .Values.qdrant.external.port -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.qdrantUseTls" -}} +{{- if .Values.qdrant.enabled -}} +false +{{- else -}} +{{- .Values.qdrant.external.useTls -}} +{{- end -}} +{{- end -}} + +{{/* Empty when Qdrant has no API key. */}} +{{- define "mcp.qdrantSecretName" -}} +{{- if .Values.qdrant.enabled -}} +{{- if .Values.qdrant.apiKey -}} +{{- printf "%s-apikey" (include "mcp.qdrantFullname" .) -}} +{{- end -}} +{{- else -}} +{{- .Values.qdrant.external.existingSecret -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.qdrantSecretKey" -}} +{{- if .Values.qdrant.enabled -}} +api-key +{{- else -}} +{{- .Values.qdrant.external.apiKeyKey -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.embeddingSecretName" -}} +{{- $embedding := .Values.mcp.config.embedding -}} +{{- if $embedding.existingSecret -}} +{{- $embedding.existingSecret -}} +{{- else if $embedding.apiKey -}} +{{- printf "%s-embedding" (include "mcp.fullname" .) -}} +{{- else -}} +{{- fail "mcp.config.embedding.apiKey or mcp.config.embedding.existingSecret is required (Gemini API key for semantic search)" -}} +{{- end -}} +{{- end -}} + +{{- define "mcp.embeddingSecretKey" -}} +{{- if .Values.mcp.config.embedding.existingSecret -}} +{{- .Values.mcp.config.embedding.existingSecretKey -}} +{{- else -}} +api-key +{{- end -}} +{{- end -}} + +{{/* +Environment shared by the MCP server and the vector sync jobs, which run the +same binary against the same database, Qdrant collection and embedding model. +*/}} +{{- define "mcp.env" -}} +- name: OPENEV_MCP_PORT + value: {{ .Values.mcp.service.port | quote }} +- name: OPENEV_MCP_HEALTH_PORT + value: {{ .Values.mcp.service.healthPort | quote }} +- name: OPENEV_MCP_REFRESH_INTERVAL + value: {{ .Values.mcp.config.refreshInterval | quote }} +- name: OPENEV_MCP_OBSERVABILITY_ENABLED + value: {{ .Values.mcp.config.observability.enabled | quote }} +- name: OPENEV_MCP_OBSERVABILITY_OTLP_ENDPOINT + value: {{ .Values.mcp.config.observability.otlpEndpoint | quote }} +- name: OPENEV_MCP_DATABASE_HOST + value: {{ include "mcp.postgresHost" . | quote }} +- name: OPENEV_MCP_DATABASE_PORT + value: {{ include "mcp.postgresPort" . | quote }} +- name: OPENEV_MCP_DATABASE_DBNAME + value: {{ include "mcp.postgresDatabase" . | quote }} +- name: OPENEV_MCP_DATABASE_SSL_MODE + value: {{ .Values.postgresql.sslMode | quote }} +- name: OPENEV_MCP_DATABASE_USER + valueFrom: + secretKeyRef: + name: {{ include "mcp.postgresSecretName" . }} + key: {{ include "mcp.postgresUserKey" . }} +- name: OPENEV_MCP_DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "mcp.postgresSecretName" . }} + key: {{ include "mcp.postgresPasswordKey" . }} +- name: OPENEV_MCP_QDRANT_HOST + value: {{ include "mcp.qdrantHost" . | quote }} +- name: OPENEV_MCP_QDRANT_PORT + value: {{ include "mcp.qdrantPort" . | quote }} +- name: OPENEV_MCP_QDRANT_USE_TLS + value: {{ include "mcp.qdrantUseTls" . | quote }} +{{- with include "mcp.qdrantSecretName" . }} +- name: OPENEV_MCP_QDRANT_API_KEY + valueFrom: + secretKeyRef: + name: {{ . }} + key: {{ include "mcp.qdrantSecretKey" $ }} +{{- end }} +- name: OPENEV_MCP_QDRANT_COLLECTION + value: {{ .Values.mcp.config.search.collection | quote }} +- name: OPENEV_MCP_QDRANT_SEARCH_LIMIT + value: {{ .Values.mcp.config.search.limit | quote }} +- name: OPENEV_MCP_QDRANT_MIN_SCORE + value: {{ .Values.mcp.config.search.minScore | quote }} +- name: OPENEV_MCP_EMBEDDING_API_KEY + valueFrom: + secretKeyRef: + name: {{ include "mcp.embeddingSecretName" . }} + key: {{ include "mcp.embeddingSecretKey" . }} +- name: OPENEV_MCP_EMBEDDING_MODEL + value: {{ .Values.mcp.config.embedding.model | quote }} +- name: OPENEV_MCP_EMBEDDING_DIMENSIONS + value: {{ .Values.mcp.config.embedding.dimensions | quote }} +- name: OPENEV_MCP_EMBEDDING_BATCH_SIZE + value: {{ .Values.mcp.config.embedding.batchSize | quote }} +{{- with .Values.mcp.extraEnv }} +{{ toYaml . }} +{{- end }} +{{- end -}} + +{{/* Pod spec of the vector sync Job, shared by the Helm hook and the CronJob. */}} +{{- define "mcp.vectorSyncPodSpec" -}} +restartPolicy: Never +serviceAccountName: {{ include "mcp.serviceAccountName" . }} +{{- with .Values.mcp.imagePullSecrets }} +imagePullSecrets: + {{- toYaml . | nindent 2 }} +{{- end }} +securityContext: + {{- toYaml .Values.mcp.podSecurityContext | nindent 2 }} +containers: + - name: vector-sync + image: {{ include "mcp.image" . }} + imagePullPolicy: {{ .Values.mcp.image.pullPolicy }} + command: ["/usr/local/bin/openev-data-mcp", "migrate"] + securityContext: + {{- toYaml .Values.mcp.securityContext | nindent 6 }} + env: + {{- include "mcp.env" . | nindent 6 }} + resources: + {{- toYaml .Values.vectorSync.resources | nindent 6 }} +{{- with .Values.mcp.nodeSelector }} +nodeSelector: + {{- toYaml . | nindent 2 }} +{{- end }} +{{- with .Values.mcp.affinity }} +affinity: + {{- toYaml . | nindent 2 }} +{{- end }} +{{- with .Values.mcp.tolerations }} +tolerations: + {{- toYaml . | nindent 2 }} +{{- end }} +{{- end -}} diff --git a/charts/openev-data-mcp/templates/deployment.yaml b/charts/openev-data-mcp/templates/deployment.yaml new file mode 100644 index 0000000..21a7a8a --- /dev/null +++ b/charts/openev-data-mcp/templates/deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mcp.fullname" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} +spec: + {{- if not .Values.mcp.autoscaling.enabled }} + replicas: {{ .Values.mcp.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "mcp.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "mcp.selectorLabels" . | nindent 8 }} + annotations: + # Roll the pods when the chart-managed Gemini API key changes. + checksum/embedding-secret: {{ include (print $.Template.BasePath "/embedding-secret.yaml") . | sha256sum }} + {{- with .Values.mcp.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "mcp.serviceAccountName" . }} + {{- with .Values.mcp.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.mcp.podSecurityContext | nindent 8 }} + containers: + - name: mcp + image: {{ include "mcp.image" . }} + imagePullPolicy: {{ .Values.mcp.image.pullPolicy }} + securityContext: + {{- toYaml .Values.mcp.securityContext | nindent 12 }} + ports: + - name: http + containerPort: {{ .Values.mcp.service.port }} + protocol: TCP + - name: health + containerPort: {{ .Values.mcp.service.healthPort }} + protocol: TCP + env: + {{- include "mcp.env" . | nindent 12 }} + {{- with .Values.mcp.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.mcp.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.mcp.resources | nindent 12 }} + {{- with .Values.mcp.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.mcp.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.mcp.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/openev-data-mcp/templates/embedding-secret.yaml b/charts/openev-data-mcp/templates/embedding-secret.yaml new file mode 100644 index 0000000..91a6a3f --- /dev/null +++ b/charts/openev-data-mcp/templates/embedding-secret.yaml @@ -0,0 +1,11 @@ +{{- if and .Values.mcp.config.embedding.apiKey (not .Values.mcp.config.embedding.existingSecret) }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "mcp.embeddingSecretName" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} +type: Opaque +data: + api-key: {{ .Values.mcp.config.embedding.apiKey | b64enc | quote }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/hpa.yaml b/charts/openev-data-mcp/templates/hpa.yaml new file mode 100644 index 0000000..63df937 --- /dev/null +++ b/charts/openev-data-mcp/templates/hpa.yaml @@ -0,0 +1,30 @@ +{{- if .Values.mcp.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "mcp.fullname" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "mcp.fullname" . }} + minReplicas: {{ .Values.mcp.autoscaling.minReplicas }} + maxReplicas: {{ .Values.mcp.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.mcp.autoscaling.targetCPUUtilizationPercentage }} + {{- if .Values.mcp.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.mcp.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/ingress.yaml b/charts/openev-data-mcp/templates/ingress.yaml new file mode 100644 index 0000000..e1cad91 --- /dev/null +++ b/charts/openev-data-mcp/templates/ingress.yaml @@ -0,0 +1,35 @@ +{{- if .Values.mcp.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "mcp.fullname" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} + {{- with .Values.mcp.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.mcp.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- with .Values.mcp.ingress.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.mcp.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "mcp.fullname" $ }} + port: + number: {{ $.Values.mcp.service.port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/migration-configmap.yaml b/charts/openev-data-mcp/templates/migration-configmap.yaml new file mode 100644 index 0000000..91e6716 --- /dev/null +++ b/charts/openev-data-mcp/templates/migration-configmap.yaml @@ -0,0 +1,38 @@ +{{- if .Values.migration.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "mcp.fullname" . }}-migrate + labels: + {{- include "mcp.labels" . | nindent 4 }} + annotations: + # -- post-install only: migrations/001_initial.sql is a one-time schema + + # seed bootstrap (mirrors Postgres' own docker-entrypoint-initdb.d and + # CNPG's postInitApplicationSQLRefs, which also only run once, against an + # empty database). Re-running it via post-upgrade would fail on + # already-applied migrations. Bump mcp.image.tag and re-apply manually + # if you need to pick up a newer upstream migration. + "helm.sh/hook": post-install + "helm.sh/hook-weight": "0" + "helm.sh/hook-delete-policy": before-hook-creation +data: + migrate.sh: | + #!/bin/sh + set -eu + + export PGPASSWORD="${DB_PASSWORD}" + + echo "Waiting for ${DB_HOST}:${DB_PORT} to accept connections..." + until pg_isready -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USER}" -d "${DB_NAME}" >/dev/null 2>&1; do + sleep 2 + done + + MIGRATION_URL="https://raw.githubusercontent.com/ChargePi/openev-data-mcp/${GIT_REF}/migrations/001_initial.sql" + echo "Fetching migration from ${MIGRATION_URL}" + wget -qO /tmp/001_initial.sql "${MIGRATION_URL}" + + echo "Applying migration to ${DB_NAME}@${DB_HOST}:${DB_PORT}" + psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USER}" -d "${DB_NAME}" -v ON_ERROR_STOP=1 -f /tmp/001_initial.sql + + echo "Migration applied." +{{- end }} diff --git a/charts/openev-data-mcp/templates/migration-job.yaml b/charts/openev-data-mcp/templates/migration-job.yaml new file mode 100644 index 0000000..91be85e --- /dev/null +++ b/charts/openev-data-mcp/templates/migration-job.yaml @@ -0,0 +1,55 @@ +{{- if .Values.migration.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "mcp.fullname" . }}-migrate + labels: + {{- include "mcp.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + backoffLimit: {{ .Values.migration.backoffLimit }} + activeDeadlineSeconds: {{ .Values.migration.activeDeadlineSeconds }} + template: + metadata: + labels: + # Not the mcp selector labels: the Service would route traffic to this pod. + app.kubernetes.io/name: mcp-migrate + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + restartPolicy: Never + containers: + - name: migrate + image: "{{ .Values.migration.image.repository }}:{{ .Values.migration.image.tag }}" + imagePullPolicy: {{ .Values.migration.image.pullPolicy }} + command: ["/bin/sh", "/scripts/migrate.sh"] + env: + - name: DB_HOST + value: {{ include "mcp.postgresHost" . | quote }} + - name: DB_PORT + value: {{ include "mcp.postgresPort" . | quote }} + - name: DB_NAME + value: {{ include "mcp.postgresDatabase" . | quote }} + - name: GIT_REF + value: {{ include "mcp.migrationGitRef" . | quote }} + - name: DB_USER + valueFrom: + secretKeyRef: + name: {{ include "mcp.postgresSecretName" . }} + key: {{ include "mcp.postgresUserKey" . }} + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "mcp.postgresSecretName" . }} + key: {{ include "mcp.postgresPasswordKey" . }} + volumeMounts: + - name: migrate-script + mountPath: /scripts + volumes: + - name: migrate-script + configMap: + name: {{ include "mcp.fullname" . }}-migrate + defaultMode: 0755 +{{- end }} diff --git a/charts/openev-data-mcp/templates/postgres-cluster.yaml b/charts/openev-data-mcp/templates/postgres-cluster.yaml new file mode 100644 index 0000000..36ffcf5 --- /dev/null +++ b/charts/openev-data-mcp/templates/postgres-cluster.yaml @@ -0,0 +1,30 @@ +{{- if .Values.postgresql.cnpg.enabled }} +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: {{ include "mcp.postgresClusterName" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} +spec: + instances: {{ .Values.postgresql.cnpg.instances }} + {{- with .Values.postgresql.cnpg.imageName }} + imageName: {{ . }} + {{- end }} + storage: + size: {{ .Values.postgresql.cnpg.storage.size }} + {{- with .Values.postgresql.cnpg.storage.storageClass }} + storageClass: {{ . }} + {{- end }} + {{- with .Values.postgresql.cnpg.resources }} + resources: + {{- toYaml . | nindent 4 }} + {{- end }} + bootstrap: + initdb: + database: {{ .Values.postgresql.cnpg.database | quote }} + owner: {{ .Values.postgresql.cnpg.database | quote }} + {{- with .Values.postgresql.cnpg.postgresql }} + postgresql: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/service.yaml b/charts/openev-data-mcp/templates/service.yaml new file mode 100644 index 0000000..586ad61 --- /dev/null +++ b/charts/openev-data-mcp/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "mcp.fullname" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} +spec: + type: {{ .Values.mcp.service.type }} + ports: + - port: {{ .Values.mcp.service.port }} + targetPort: http + protocol: TCP + name: http + - port: {{ .Values.mcp.service.healthPort }} + targetPort: health + protocol: TCP + name: health + selector: + {{- include "mcp.selectorLabels" . | nindent 4 }} diff --git a/charts/openev-data-mcp/templates/serviceaccount.yaml b/charts/openev-data-mcp/templates/serviceaccount.yaml new file mode 100644 index 0000000..0249afa --- /dev/null +++ b/charts/openev-data-mcp/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.mcp.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "mcp.serviceAccountName" . }} + labels: + {{- include "mcp.labels" . | nindent 4 }} + {{- with .Values.mcp.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/vector-sync-cronjob.yaml b/charts/openev-data-mcp/templates/vector-sync-cronjob.yaml new file mode 100644 index 0000000..56b9f49 --- /dev/null +++ b/charts/openev-data-mcp/templates/vector-sync-cronjob.yaml @@ -0,0 +1,27 @@ +{{- if .Values.vectorSync.cronJob.enabled }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "mcp.fullname" . }}-vector-sync + labels: + {{- include "mcp.labels" . | nindent 4 }} + app.kubernetes.io/component: vector-sync +spec: + schedule: {{ .Values.vectorSync.cronJob.schedule | quote }} + # -- Two syncs writing the same collection would embed the same vehicles twice. + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: {{ .Values.vectorSync.cronJob.successfulJobsHistoryLimit }} + failedJobsHistoryLimit: {{ .Values.vectorSync.cronJob.failedJobsHistoryLimit }} + jobTemplate: + spec: + backoffLimit: {{ .Values.vectorSync.backoffLimit }} + activeDeadlineSeconds: {{ .Values.vectorSync.activeDeadlineSeconds }} + template: + metadata: + labels: + app.kubernetes.io/name: mcp-vector-sync + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: vector-sync + spec: + {{- include "mcp.vectorSyncPodSpec" . | nindent 10 }} +{{- end }} diff --git a/charts/openev-data-mcp/templates/vector-sync-job.yaml b/charts/openev-data-mcp/templates/vector-sync-job.yaml new file mode 100644 index 0000000..047a3dc --- /dev/null +++ b/charts/openev-data-mcp/templates/vector-sync-job.yaml @@ -0,0 +1,26 @@ +{{- if .Values.vectorSync.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "mcp.fullname" . }}-vector-sync + labels: + {{- include "mcp.labels" . | nindent 4 }} + app.kubernetes.io/component: vector-sync + annotations: + # -- Runs after the database migration on install (hook weight 1) and on + # every upgrade; the sync is incremental, so re-running it is cheap. + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": "2" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + backoffLimit: {{ .Values.vectorSync.backoffLimit }} + activeDeadlineSeconds: {{ .Values.vectorSync.activeDeadlineSeconds }} + template: + metadata: + labels: + app.kubernetes.io/name: mcp-vector-sync + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: vector-sync + spec: + {{- include "mcp.vectorSyncPodSpec" . | nindent 6 }} +{{- end }} diff --git a/charts/openev-data-mcp/values.yaml b/charts/openev-data-mcp/values.yaml new file mode 100644 index 0000000..da59d28 --- /dev/null +++ b/charts/openev-data-mcp/values.yaml @@ -0,0 +1,244 @@ +# Default values for the openev-data-mcp chart. + +## @section mcp +## The openev-data-mcp server itself: exposes EV specs from a PostgreSQL database +## over the Model Context Protocol (streamable HTTP). +mcp: + replicaCount: 1 + + image: + repository: ghcr.io/chargepi/openev-data-mcp + # -- Overrides the image tag, which defaults to the chart's appVersion. Also + # selects the migration ref (v) unless migration.gitRef is set. + tag: "" + pullPolicy: IfNotPresent + + imagePullSecrets: [] + + service: + type: ClusterIP + # -- MCP (streamable HTTP) port. + port: 8080 + # -- gRPC health-check port (probed with the grpc_health_probe binary + # baked into the image, since the app has no HTTP health endpoint). + healthPort: 9090 + + # -- Application configuration, rendered into the container's OPENEV_MCP_* env vars. + config: + # -- How often the server's in-memory resource cache refreshes from the database. + refreshInterval: 5m + + observability: + enabled: false + # -- OTLP gRPC collector endpoint, e.g. "otel-collector.observability:4317". + otlpEndpoint: "" + + # -- Semantic search (the search_vehicles tool) over the Qdrant collection + # populated by the vector sync job. + search: + # -- Qdrant collection holding one embedded document per vehicle. + collection: ev_vehicles + # -- Maximum number of vehicles returned per search. + limit: 10 + # -- Matches below this cosine similarity are discarded. + minScore: 0.6 + + # -- Gemini embeddings, used to index vehicles and to embed search queries. + embedding: + # -- Gemini API key. Ignored when existingSecret is set; otherwise the + # chart stores it in a Secret. One of the two is required. + apiKey: "" + # -- Name of an existing Secret holding the Gemini API key. + existingSecret: "" + existingSecretKey: api-key + model: gemini-embedding-001 + # -- Vector size. Changing it requires deleting the collection, since the + # sync refuses to mix dimensions. + dimensions: 768 + # -- Texts per embedding request (Gemini allows at most 100). + batchSize: 100 + + extraEnv: [] + # - name: SOME_EXTRA_VAR + # value: "value" + + livenessProbe: + exec: + command: ["/usr/local/bin/grpc_health_probe", "-addr=:9090"] + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + exec: + command: ["/usr/local/bin/grpc_health_probe", "-addr=:9090"] + initialDelaySeconds: 5 + periodSeconds: 10 + + resources: {} + # limits: + # cpu: 500m + # memory: 256Mi + # requests: + # cpu: 100m + # memory: 128Mi + + serviceAccount: + create: true + annotations: {} + name: "" + + podAnnotations: {} + podSecurityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] + readOnlyRootFilesystem: false + + nodeSelector: {} + tolerations: [] + affinity: {} + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 5 + targetCPUUtilizationPercentage: 80 + # -- Set to a number to also scale on memory utilization; leave empty/0 to disable. + targetMemoryUtilizationPercentage: 80 + + ingress: + enabled: false + className: "" + annotations: {} + hosts: + - host: openev-mcp.local + paths: + - path: / + pathType: Prefix + tls: [] + +## @section postgresql +## openev-data-mcp requires PostgreSQL. This chart does NOT vendor a PostgreSQL +## Helm chart as a Chart.yaml dependency: Bitnami's postgresql chart (the usual +## default) had its free OCI images frozen in 2025, and a bundled operator +## subchart would tie a cluster-scoped operator + CRDs to this release's +## lifecycle. Instead it targets the CloudNativePG operator +## (https://cloudnative-pg.io), which must already be installed once per +## cluster (typically by a platform team, not per application release): +## +## helm repo add cnpg https://cloudnative-pg.github.io/charts +## helm upgrade --install cnpg-operator cnpg/cloudnative-pg \ +## --namespace cnpg-system --create-namespace +postgresql: + # -- Connection SSL mode, used whether postgresql.cnpg or postgresql.external is active. + sslMode: disable + + cnpg: + # -- Provision a dedicated Postgres cluster for this release via a CNPG + # `Cluster` resource. Requires the CloudNativePG operator (and its CRDs) + # to already be installed in the cluster. Set to false and configure + # postgresql.external instead to use a database you manage yourself. + enabled: true + # -- Defaults to "-postgres" when empty. + clusterName: "" + instances: 1 + # -- Defaults to the operator's own default PostgreSQL image when empty. + imageName: "" + # -- Name of the application database (and its owner role) created at bootstrap. + database: openevdata + storage: + size: 1Gi + storageClass: "" + resources: {} + # -- Passed through verbatim to Cluster.spec.postgresql (extra postgresql.conf + # parameters, pg_hba rules, etc). See the CNPG Cluster CRD reference. + postgresql: {} + + # -- Used instead of postgresql.cnpg when postgresql.cnpg.enabled is false, to + # point at a database you manage yourself (a CNPG cluster in another + # namespace, RDS, a shared on-prem instance, etc). + external: + host: "" + port: 5432 + database: openevdata + # -- Name of an existing Secret with the connection credentials. + existingSecret: "" + userKey: username + passwordKey: password + +## @section migration +## openev-data-mcp does not run its schema migration on startup. This applies +## migrations/001_initial.sql (schema + seed data) via a post-install-only Job +## (it does not re-run on upgrade — see README), fetched at deploy time from +## the project's GitHub repository at the release matching the deployed image +## rather than vendored into this chart (mirrors how api.database.fetch works +## in the open-ev-data chart). +migration: + enabled: true + # -- Overrides the git ref (tag/branch/sha) to fetch migrations/001_initial.sql + # from. Defaults to v; required when mcp.image.tag isn't a + # semver release (e.g. "latest" or a sha). + gitRef: "" + image: + repository: postgres + tag: "17-alpine" + pullPolicy: IfNotPresent + backoffLimit: 5 + # -- Generous default to cover a first-time CNPG cluster bootstrap (image + # pull + volume provisioning + initdb) before the migration Job gives up. + activeDeadlineSeconds: 600 + +## @section qdrant +## Vector database for semantic search. By default the official Qdrant chart +## (https://github.com/qdrant/qdrant-helm) is installed as a dependency; every +## key below except `external` is passed through to it, see its values.yaml. +qdrant: + # -- Install Qdrant alongside this release. Set to false and configure + # qdrant.external to use a Qdrant you manage yourself (e.g. Qdrant Cloud). + enabled: true + # -- Generate an API key, kept across upgrades in the "-apikey" + # Secret, which the MCP server and the vector sync job read. + apiKey: true + persistence: + size: 1Gi + + # -- Used instead of the bundled Qdrant when qdrant.enabled is false. + external: + host: "" + # -- gRPC port. + port: 6334 + useTls: false + # -- Name of an existing Secret with the Qdrant API key; leave empty if the + # instance has no authentication. + existingSecret: "" + apiKeyKey: api-key + +## @section vectorSync +## Runs `openev-data-mcp migrate`, which provisions the Qdrant collection and +## embeds new or changed vehicles (unchanged ones are skipped, removed ones +## deleted), so it is safe to re-run. +vectorSync: + # -- Run the sync as a Helm hook on install (after the database migration) + # and on every upgrade. Helm waits for it, so a failed sync fails the + # release; on the Gemini free tier the first sync of the full dataset can + # exceed the daily quota, so either use a paid key, or disable this and rely + # on the CronJob below. + enabled: true + backoffLimit: 3 + # -- Covers embedding the full dataset, including waits for per-minute + # rate limits on the Gemini free tier. + activeDeadlineSeconds: 3600 + resources: {} + + # -- Also re-run the sync on a schedule, e.g. to finish an initial index + # that hit the free-tier daily quota, or to pick up dataset changes. + cronJob: + enabled: false + schedule: "0 3 * * *" + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 1 From 040cd3630f5ad123c5db8d145d79bc65c449ece9 Mon Sep 17 00:00:00 2001 From: xBlaz3kx Date: Thu, 15 Oct 2026 20:08:46 +0200 Subject: [PATCH 2/2] fix: default openev-data-mcp image tag to v Upstream releases publish the image under the git tag (v1.0.0), not the bare semver, so the default image ghcr.io/chargepi/openev-data-mcp:1.0.0 did not exist and installs never became ready. The migration ref now follows the image tag, accepting it with or without the v prefix. --- charts/openev-data-mcp/README.md | 8 ++++---- charts/openev-data-mcp/templates/_helpers.tpl | 14 +++++++++----- charts/openev-data-mcp/values.yaml | 9 +++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/charts/openev-data-mcp/README.md b/charts/openev-data-mcp/README.md index 080154f..a28a2ea 100644 --- a/charts/openev-data-mcp/README.md +++ b/charts/openev-data-mcp/README.md @@ -61,7 +61,7 @@ key in a Secret of its own. `openev-data-mcp` does not run its schema migration on startup — it just connects. This chart applies the upstream project's `migrations/001_initial.sql` (schema + seed data) via a **post-install-only** Job that fetches the file from `raw.githubusercontent.com/ChargePi/openev-data-mcp` at the release tag -matching the deployed image (`v`, defaulting to the chart's `appVersion`), the same way +matching the deployed image (the `mcp.image.tag` git tag, defaulting to `v`), the same way `api.database.fetch` in the sibling `open-ev-data` chart fetches its dataset — rather than vendoring the SQL into this chart, so the schema always matches the server version. @@ -106,7 +106,7 @@ without a Helm upgrade. | Key | Description | Default | |---|---|---| | `mcp.replicaCount` | Replica count | `1` | -| `mcp.image.repository` / `mcp.image.tag` | MCP server image; `tag` defaults to the chart's `appVersion` | `ghcr.io/chargepi/openev-data-mcp` / `""` | +| `mcp.image.repository` / `mcp.image.tag` | MCP server image; `tag` defaults to `v`, the release's git tag | `ghcr.io/chargepi/openev-data-mcp` / `""` | | `mcp.service.port` | MCP (streamable HTTP) port | `8080` | | `mcp.service.healthPort` | gRPC health-check port (probed via the `grpc_health_probe` binary baked into the image) | `9090` | | `mcp.config.refreshInterval` | How often the in-memory resource cache refreshes from the database | `5m` | @@ -118,7 +118,7 @@ without a Helm upgrade. | `postgresql.cnpg.storage.size` | PVC size for the CNPG cluster | `1Gi` | | `postgresql.external.*` | Connection details for a database you manage yourself, used when `postgresql.cnpg.enabled: false` | — | | `migration.enabled` | Run the post-install schema/seed Job | `true` | -| `migration.gitRef` | Override the git ref to fetch `migrations/001_initial.sql` from; required if `mcp.image.tag` isn't a semver release | `""` (`v`) | +| `migration.gitRef` | Override the git ref to fetch `migrations/001_initial.sql` from; required if `mcp.image.tag` isn't a semver release | `""` (the image tag) | | `mcp.config.embedding.apiKey` / `mcp.config.embedding.existingSecret` | Gemini API key, inline or from an existing Secret (key `existingSecretKey`); one is required | `""` / `""` | | `mcp.config.embedding.model` / `mcp.config.embedding.dimensions` | Embedding model and vector size; changing the size requires deleting the collection | `gemini-embedding-001` / `768` | | `mcp.config.search.collection` | Qdrant collection name | `ev_vehicles` | @@ -136,7 +136,7 @@ See `values.yaml` for the full set of options (resources, security contexts, nod ## Upgrading the MCP server ```console -helm upgrade my-release charts/openev-data-mcp --set mcp.image.tag=1.0.0 +helm upgrade my-release charts/openev-data-mcp --set mcp.image.tag=v1.0.0 ``` The database migration Job does not re-run on upgrade (see above); the `mcp` Deployment rolls and the diff --git a/charts/openev-data-mcp/templates/_helpers.tpl b/charts/openev-data-mcp/templates/_helpers.tpl index 4d0142b..770ad85 100644 --- a/charts/openev-data-mcp/templates/_helpers.tpl +++ b/charts/openev-data-mcp/templates/_helpers.tpl @@ -22,8 +22,12 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end -}} {{- end -}} +{{/* +Upstream publishes images tagged with the release's git tag (v), while +the chart's appVersion is plain semver. +*/}} {{- define "mcp.version" -}} -{{- .Values.mcp.image.tag | default .Chart.AppVersion -}} +{{- .Values.mcp.image.tag | default (printf "v%s" .Chart.AppVersion) -}} {{- end -}} {{- define "mcp.image" -}} @@ -31,18 +35,18 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end -}} {{/* -Upstream tags releases as v and publishes the image as , so the -migration matching the deployed image lives at v. +Image tags are the release's git tag, so the migration matching the deployed +image lives at that same ref (a tag given without the "v" prefix gets one). */}} {{- define "mcp.migrationGitRef" -}} {{- if .Values.migration.gitRef -}} {{- .Values.migration.gitRef -}} {{- else -}} {{- $version := include "mcp.version" . -}} -{{- if not (regexMatch "^[0-9]+\\.[0-9]+\\.[0-9]+" $version) -}} +{{- if not (regexMatch "^v?[0-9]+\\.[0-9]+\\.[0-9]+" $version) -}} {{- fail (printf "migration.gitRef is required when mcp.image.tag (%q) is not a semver release" $version) -}} {{- end -}} -{{- printf "v%s" $version -}} +{{- printf "v%s" (trimPrefix "v" $version) -}} {{- end -}} {{- end -}} diff --git a/charts/openev-data-mcp/values.yaml b/charts/openev-data-mcp/values.yaml index da59d28..8ce60b8 100644 --- a/charts/openev-data-mcp/values.yaml +++ b/charts/openev-data-mcp/values.yaml @@ -8,8 +8,9 @@ mcp: image: repository: ghcr.io/chargepi/openev-data-mcp - # -- Overrides the image tag, which defaults to the chart's appVersion. Also - # selects the migration ref (v) unless migration.gitRef is set. + # -- Overrides the image tag, which defaults to v (images + # are tagged with the release's git tag). Also selects the migration ref + # unless migration.gitRef is set. tag: "" pullPolicy: IfNotPresent @@ -181,8 +182,8 @@ postgresql: migration: enabled: true # -- Overrides the git ref (tag/branch/sha) to fetch migrations/001_initial.sql - # from. Defaults to v; required when mcp.image.tag isn't a - # semver release (e.g. "latest" or a sha). + # from. Defaults to the image tag (v); required when mcp.image.tag + # isn't a semver release (e.g. "latest" or a sha). gitRef: "" image: repository: postgres