Skip to content

Commit 35f6e42

Browse files
updating the kube-setup-indexd job to apply single table driver settings.py for specific environments. (#2683)
1 parent 05aecc0 commit 35f6e42

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from indexd.index.drivers.alchemy import SQLAlchemyIndexDriver
2+
from indexd.alias.drivers.alchemy import SQLAlchemyAliasDriver
3+
from indexd.auth.drivers.alchemy import SQLAlchemyAuthDriver
4+
from indexd.index.drivers.single_table_alchemy import SingleTableSQLAlchemyIndexDriver
5+
import config_helper
6+
from os import environ
7+
import json
8+
9+
APP_NAME = "indexd"
10+
11+
12+
def load_json(file_name):
13+
return config_helper.load_json(file_name, APP_NAME)
14+
15+
16+
conf_data = load_json("creds.json")
17+
18+
usr = conf_data.get("db_username", "{{db_username}}")
19+
db = conf_data.get("db_database", "{{db_database}}")
20+
psw = conf_data.get("db_password", "{{db_password}}")
21+
pghost = conf_data.get("db_host", "{{db_host}}")
22+
pgport = 5432
23+
index_config = conf_data.get("index_config")
24+
CONFIG = {}
25+
26+
CONFIG["JSONIFY_PRETTYPRINT_REGULAR"] = False
27+
28+
dist = environ.get("DIST", None)
29+
if dist:
30+
CONFIG["DIST"] = json.loads(dist)
31+
32+
arborist = environ.get("ARBORIST", "false").lower() == "true"
33+
34+
USE_SINGLE_TABLE = True
35+
36+
if USE_SINGLE_TABLE is True:
37+
38+
39+
CONFIG["INDEX"] = {
40+
"driver": SingleTableSQLAlchemyIndexDriver(
41+
"postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
42+
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db
43+
),
44+
index_config=index_config,
45+
)
46+
}
47+
else:
48+
CONFIG["INDEX"] = {
49+
"driver": SQLAlchemyIndexDriver(
50+
"postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
51+
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db
52+
),
53+
index_config=index_config,
54+
)
55+
}
56+
57+
CONFIG["ALIAS"] = {
58+
"driver": SQLAlchemyAliasDriver(
59+
"postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
60+
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db
61+
)
62+
)
63+
}
64+
65+
if arborist:
66+
AUTH = SQLAlchemyAuthDriver(
67+
"postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
68+
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db
69+
),
70+
arborist="http://arborist-service/",
71+
)
72+
else:
73+
AUTH = SQLAlchemyAuthDriver(
74+
"postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
75+
usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db
76+
)
77+
)
78+
79+
settings = {"config": CONFIG, "auth": AUTH}

gen3/bin/kube-setup-indexd.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
source "${GEN3_HOME}/gen3/lib/utils.sh"
77
gen3_load "gen3/lib/kube-setup-init"
88

9+
manifestPath=$(g3k_manifest_path)
10+
singleTable="$(jq -r ".[\"global\"][\"indexd_single_table\"]" < "$manifestPath" | tr '[:upper:]' '[:lower:]')"
11+
912
[[ -z "$GEN3_ROLL_ALL" ]] && gen3 kube-setup-secrets
1013

1114
if [[ ! -f "$(gen3_secrets_folder)/.rendered_indexd_userdb" ]]; then
@@ -19,8 +22,12 @@ if [[ ! -f "$(gen3_secrets_folder)/.rendered_indexd_userdb" ]]; then
1922
fi
2023

2124
g3kubectl delete secrets/indexd-secret > /dev/null 2>&1 || true;
22-
g3kubectl create secret generic indexd-secret --from-file=local_settings.py="${GEN3_HOME}/apis_configs/indexd_settings.py" "--from-file=${GEN3_HOME}/apis_configs/config_helper.py"
23-
25+
if "$singleTable" = true; then
26+
g3kubectl create secret generic indexd-secret --from-file=local_settings.py="${GEN3_HOME}/apis_configs/indexd_multi_table/indexd_settings.py" "--from-file=${GEN3_HOME}/apis_configs/config_helper.py"
27+
else
28+
g3kubectl create secret generic indexd-secret --from-file=local_settings.py="${GEN3_HOME}/apis_configs/indexd_settings.py" "--from-file=${GEN3_HOME}/apis_configs/config_helper.py"
29+
fi
30+
2431
gen3 roll indexd
2532
g3kubectl apply -f "${GEN3_HOME}/kube/services/indexd/indexd-service.yaml"
2633
gen3 roll indexd-canary || true

0 commit comments

Comments
 (0)