Skip to content

Commit

Permalink
Fix redhat posql persistent (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
phracek authored Oct 30, 2024
1 parent e23d419 commit 3e6283b
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
description: |-
This content is expermental, do not use it in production. PostgreSQL database service, with persistent storage. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/postgresql-container/.
NOTE: Scaling to more than one replica is not supported. You must have persistent volumes available in your cluster to use this template.
annotations:
charts.openshift.io/name: Red Hat PostgreSQL database service, with persistent storage (experimental)
charts.openshift.io/provider: Red Hat
charts.openshift.io/providerType: redhat
apiVersion: v2
appVersion: 0.0.4
name: redhat-postgresql-persistent
tags: database,postgresql
sources:
- https://github.com/sclorg/helm-charts
version: 0.0.4

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# PostgreSQL helm chart

# MariaDB helm chart

A Helm chart for building and deploying a [PostgreSQL](https://github/sclorg/postgresql-container) application on OpenShift.

For more information about helm charts see the official [Helm Charts Documentation](https://helm.sh/).

You need to have access to a cluster for each operation with OpenShift 4, like deploying and testing.

## Values
Below is a table of each value used to configure this chart.

| Value | Description | Default | Additional Information |
|---------------------------------------------| ----------- | -- | ---------------------- |
| `database_service_name` | The name of the OpenShift Service exposed for the database. | `postgresql` | - |
| `postgresql_user` | Username for PostgreSQL user that will be used for accessing the database. | - | Expresion like: `user[A-Z0-9]{3}` |
| `postgresql_database` | Name of the PostgreSQL database accessed. | `sampledb` | |
| `postgresql_password` | Password for the PostgreSQL connection user. | | Expression like: `[a-zA-Z0-9]{16}` |
| `postgresql_version` | Version of PostgreSQL image to be used (10-el7, 10-el8, or latest). | `10-el8` | |
| `namespace` | The OpenShift Namespace where the ImageStream resides. | `openshift` | |
| `memory_limit` | Maximum amount of memory the container can use. | `521Mi` | |
| `volume_capacity` | Volume space available for data, e.g. 512Mi, 2Gi. | `1Gi` | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
template.alpha.openshift.io/wait-for-ready: "true"
image.openshift.io/triggers: |-
[
{
"from": {
"kind": "ImageStreamTag",
"name": "postgresql:{{ .Values.image.tag }}"
},
"fieldPath": "spec.template.spec.containers[0].image"
}
]
labels:
template: postgresql-persistent-template
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ .Release.Name }}
spec:
replicas: 1
selector:
matchLabels:
name: {{ .Values.database_service_name }}
strategy:
type: Recreate
template:
metadata:
labels:
name: {{ .Values.database_service_name }}
spec:
containers:
- env:
- name: POSTGRESQL_USER
valueFrom:
secretKeyRef:
key: database-user
name: {{ .Values.database_service_name }}
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
key: database-password
name: {{ .Values.database_service_name }}
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: {{ .Values.database_service_name }}
image: " "
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- /usr/libexec/check-container
- --live
initialDelaySeconds: 120
timeoutSeconds: 10
name: "postgresql-persistent"
ports:
- containerPort: {{ .Values.config.port }}
protocol: TCP
readinessProbe:
exec:
command:
- /usr/libexec/check-container
initialDelaySeconds: 5
timeoutSeconds: 1
resources:
limits:
memory: {{ .Values.memory_limit }}
securityContext:
capabilities: {}
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /var/lib/pgsql/data
name: {{ .Values.database_service_name }}-data
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: {{ .Values.database_service_name }}-data
persistentVolumeClaim:
claimName: {{ .Values.database_service_name }}
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
template: postgresql-persistent-template
name: {{ .Values.database_service_name }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.volume_capacity }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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'']}'
labels:
template: postgresql-persistent-template
name: {{ .Values.database_service_name }}
stringData:
database-name: {{ .Values.config.postgresql_database }}
database-password: {{ .Values.config.postgresql_password }}
database-user: {{ .Values.config.postgresql_user }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Service
metadata:
annotations:
template.openshift.io/expose-uri: postgres://{.spec.clusterIP}:{.spec.ports[?(.name=="postgresql")].port}
labels:
template: postgresql-persistent-template
name: {{ .Values.database_service_name }}
spec:
ports:
- name: postgresql
nodePort: 0
port: 5432
protocol: TCP
targetPort: 5432
selector:
name: {{ .Values.database_service_name }}
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-connection-test"
namespace: "{{ .Release.Namespace }}"
annotations:
"helm.sh/hook": test
labels:
name: {{ .Values.database_service_name }}
spec:
#serviceAccount: {{ .Values.serviceAccount }}
containers:
- name: "postgresql-connection-test"
image: "registry.redhat.io/rhel8/postgresql-13:latest"
imagePullPolicy: IfNotPresent
env:
- name: POSTGRESQL_USER
value: "{{ .Values.config.postgresql_user }}"
- name: PGPASSWORD
value: "{{ .Values.config.postgresql_password }}"
- name: POSTGRESQL_DATABASE
value: "{{ .Values.config.postgresql_database }}"
- name: POSTGRESQL_PORT
value: "{{ .Values.config.port }}"
command:
- /bin/bash
- -exc
- "PGPASSWORD=$PGPASSWORD /usr/bin/pg_isready -d $POSTGRESQL_DATABASE -h {{ .Values.database_service_name }} -p $POSTGRESQL_PORT -U $POSTGRESQL_USER"
restartPolicy: Never
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"database_service_name": {
"type": "string",
"pattern": "^[a-z0-9-_]+$"
},
"namespace": {
"type": "string"
},
"config": {
"type": "object",
"properties": {
"postgresql_database": {
"type": "string"
},
"postgresql_password": {
"type": "string"
},
"postgresql_user": {
"type": "string"
},
"port": {
"type": "integer"
}
}
},
"volume_capacity": {
"type": "string",
"title": "Persistent Volume Size",
"form": true,
"render": "slider",
"sliderMin": 1,
"sliderMax": 100,
"sliderUnit": "Gi"
},
"memory_limit": {
"type": "string",
"title": "Database memory limit",
"form": true,
"render": "slider",
"sliderMin": 512,
"sliderMax": 65536,
"sliderUnit": "Mi"
},
"image": {
"type": "object",
"properties": {
"tag": {
"type": "string",
"description": "Specify postgresql imagestream tag",
"enum": ["latest", "16-el9", "16-el8", "15-el9", "15-el8","13-el9", "13-el8", "12-el8", "12" ]
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
database_service_name: postgresql-persistent
memory_limit: 512Mi
namespace: postgresql-persistent-testing
volume_capacity: 1Gi
config:
postgresql_database: testdb
postgresql_password: testp
postgresql_user: testu
port: 5432
image:
tag: "13-el8"

0 comments on commit 3e6283b

Please sign in to comment.