Skip to content

Commit 71b1543

Browse files
committed
Patch load-data.sh and local-demo-data.sql for 3.7.x and 4.0.x
1 parent d0d7834 commit 71b1543

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Dockerfile.cross
99

1010
# Test binary, built with `go test -c`
1111
*.test
12+
13+
# Test/Intermediate files
1214
database.sql
15+
load-data.sh
16+
local-demo-data.sh
1317

1418
# Output of the go coverage tool, specifically when used with LiteIDE
1519
*.out

kind/load-data-job/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# load-data-job
2+
3+
Due to database schema changes cross major/minor NetBox versions, we have to `patch` the SQL files and demo data link on-the-fly.
4+
5+
The default values stems from the NetBox 4.1.x version. So the patching will only happen for 3.7.x and 4.0.x versions.
6+
7+
Please see `../local-env.sh`, that's where all the patching happen.

kind/load-data-job/load-data.sh renamed to kind/load-data-job/load-data.orig.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -o errexit
33

44
TMP_SQL_FILE=$(mktemp /tmp/netbox-data-dump.XXXXXXX.sql) || exit 1
5-
curl -k https://raw.githubusercontent.com/netbox-community/netbox-demo-data/master/sql/netbox-demo-v4.1.sql > "${TMP_SQL_FILE}"
5+
curl -k https://raw.githubusercontent.com/netbox-community/netbox-demo-data/master/sql/netbox-demo-v3.7.sql > "${TMP_SQL_FILE}"
66
psql "user=netbox host=netbox-db.${NAMESPACE}.svc.cluster.local" netbox -q -f "${TMP_SQL_FILE}"
77
rm "${TMP_SQL_FILE}"
88
psql "user=netbox host=netbox-db.${NAMESPACE}.svc.cluster.local" netbox -q -f /load-data-job/local-demo-data.sql

kind/local-env.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ if [[ "${VERSION}" == "3.7.8" ]] ;then
4848
"ghcr.io/zalando/spilo-16:3.2-p3" \
4949
)
5050
NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz"
51+
52+
# perform patching, as we need different demo data and adapt to the database schema
53+
# to avoid accidental check-in of the files, the base file is renamed to xx.orig.yy, and the xx.yy is added to .gitignore
54+
# patch load-data.sh
55+
sed 's/netbox-demo-v4.1.sql/netbox-demo-v3.7.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh
56+
57+
# patch local-demo-data.sql
58+
sed \
59+
-e 's/related_object_type_id/object_type_id/g' \
60+
-e 's/, comments, \"unique\", related_object_filter//g' \
61+
-e "s/, '', false, NULL//g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
5162
elif [[ "${VERSION}" == "4.0.11" ]] ;then
5263
echo "Using version ${VERSION}"
5364
# need to align with netbox-chart otherwise the creation of the cluster will hang
@@ -60,6 +71,14 @@ elif [[ "${VERSION}" == "4.0.11" ]] ;then
6071
"ghcr.io/zalando/spilo-16:3.2-p3" \
6172
)
6273
NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.84/netbox-5.0.0-beta.84.tgz"
74+
75+
# patch load-data.sh
76+
sed 's/netbox-demo-v4.1.sql/netbox-demo-v4.0.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh
77+
78+
# patch local-demo-data.sql
79+
sed \
80+
-e "s/comments, \"unique\", related_object_filter)/comments)/g" \
81+
-e "s/'', false, NULL);/'');/g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
6382
elif [[ "${VERSION}" == "4.1.7" ]] ;then
6483
echo "Using version ${VERSION}"
6584
# need to align with netbox-chart otherwise the creation of the cluster will hang
@@ -106,3 +125,7 @@ helm upgrade --install --namespace="${NAMESPACE}" netbox \
106125
${NETBOX_HELM_CHART}
107126

108127
kubectl rollout status --namespace="${NAMESPACE}" deployment netbox
128+
129+
# clean up
130+
rm $(dirname "$0")/load-data-job/load-data.sh
131+
rm $(dirname "$0")/load-data-job/local-demo-data.sql

0 commit comments

Comments
 (0)