Skip to content

Commit

Permalink
wip -- plumb value thru sidecar demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ransomw1c committed Oct 1, 2019
1 parent c8b1278 commit 8dcf220
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
8 changes: 7 additions & 1 deletion hack/fuse-demo/create_coord_pg_pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ proj_root_dir="$(dirname "$(dirname "$SCRIPT_DIR")")"

pull_policy=Always

while getopts o opt; do
typeset -i SOME_CONST

while getopts oc: opt; do
case $opt in
(o)
# local deploy
pull_policy=IfNotPresent
;;
(c)
SOME_CONST="$OPTARG"
;;
(\?)
print Bad option, aborting.
exit 1
Expand All @@ -40,6 +45,7 @@ RES_DEF="$proj_root_dir"/hack/k8s/gen/example-coord-pg.yaml

PULL_POLICY=$pull_policy \
OUTPUT_LABEL=$OUTPUT_LABEL \
SOME_CONST=$SOME_CONST \
"$proj_root_dir"/hack/envexpand "$proj_root_dir"/hack/k8s/example-coord-pg.template.yaml > "$RES_DEF"

if kubectl get deployment datamon-coord-pg-demo &> /dev/null; then
Expand Down
14 changes: 11 additions & 3 deletions hack/fuse-demo/demo_pg_coord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ build_datamon_base=false
build_sidecar=true
build_demo_app=true

while getopts bs opt; do
# roundtrip thru sidecar.
# change this variable to demonstrate dynamic upload contents
typeset -i SOME_CONST

while getopts bsc: opt; do
case $opt in
(b)
build_datamon_base=true
Expand All @@ -20,6 +24,9 @@ while getopts bs opt; do
build_sidecar=false
build_demo_app=false
;;
(c)
SOME_CONST="$OPTARG"
;;
(\?)
print Bad option, aborting.
exit 1
Expand All @@ -44,7 +51,7 @@ make build-datamon-local

date '+%s' > /tmp/datamon_pg_demo_coord_start_timestamp

./hack/fuse-demo/create_coord_pg_pod.sh
./hack/fuse-demo/create_coord_pg_pod.sh -c $SOME_CONST

##### follow_coord_logs.sh dupe

Expand Down Expand Up @@ -186,10 +193,11 @@ $0 ~ /^----/ { on_row = 1 }
tabla_idx_vals_scalar=$(get_tabla_idx_vals)
tabla_idx_vals_array=(${(f)tabla_idx_vals_scalar})

if [[ ${tabla_idx_vals_array[3]} -eq 5 ]]; then
if [[ ${tabla_idx_vals_array[3]} -eq $((5 + $SOME_CONST)) ]]; then
print "got an expected value out of database"
else
print "got unexpected value out of database artifact"
print "${tabla_idx_vals_array[3]} != $((5 + $SOME_CONST))"
exit 1
fi

Expand Down
61 changes: 48 additions & 13 deletions hack/fuse-demo/mock_application_pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ setopt PIPE_FAIL
#
# todo: sandbox poc python (sqla/pandas) use rather than psql

MY_PG_PORT="$1"
OUTPUT_PG_PORT="$1"
INPUT_PG_PORT="$2"
SOME_CONST="$3"

usage() {
print -- 'usage: ./mock_application_pg.sh pg-port' 1>&2
print -- 'usage: ' \
'./mock_application_pg.sh input-pg-port ouput-pg-port some-const' \
1>&2
exit 1
}

if [ -z "$MY_PG_PORT" ]; then
if [ -z "$OUTPUT_PG_PORT" ]; then
usage
fi
if [ -z "$INPUT_PG_PORT" ]; then
usage
fi
if [ -z "$SOME_CONST" ]; then
usage
fi

Expand All @@ -26,24 +36,49 @@ PG_SU=postgres
PG_U=testpguser
PG_DB=testdb

# aside: postgres defaults to UNIX (filesystem) socket at /var/run/postgresql/*,
# not IP (network) socket, so it's the client's responsibility to ensure that
# the conn is opened at the network location
run_sql() {
sql_str=$1
my_pg_port=$2
if [[ -z $my_pg_port ]]; then
my_pg_port=$OUTPUT_PG_PORT
fi
print -- "$sql_str" | psql -h localhost -p $my_pg_port -U ${PG_U} ${PG_DB}
}

# aside: postgres defaults to UNIX (filesystem)
# socket at /var/run/postgresql/*,
# not IP (network) socket, so it's the client's responsibility
# to ensure that the conn is opened at the network location

print -- "CREATE ROLE ${PG_U} WITH LOGIN CREATEDB;
CREATE DATABASE ${PG_DB} WITH OWNER ${PG_U};" | \
psql -h localhost -p $MY_PG_PORT -U $PG_SU


run_sql() {
print -- "$1" | psql -h localhost -p $MY_PG_PORT -U ${PG_U} ${PG_DB}
}
psql -h localhost -p $OUTPUT_PG_PORT -U $PG_SU

run_sql 'CREATE TABLE tabla_e (
id serial PRIMARY KEY,
an_idx integer
);'

for idx in $(seq 1 2 9); do
get_tabla_idx_vals_with_const() {
print 'select an_idx from tabla_e;' | \
psql -h localhost -p $INPUT_PG_PORT -U $PG_U $PG_DB | \
awk '
BEGIN { on_row = 0 }
$0 ~ /^\(/ {if(on_row) {on_row = 0}}
{if(on_row) {print $1;}}
$0 ~ /^----/ { on_row = 1 }
' | \
awk "{print "'$1'" + $SOME_CONST }"
}

# previously to set input bundle
initdb() {
for idx in $(seq 1 2 9); do
run_sql "INSERT INTO tabla_e (an_idx) VALUES (${idx}) RETURNING id;"
done
}

for idx in $(get_tabla_idx_vals_with_const); do
print -- "adding index $idx to output table"
run_sql "INSERT INTO tabla_e (an_idx) VALUES (${idx}) RETURNING id;"
done
2 changes: 1 addition & 1 deletion hack/k8s/example-coord-pg.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:

command: ["/tmp/coord/.scripts/wrap_application.sh"]
args: ["-s", "-c", "/tmp/coord", "-b", "postgres", "--",
"./mock_application_pg.sh", "5430"]
"./mock_application_pg.sh", "5430", "5429", "$SOME_CONST"]

stdin: true
tty: true
Expand Down

0 comments on commit 8dcf220

Please sign in to comment.