Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .github/workflows/build_helm_charts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ jobs:
- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
working-directory: .
run: ct install --config .github/linters/ct.yaml
# hapi-fhir is linted but not installed: it has no templating, so it cannot be
# scaled to zero for CI, and its pods need the hapi-fhir-db Secret, which is
# created outside the chart.
run: ct install --config .github/linters/ct.yaml --excluded-charts hapi-fhir

helm-publish:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"deployment/charts/ocr-service": "0.1.0",
"deployment/charts/nifi": "0.0.0",
"deployment/charts/nginx": "0.0.0",
"deployment/charts/hapi-fhir": "0.0.0",
"deployment/terraform/openstack-kubernetes-k3s": "0.1.4",
"apps/cohorter": "0.0.1",
"apps/nifi": "2.0.6",
Expand Down
10 changes: 10 additions & 0 deletions deployment/charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Existing deployments must reload `nifi-auth` for NGINX before upgrading.
OpenSearch upgrades also require the bootstrap Secret and preparation of
administrative access when using an admin certificate. [OpenSearch upgrade details](opensearch/README.md#install)

## HAPI FHIR

`hapi-fhir/` runs a HAPI FHIR JPA server (R4) with PostgreSQL and its own single-node
OpenSearch for full-text search. Its manifests are plain Kubernetes YAML with
no Helm templating and no values. It needs the `hapi-fhir-db` Secret before
installation. [HAPI FHIR chart](hapi-fhir/README.md)

## Chart development

```bash
Expand Down Expand Up @@ -71,6 +78,9 @@ can validate Kubernetes resource installation without deployment-owned
ConfigMaps and Secrets. Application startup and TLS checks require a separate
runtime test with those inputs supplied.

The HAPI FHIR chart has no values, so it cannot be scaled to zero. CI lints it
and skips the install test, because its pods need the `hapi-fhir-db` Secret.

To package locally, keep generated archives outside the source tree:

```bash
Expand Down
14 changes: 14 additions & 0 deletions deployment/charts/hapi-fhir/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: hapi-fhir
description: HAPI FHIR JPA server (R4) with PostgreSQL and OpenSearch full-text search
type: application
version: 0.1.0
appVersion: "v8.12.0-2"

home: https://docs.cogstack.org/
sources:
- https://github.com/CogStack/cogstack-platform
- https://github.com/hapifhir/hapi-fhir-jpaserver-starter
maintainers:
- name: mooperd
icon: "https://avatars.githubusercontent.com/u/28688163"
105 changes: 105 additions & 0 deletions deployment/charts/hapi-fhir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# CogStack HAPI FHIR Helm chart

A [HAPI FHIR](https://hapifhir.io/) JPA server (FHIR R4) with PostgreSQL as the
resource store and a single-node OpenSearch as its full-text index, which is
what answers `_text` and `_content` searches. Every other search stays in
PostgreSQL, so a search straight after a write still sees it.

| Workload | Image | Service | Storage |
| --- | --- | --- | --- |
| `hapi-fhir` | `hapiproject/hapi:v8.12.0-2` | `hapi-fhir:8080` | none |
| `hapi-fhir-db` | `postgres:16-alpine` | `hapi-fhir-db:5432` | 10Gi PVC |
| `hapi-fhir-opensearch` | `opensearchproject/opensearch:3.9.0` | `hapi-fhir-opensearch:9200` | 10Gi PVC |

## No templating

The files in `templates/` are plain Kubernetes YAML. They contain no Helm
template expressions, and the chart has no values: `helm template` prints them
as they are written. Helm packages, versions, installs and removes the chart,
and nothing else.

This has three consequences.

- **Fixed names.** Resource names do not include the release name, so install
one release per namespace.
- **No `--set`.** To change an image, a size or a setting, edit the manifests
(or post-process them with `helm template | kustomize`).
- **No automatic restart on a configuration change.** HAPI reads the
`hapi-fhir-config` ConfigMap only at startup. After an upgrade that changes
it, run `kubectl rollout restart deployment/hapi-fhir`.

## Install

The chart does not contain the database password. Create the `hapi-fhir-db`
Secret first, in the namespace you install into. Keep it across upgrades:
PostgreSQL sets the password only when it first initialises its volume.

```bash
kubectl create namespace cogstack
kubectl -n cogstack create secret generic hapi-fhir-db \
--from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)"
helm upgrade --install hapi-fhir deployment/charts/hapi-fhir -n cogstack \
--wait --timeout 15m
```

HAPI waits for PostgreSQL and OpenSearch, then migrates its schema. The
first start takes a few minutes.

## Access

The chart creates only ClusterIP Services. It has no Ingress or HTTPRoute,
because a hostname cannot be set without templating. PostgreSQL and
OpenSearch are meant to stay inside the cluster; the OpenSearch container
uninstalls its security plugin at startup, so it runs without authentication
and needs no certificates.

```bash
kubectl -n cogstack port-forward svc/hapi-fhir 8080:8080
curl http://localhost:8080/fhir/metadata
curl 'http://localhost:8080/fhir/Patient?_text=x&_summary=count'
```

The second request answers `400` (`HAPI-1192`) if HAPI is not using
OpenSearch.

To publish the server, route your own Ingress or Gateway API HTTPRoute to the
`hapi-fhir` Service on port `8080`. HAPI builds its links from the
`X-Forwarded-*` headers the proxy sends.

If resources were stored before OpenSearch was attached, index them once:

```bash
curl -X POST 'http://localhost:8080/fhir/$reindex' \
-H 'Content-Type: application/fhir+json' \
-d '{"resourceType":"Parameters"}'
```

## OpenSearch and HAPI

HAPI reaches OpenSearch through Hibernate Search, whose backend type is named
`elasticsearch` in the configuration. Two things follow from using OpenSearch
there.

- **No `spring.elasticsearch` settings.** They make HAPI start its Elasticsearch
Java client, which OpenSearch rejects with `406 Not Acceptable`, and HAPI then
fails to start. That client serves only the `$lastn` operation, so `$lastn`
is not available with this chart.
- **A version warning at startup.** Hibernate Search 7.2 in HAPI v8.12.0 logs
`HSEARCH400085: Unknown Elasticsearch version running on the cluster:
'opensearch:3.9.0'`. Indexing, `_text`, `_content` and `$reindex` work.

## Sizing

OpenSearch runs with a 512 MB heap and a 1200Mi memory limit, and uses
`node.store.allow_mmap=false` so the nodes need no `vm.max_map_count` change.
PostgreSQL is tuned for about 2 GB of memory. These suit a small shared
cluster; edit the manifests for anything larger.

## Remove

```bash
helm uninstall hapi-fhir -n cogstack
```

This deletes the PersistentVolumeClaims, and with them the data. The
`hapi-fhir-db` Secret is yours to delete.
181 changes: 181 additions & 0 deletions deployment/charts/hapi-fhir/templates/hapi-fhir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# HAPI FHIR JPA server (R4).
# The ConfigMap is merged on top of the application.yaml in the image.
apiVersion: v1
kind: ConfigMap
metadata:
name: hapi-fhir-config
data:
application.yaml: |
spring:
# No spring.elasticsearch block: it would make HAPI start its Elasticsearch Java
# client (used only for $lastn), which OpenSearch rejects with 406. Hibernate
# Search has its own client, configured under backend below, and that one works
# with OpenSearch. Its backend type is still called elasticsearch.
datasource:
hikari:
maximum-pool-size: 30
jpa:
properties:
hibernate:
search:
enabled: true
schema_management:
strategy: CREATE
backend:
type: elasticsearch
hosts: hapi-fhir-opensearch:9200
protocol: http
layout:
strategy: ca.uhn.fhir.jpa.search.elastic.IndexNamePrefixLayoutStrategy
analysis:
configurer: ca.uhn.fhir.jpa.search.HapiHSearchAnalysisConfigurers$HapiElasticsearchAnalysisConfigurer
scroll_timeout: 60
dynamic_mapping: true
schema_management:
settings_file: ca/uhn/fhir/jpa/elastic/index-settings.json
minimal_required_status: YELLOW
minimal_required_status_wait_timeout: 10000
hapi:
fhir:
# _text / _content indexing (off by default since HAPI FHIR 8.0)
search_index_full_text_enabled: true
# false: OpenSearch answers only _text / _content, and every other search stays
# in PostgreSQL, so a search straight after a write still sees it.
# true also indexes and answers ordinary search parameters in
# OpenSearch, which lags a write by its refresh interval.
advanced_lucene_indexing: false
store_resource_in_lucene_index_enabled: false
# Never reuse a cached search: timings measure the search, not the cache.
reuse_cached_search_results_millis: 0
allow_contains_searches: true
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hapi-fhir
spec:
replicas: 1
strategy:
type: Recreate # a new version migrates the schema — never two versions at once
selector:
matchLabels:
app: hapi-fhir
template:
metadata:
labels:
app: hapi-fhir
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
initContainers:
- name: wait-for-db
image: postgres:16-alpine
command: ["/bin/sh", "-c"]
args:
- |
until pg_isready -h hapi-fhir-db -p 5432 -U fhir; do
echo "waiting for postgres..."; sleep 5;
done
- name: wait-for-opensearch
image: postgres:16-alpine # for its busybox wget; the HAPI image has no shell
command: ["/bin/sh", "-c"]
args:
- |
until wget -q -O /dev/null "http://hapi-fhir-opensearch:9200/_cluster/health?wait_for_status=yellow&timeout=5s"; do
echo "waiting for opensearch..."; sleep 5;
done
containers:
- name: hapi-fhir
# distroless flavour
# (Docker Hub tags carry a -N release suffix; bare v8.12.0 does not exist)
image: hapiproject/hapi:v8.12.0-2
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
ports:
- name: http
containerPort: 8080
- name: http-metrics
containerPort: 8081
env:
# --- FHIR version: R4 (hapi-fhir-structures-r4) ---
- name: HAPI_FHIR_FHIR_VERSION
value: R4
# --- database wiring (mirrors the hapi-fhir-jpaserver chart) ---
- name: SPRING_DATASOURCE_URL
value: jdbc:postgresql://hapi-fhir-db:5432/fhir
- name: SPRING_DATASOURCE_USERNAME
value: fhir
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: hapi-fhir-db
key: POSTGRES_PASSWORD
- name: SPRING_DATASOURCE_DRIVERCLASSNAME
value: org.postgresql.Driver
- name: spring.jpa.properties.hibernate.dialect
value: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgresDialect
# --- OpenSearch and search settings: the hapi-fhir-config ConfigMap ---
- name: SPRING_CONFIG_ADDITIONAL_LOCATION
value: file:/config/
- name: HAPI_FHIR_USE_APACHE_ADDRESS_STRATEGY
value: "true"
- name: MANAGEMENT_SERVER_PORT
value: "8081"
- name: MANAGEMENT_ENDPOINT_HEALTH_PROBES_ADD_ADDITIONAL_PATHS
value: "true"
- name: MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE
value: "health,prometheus"
startupProbe:
httpGet:
path: /readyz
port: http
failureThreshold: 30
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /readyz
port: http
periodSeconds: 20
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /livez
port: http
periodSeconds: 20
timeoutSeconds: 10
volumeMounts:
- name: tmp
mountPath: /tmp
- name: lucene
mountPath: /app/target
- name: config
mountPath: /config
readOnly: true
volumes:
- name: config
configMap:
name: hapi-fhir-config
- name: tmp
emptyDir: {}
- name: lucene
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: hapi-fhir
spec:
selector:
app: hapi-fhir
ports:
- port: 8080
targetPort: http
Loading