generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-2532 Daily job to delete semantic search indices
to reduce Bedrock costs
- Loading branch information
1 parent
cf09ead
commit 85c5fc2
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
projects/person-search-index-from-delius/deploy/templates/contact-index-deletion-cronjob.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
- apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: contact-index-deletion-script | ||
data: | ||
script.sh: | | ||
#!/bin/bash | ||
set -euo pipefail | ||
curl -fsSL "$OPENSEARCH_URL/_cat/indices?format=json" \ | ||
| jq -r '.[].index' \ | ||
| grep '^contact-semantic-search' \ | ||
| xargs -I{} sh -c 'echo "Deleting {}..." && curl -fsSL -XDELETE "$OPENSEARCH_URL/{}"' | ||
- apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: contact-index-deletion | ||
spec: | ||
schedule: 0 5 * * 1-5 # Every weekday at 5am UTC | ||
concurrencyPolicy: Replace | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: person-search-index-from-delius | ||
volumes: | ||
- name: script-volume | ||
configMap: | ||
name: contact-index-deletion-script | ||
containers: | ||
- name: contact-index-deletion | ||
image: "ghcr.io/ministryofjustice/hmpps-devops-tools:latest" | ||
command: [ "bash", "/script.sh" ] | ||
volumeMounts: | ||
- name: script-volume | ||
mountPath: /script.sh | ||
subPath: script.sh | ||
env: | ||
- name: OPENSEARCH_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: person-search-index-from-delius-opensearch | ||
key: url | ||
optional: false | ||
securityContext: | ||
capabilities: | ||
drop: | ||
- ALL | ||
runAsNonRoot: true | ||
allowPrivilegeEscalation: false | ||
seccompProfile: | ||
type: RuntimeDefault | ||
restartPolicy: Never |