diff --git a/install-storage/check_data.sh b/install-storage/check_data.sh new file mode 100755 index 0000000..70bf2db --- /dev/null +++ b/install-storage/check_data.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +echo "Checking characters table" + +if [ "$(oc get pods -o name -l deployment=postgresql-persistent)" != "" ] +then + APP="deployment/postgresql-persistent" +elif [ "$(oc get pods -o name -l deployment=postgresql-persistent2)" != "" ] +then + APP="deployment/postgresql-persistent2" +else + echo "ERROR: deployment/postgresql-persistent not found" + echo "ERROR: deployment/postgresql-persistent2 not found" +fi + +if [ -n "${APP}" ] +then + if [[ "$(oc exec ${APP} -i redhat123 -t -- /usr/bin/psql -U redhat persistentdb -c '\d characters' 2>&1)" != *"exit code 1"* ]] + then + OUTPUT=$(oc exec ${APP} -i redhat123 -t -- /usr/bin/psql -U redhat persistentdb -c 'select id,name,nationality from characters' 2>&1) + fi +fi + +if [ -n "${OUTPUT}" ] +then + echo "${OUTPUT}" +else + echo "ERROR: 'characters' table does not exist" +fi diff --git a/install-storage/check_data_demo.sh b/install-storage/check_data_demo.sh new file mode 100755 index 0000000..9f15589 --- /dev/null +++ b/install-storage/check_data_demo.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +echo "Checking characters table" + +if [ "$(oc get pods -o name -l deployment=db-storage-demo)" != "" ] +then + APP="deployment/db-storage-demo" +elif [ "$(oc get pods -o name -l deployment=db-storage-demo2)" != "" ] +then + APP="deployment/db-storage-demo2" +else + echo "ERROR: deployment/db-storge-demo not found" + echo "ERROR: deployment/db-storage-demo2 not found" +fi + +if [ -n "${APP}" ] +then + if [[ "$(oc exec ${APP} -i redhat123 -t -- /usr/bin/psql -U redhat demodb -c '\d characters' 2>&1)" != *"exit code 1"* ]] + then + OUTPUT=$(oc exec ${APP} -i redhat123 -t -- /usr/bin/psql -U redhat demodb -c 'select id,name,nationality from characters' 2>&1) + fi +fi + +if [ -n "${OUTPUT}" ] +then + echo "${OUTPUT}" +else + echo "ERROR: 'characters' table does not exist" +fi diff --git a/install-storage/commands.txt b/install-storage/commands.txt new file mode 100644 index 0000000..1b07d01 --- /dev/null +++ b/install-storage/commands.txt @@ -0,0 +1,33 @@ +# Create the postgresql-persistent deployment +oc new-app --name postgresql-persistent \ + --docker-image registry.redhat.io/rhel8/postgresql-12:1-43 \ + -e POSTGRESQL_USER=redhat \ + -e POSTGRESQL_PASSWORD=redhat123 \ + -e POSTGRESQL_DATABASE=persistentdb + + +# Create a PVC and volume for the postgresql-persistent deployment +oc set volumes deployment/postgresql-persistent \ + --add --name postgresql-storage --type pvc --claim-class nfs-storage \ + --claim-mode rwo --claim-size 10Gi --mount-path /var/lib/pgsql \ + --claim-name postgresql-storage + + +# List persistent volumes with custom columns +oc get pv \ + -o custom-columns=NAME:.metadata.name,CLAIM:.spec.claimRef.name + +# Create the postgresql-persistent2 deployment +oc new-app --name postgresql-persistent2 \ + --docker-image registry.redhat.io/rhel8/postgresql-12:1-43 \ + -e POSTGRESQL_USER=redhat \ + -e POSTGRESQL_PASSWORD=redhat123 \ + -e POSTGRESQL_DATABASE=persistentdb + + +# Attach the existing PVC to the postgresql-persistent2 deployment +oc set volumes \ + deployment/postgresql-persistent2 \ + --add --name postgresql-storage --type pvc \ + --claim-name postgresql-storage --mount-path /var/lib/pgsql + diff --git a/install-storage/init_data.sh b/install-storage/init_data.sh new file mode 100755 index 0000000..5642e17 --- /dev/null +++ b/install-storage/init_data.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "Populating characters table" +oc exec deployment.apps/postgresql-persistent -i redhat123 -- /usr/bin/psql -U redhat persistentdb < /home/student/DO280/labs/install-storage/init_data.sql + diff --git a/install-storage/init_data.sql b/install-storage/init_data.sql new file mode 100644 index 0000000..882c882 --- /dev/null +++ b/install-storage/init_data.sql @@ -0,0 +1,13 @@ +CREATE TABLE characters ( + id SERIAL PRIMARY KEY, + name varchar(50), + nationality varchar(50) +); + +INSERT INTO characters (name, nationality) +VALUES + ('Wolfgang Amadeus Mozart', 'Prince-Archbishopric of Salzburg'), + ('Ludwig van Beethoven', 'Bonn, Germany'), + ('Johann Sebastian Bach', 'Eisenach, Germany'), + ('José Pablo Moncayo', 'Guadalajara, México'), + ('Niccolò Paganini', 'Genoa, Italy'); diff --git a/install-storage/init_data_demo.sh b/install-storage/init_data_demo.sh new file mode 100755 index 0000000..ac4d7c5 --- /dev/null +++ b/install-storage/init_data_demo.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "Populating characters table" +oc exec deployment.apps/db-storage-demo -i redhat123 -- /usr/bin/psql -U redhat demodb < /home/student/DO280/labs/install-storage/init_data.sql +