Skip to content

Commit

Permalink
Modified scripts for install-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
tmichett committed Dec 6, 2020
1 parent 7ada68f commit a0cac56
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
29 changes: 29 additions & 0 deletions install-storage/check_data.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions install-storage/check_data_demo.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions install-storage/commands.txt
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions install-storage/init_data.sh
Original file line number Diff line number Diff line change
@@ -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

13 changes: 13 additions & 0 deletions install-storage/init_data.sql
Original file line number Diff line number Diff line change
@@ -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');
5 changes: 5 additions & 0 deletions install-storage/init_data_demo.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a0cac56

Please sign in to comment.