Skip to content

Commit

Permalink
Update db template to use deployments (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwillia authored Aug 1, 2024
1 parent 5c9155e commit e30e6ca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ container_tool ?= podman
# when it is accessed from outside the cluster and when it is accessed from
# inside the cluster. We need the external name to push the image, and the
# internal name to pull it.
external_image_registry:=default-route-openshift-image-registry.apps-crc.testing
internal_image_registry:=image-registry.openshift-image-registry.svc:5000
external_apps_domain?=apps-crc.testing
external_image_registry?=default-route-openshift-image-registry.$(external_apps_domain)
internal_image_registry?=image-registry.openshift-image-registry.svc:5000

# The name of the image repository needs to start with the name of an existing
# namespace because when the image is pushed to the internal registry of a
Expand Down
78 changes: 31 additions & 47 deletions templates/db-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
apiVersion: v1
kind: Template
metadata:
name: trex-db
annotations:
description: PostgreSQL database service for use with the rh-trex
description: PostgreSQL database service for use with the RH Trex service
iconClass: icon-postgresql
openshift.io/display-name: Example Service PostgreSQL Database
openshift.io/display-name: RH Trex PostgreSQL Database
tags: database,postgresql
name: trex-db
parameters:

- name: POSTGRESQL_IMAGESTREAM_NAMESPACE
description: The OpenShift Namespace where the ImageStream resides.
displayName: Namespace
value: openshift

- name: DATABASE_SERVICE_NAME
description: The name of the OpenShift Service exposed for the database.
displayName: Database Service Name
required: true
value: trex-db
value: trex-db

- name: DATABASE_USER
description: Username for PostgreSQL user that will be used for accessing the database.
Expand Down Expand Up @@ -49,7 +44,7 @@ parameters:
description: Version of PostgreSQL image to be used (10 or latest).
displayName: Version of PostgreSQL Image
required: true
value: "10"
value: "16.2"

objects:

Expand All @@ -72,6 +67,7 @@ objects:
type: ClusterIP
status:
loadBalancer: {}

- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand All @@ -82,16 +78,18 @@ objects:
resources:
requests:
storage: ${DATABASE_VOLUME_CAPACITY}
- apiVersion: v1
kind: DeploymentConfig

- apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
template.alpha.openshift.io/wait-for-ready: true
name: ${DATABASE_SERVICE_NAME}
spec:
replicas: 1
selector:
name: ${DATABASE_SERVICE_NAME}
matchLabels:
name: ${DATABASE_SERVICE_NAME}
strategy:
type: Recreate
template:
Expand All @@ -102,28 +100,28 @@ objects:
containers:
- capabilities: {}
env:
- name: POSTGRESQL_USER
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
key: database-user
key: db.user
name: ${DATABASE_SERVICE_NAME}
- name: POSTGRESQL_PASSWORD
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: database-password
key: db.password
name: ${DATABASE_SERVICE_NAME}
- name: POSTGRESQL_DATABASE
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
key: database-name
key: db.name
name: ${DATABASE_SERVICE_NAME}
image: ""
- name: PGDATA
value: /var/lib/pgsql/data/pgdata
image: docker.io/library/postgres:${POSTGRESQL_VERSION}
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- /usr/libexec/check-container
- --live
tcpSocket:
port: 5432
initialDelaySeconds: 120
timeoutSeconds: 10
name: postgresql
Expand All @@ -133,12 +131,11 @@ objects:
readinessProbe:
exec:
command:
- /usr/libexec/check-container
- /bin/sh
- -c
- exec /usr/bin/pg_isready -U $POSTGRES_USER -d $POSTGRES_DB -h localhost -p 5432
initialDelaySeconds: 5
timeoutSeconds: 1
securityContext:
capabilities: {}
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /var/lib/pgsql/data
Expand All @@ -147,31 +144,18 @@ objects:
restartPolicy: Always
volumes:
- name: ${DATABASE_SERVICE_NAME}-data
#emptyDir: {}
persistentVolumeClaim:
claimName: ${DATABASE_SERVICE_NAME}
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- postgresql
from:
kind: ImageStreamTag
name: postgresql:${POSTGRESQL_VERSION}
namespace: ${POSTGRESQL_IMAGESTREAM_NAMESPACE}
- type: ConfigChange
status: {}

- apiVersion: v1
kind: Secret
metadata:
annotations:
template.openshift.io/expose-database_name: "{.data['database-name']}"
template.openshift.io/expose-password: "{.data['database-password']}"
template.openshift.io/expose-username: "{.data['database-user']}"
name: ${DATABASE_SERVICE_NAME}
stringData:
database-name: ${DATABASE_NAME}
database-password: ${DATABASE_PASSWORD}
database-user: ${DATABASE_USER}

db.host: ${DATABASE_SERVICE_NAME}
db.name: ${DATABASE_NAME}
db.password: ${DATABASE_PASSWORD}
db.user: ${DATABASE_USER}
db.port: "5432"
5 changes: 3 additions & 2 deletions templates/route-template.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: v1
kind: Template
name: uhc-acct-mangr-routes
name: trex-routes
metadata:
name: route

Expand All @@ -14,7 +14,8 @@ objects:
labels:
app: trex
spec:
host: trex.apps-crc.testing
# The cluster should assign a suitable host. If using CRC, it may be necessary to define one manually:
# host: trex.apps-crc.testing
to:
kind: Service
name: trex
Expand Down

0 comments on commit e30e6ca

Please sign in to comment.