Skip to content

Commit

Permalink
Patch load-data.sh and local-demo-data.sql for 3.7.x and 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybear327 committed Dec 12, 2024
1 parent 34b5f78 commit 7eb4102
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Dockerfile.cross

# Test binary, built with `go test -c`
*.test

# Test/Intermediate files
database.sql
load-data.sh
local-demo-data.sh

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
7 changes: 7 additions & 0 deletions kind/load-data-job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# load-data-job

Due to database schema changes cross major/minor NetBox versions, we have to `patch` the SQL files and demo data link on-the-fly.

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.

Please see `../local-env.sh`, that's where all the patching happen.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions kind/local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ if [[ "${VERSION}" == "3.7.8" ]] ;then
"ghcr.io/zalando/spilo-16:3.2-p3" \
)
NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz"

# perform patching, as we need different demo data and adapt to the database schema
# 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
# patch load-data.sh
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

# patch local-demo-data.sql
sed \
-e 's/related_object_type_id/object_type_id/g' \
-e 's/, comments, \"unique\", related_object_filter//g' \
-e "s/, '', false, NULL//g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
elif [[ "${VERSION}" == "4.0.11" ]] ;then
echo "Using version ${VERSION}"
# need to align with netbox-chart otherwise the creation of the cluster will hang
Expand All @@ -60,6 +71,14 @@ elif [[ "${VERSION}" == "4.0.11" ]] ;then
"ghcr.io/zalando/spilo-16:3.2-p3" \
)
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"

# patch load-data.sh
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

# patch local-demo-data.sql
sed \
-e "s/comments, \"unique\", related_object_filter)/comments)/g" \
-e "s/'', false, NULL);/'');/g" $(dirname "$0")/load-data-job/local-demo-data.orig.sql > $(dirname "$0")/load-data-job/local-demo-data.sql
elif [[ "${VERSION}" == "4.1.7" ]] ;then
echo "Using version ${VERSION}"
# need to align with netbox-chart otherwise the creation of the cluster will hang
Expand Down Expand Up @@ -106,3 +125,7 @@ helm upgrade --install --namespace="${NAMESPACE}" netbox \
${NETBOX_HELM_CHART}

kubectl rollout status --namespace="${NAMESPACE}" deployment netbox

# clean up
rm $(dirname "$0")/load-data-job/load-data.sh
rm $(dirname "$0")/load-data-job/local-demo-data.sql

0 comments on commit 7eb4102

Please sign in to comment.