From 30fec04adacabc08c14ff0e39bec1ccd8fc8df92 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 25 Apr 2024 19:11:35 -0500 Subject: [PATCH] Add TM database --- .../tasking-manager-api/tm-deployment.yaml | 10 +- .../tasking-manager-db/tm-db-pd.yaml | 85 +++++++++++++++ .../tasking-manager-db/tm-db-service.yaml | 19 ++++ .../tasking-manager-db/tm-db-statefulset.yaml | 101 ++++++++++++++++++ 4 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 osm-seed/templates/tasking-manager-db/tm-db-pd.yaml create mode 100644 osm-seed/templates/tasking-manager-db/tm-db-service.yaml create mode 100644 osm-seed/templates/tasking-manager-db/tm-db-statefulset.yaml diff --git a/osm-seed/templates/tasking-manager-api/tm-deployment.yaml b/osm-seed/templates/tasking-manager-api/tm-deployment.yaml index 997cb503..362f4b61 100644 --- a/osm-seed/templates/tasking-manager-api/tm-deployment.yaml +++ b/osm-seed/templates/tasking-manager-api/tm-deployment.yaml @@ -46,15 +46,15 @@ spec: {{- end }} env: - name: POSTGRES_HOST - value: {{ .Values.tmApi.env.POSTGRES_HOST }} + value: {{ .Release.Name }}-tm-db - name: POSTGRES_DB - value: {{ .Values.tmApi.env.POSTGRES_DB }} + value: {{ .Values.tmDb.env.POSTGRES_DB }} - name: POSTGRES_PASSWORD - value: {{ quote .Values.tmApi.env.POSTGRES_PASSWORD }} + value: {{ quote .Values.tmDb.env.POSTGRES_PASSWORD }} - name: POSTGRES_USER - value: {{ .Values.tmApi.env.POSTGRES_USER }} + value: {{ .Values.tmDb.env.POSTGRES_USER }} - name: POSTGRES_PORT - value: {{ .Values.tmApi.env.POSTGRES_PORT | quote }} + value: "5432" - name: TM_DB value: {{ printf "postgresql://%s:%s@%s/%s" .Values.tmApi.env.POSTGRES_USER .Values.tmApi.env.POSTGRES_PASSWORD .Values.tmApi.env.POSTGRES_HOST .Values.tmApi.env.POSTGRES_DB }} - name: TM_ORG_NAME diff --git a/osm-seed/templates/tasking-manager-db/tm-db-pd.yaml b/osm-seed/templates/tasking-manager-db/tm-db-pd.yaml new file mode 100644 index 00000000..0e05952d --- /dev/null +++ b/osm-seed/templates/tasking-manager-db/tm-db-pd.yaml @@ -0,0 +1,85 @@ +{{- if .Values.tmDb.enabled -}} +{{- if .Values.tmDb.persistenceDisk.enabled -}} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ .Release.Name }}-tm-db-pv + labels: + app: {{ template "osm-seed.name" . }} + component: tm-db-pd + environment: {{ .Values.environment }} + release: {{ .Release.Name }} +spec: + ############## Minikube ############## + {{- if eq .Values.cloudProvider "minikube" }} + storageClassName: local-storage + capacity: + storage: {{ .Values.tmDb.persistenceDisk.localVolumeSize }} + accessModes: + - ReadWriteOnce + hostPath: + path: {{ .Values.tmDb.persistenceDisk.localVolumeHostPath | quote }} + {{- end }} + + ############## AWS Provider ############## + {{- if eq .Values.cloudProvider "aws" }} + storageClassName: "" + capacity: + storage: {{ .Values.tmDb.persistenceDisk.AWS_ElasticBlockStore_size }} + accessModes: + - ReadWriteOnce + awsElasticBlockStore: + volumeID: {{ .Values.tmDb.persistenceDisk.AWS_ElasticBlockStore_volumeID }} + fsType: ext4 + {{- end }} + + ############## GCP Provider ############## + {{- if eq .Values.cloudProvider "gcp" }} + storageClassName: "" + capacity: + storage: {{ .Values.tmDb.persistenceDisk.GCP_gcePersistentDisk_size }} + accessModes: + - ReadWriteOnce + gcePersistentDisk: + pdName: {{ .Values.tmDb.persistenceDisk.GCP_gcePersistentDisk_pdName }} + fsType: ext4 + {{- end }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }}-tm-db-pv-claim + labels: + app: {{ template "osm-seed.name" . }} + component: db-pd + environment: {{ .Values.environment }} + release: {{ .Release.Name }} +spec: + ############## Minikube ############## + {{- if eq .Values.cloudProvider "minikube" }} + storageClassName: local-storage + {{- else }} + ############## Other providers ############## + storageClassName: "" + {{- end }} + volumeName: {{ .Release.Name }}-tm-db-pv + accessModes: + - ReadWriteOnce + resources: + requests: + ############# Minikube ############## + {{- if eq .Values.cloudProvider "minikube" }} + storage: {{ .Values.tmDb.persistenceDisk.localVolumeSize }} + {{- end }} + + ############## AWS Provider ############## + {{- if eq .Values.cloudProvider "aws" }} + storage: {{ .Values.tmDb.persistenceDisk.AWS_ElasticBlockStore_size }} + {{- end }} + + ############## GCP Provider ############## + {{- if eq .Values.cloudProvider "gcp" }} + storage: {{ .Values.tmDb.persistenceDisk.GCP_gcePersistentDisk_size }} + {{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/osm-seed/templates/tasking-manager-db/tm-db-service.yaml b/osm-seed/templates/tasking-manager-db/tm-db-service.yaml new file mode 100644 index 00000000..d7855eba --- /dev/null +++ b/osm-seed/templates/tasking-manager-db/tm-db-service.yaml @@ -0,0 +1,19 @@ +{{- if .Values.tmDb.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-tm-db + labels: + app: {{ template "osm-seed.name" . }} + component: tm-db-service + environment: {{ .Values.environment }} + release: {{ .Release.Name }} +spec: + ports: + - port: 5432 + targetPort: 5432 + selector: + app: {{ template "osm-seed.name" . }} + release: {{ .Release.Name }} + run: {{ .Release.Name }}-tm-db +{{- end }} \ No newline at end of file diff --git a/osm-seed/templates/tasking-manager-db/tm-db-statefulset.yaml b/osm-seed/templates/tasking-manager-db/tm-db-statefulset.yaml new file mode 100644 index 00000000..99b00271 --- /dev/null +++ b/osm-seed/templates/tasking-manager-db/tm-db-statefulset.yaml @@ -0,0 +1,101 @@ +{{- if .Values.tmDb.enabled -}} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ .Release.Name }}-tm-db + labels: + app: {{ template "osm-seed.name" . }} + component: db-tm-statefulset + environment: {{ .Values.environment }} + release: {{ .Release.Name }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ template "osm-seed.name" . }} + release: {{ .Release.Name }} + run: {{ .Release.Name }}-tm-db + serviceName: {{ .Release.Name }}-tm-db + template: + metadata: + labels: + app: {{ template "osm-seed.name" . }} + release: {{ .Release.Name }} + run: {{ .Release.Name }}-tm-db + spec: + containers: + - name: {{ .Chart.Name }}-tm-db + image: "{{ .Values.tmDb.image.name }}:{{ .Values.tmDb.image.tag }}" + ports: + - name: postgres + containerPort: 5432 + protocol: TCP + env: + - name: POSTGRES_HOST + value: {{ .Release.Name }}-tm-db + - name: POSTGRES_DB + value: {{ .Values.tmDb.env.POSTGRES_DB }} + - name: POSTGRES_PASSWORD + value: {{ quote .Values.tmDb.env.POSTGRES_PASSWORD }} + - name: POSTGRES_USER + value: {{ default "postgres" .Values.tmDb.env.POSTGRES_USER | quote }} + - name: PGUSER + value: {{ default "postgres" .Values.tmDb.env.POSTGRES_USER | quote }} + - name: PGDATA + value: {{ .Values.tmDb.persistenceDisk.mountPath }} + - name: POSTGRES_DB_MAX_CONNECTIONS + value: {{ default 100 .Values.tmDb.env.POSTGRES_DB_MAX_CONNECTIONS | quote }} + - name: POSTGRES_DB_SHARED_BUFFERS + value: {{ default "128MB" .Values.tmDb.env.POSTGRES_DB_SHARED_BUFFERS | quote }} + - name: POSTGRES_DB_WORK_MEM + value: {{ default "4MB" .Values.tmDb.env.POSTGRES_DB_WORK_MEM | quote }} + - name: POSTGRES_DB_MAINTENANCE_WORK_MEM + value: {{ default "64MB" .Values.tmDb.env.POSTGRES_DB_MAINTENANCE_WORK_MEM | quote }} + - name: POSTGRES_DB_EFFECTIVE_CACHE_SIZE + value: {{ default "4GB" .Values.tmDb.env.POSTGRES_DB_EFFECTIVE_CACHE_SIZE | quote }} + - name: POD_IP + valueFrom: { fieldRef: { fieldPath: status.podIP } } + livenessProbe: + exec: + command: + - sh + - -c + - exec pg_isready --host $POD_IP + initialDelaySeconds: 120 + timeoutSeconds: 5 + failureThreshold: 6 + readinessProbe: + exec: + command: + - sh + - -c + - exec pg_isready --host $POD_IP + initialDelaySeconds: 5 + timeoutSeconds: 3 + periodSeconds: 5 + volumeMounts: + - name: postgres-storage + mountPath: {{ .Values.tmDb.persistenceDisk.mountPath }} + subPath: {{ .Values.tmDb.persistenceDisk.subPath }} + {{- if .Values.tmDb.resources.enabled }} + resources: + requests: + memory: {{ .Values.tmDb.resources.requests.memory }} + cpu: {{ .Values.tmDb.resources.requests.cpu }} + limits: + memory: {{ .Values.tmDb.resources.limits.memory }} + cpu: {{ .Values.tmDb.resources.limits.cpu }} + {{- end }} + volumes: + - name: postgres-storage + {{- if .Values.tmDb.persistenceDisk.enabled }} + persistentVolumeClaim: + claimName: {{ .Release.Name }}-tm-db-pv-claim + {{- else }} + emptyDir: {} + {{- end }} + {{- if .Values.tmDb.nodeSelector.enabled }} + nodeSelector: + {{ .Values.tmDb.nodeSelector.label_key }} : {{ .Values.tmDb.nodeSelector.label_value }} + {{- end }} +{{- end }}