Skip to content

Commit

Permalink
Add PG DSN
Browse files Browse the repository at this point in the history
Signed-off-by: RuliXu <[email protected]>
  • Loading branch information
RuliXu committed Jul 17, 2023
1 parent 53c40cb commit 1121d8e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/clusterpedia/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.7.1
version: 1.7.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
2 changes: 1 addition & 1 deletion charts/clusterpedia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ rm /var/local/clusterpedia/internalstorage/<storage type>
| controllerManager.tolerations | list | `[]` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
6 changes: 4 additions & 2 deletions charts/clusterpedia/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ Return the proper Docker Image Registry Secret Names
{{- if not (empty .Values.externalStorage.dsn) -}}
{{- if eq .Values.externalStorage.type "mysql" }}
{{- .Values.externalStorage.dsn }}
{{- else if eq (include "clusterpedia.storage.type" .) "postgres" -}}
{{- .Values.externalStorage.dsn }}
{{- else -}}
{{ required "storage dsn only supports mysql" "" }}
{{ required "storage dsn only supports mysql or postgres" "" }}
{{- end -}}
{{- end -}}
{{- end -}}
Expand All @@ -149,7 +151,7 @@ Return the proper Docker Image Registry Secret Names
{{- else -}}
{{- "postgres" -}}
{{- end -}}
{{- else if eq (include "clusterpedia.storage.type" .) "mysql" -}}
{{- else if eq (include "clusterpedia.storage.type" .) "mysql" -}}
{{- if not (empty .Values.mysql.auth.username) -}}
{{- .Values.mysql.auth.username -}}
{{- else -}}
Expand Down
34 changes: 34 additions & 0 deletions charts/clusterpedia/templates/scripts-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ data:
echo "user=\"$user\""
echo "password=\"$password\""
}
function parse_postgres_dsn() {
local dsn=$1
if [ -z $dsn ]
then
return
fi
kvpairs=($dsn)
for kv in "${kvpairs[@]}"; do
if [[ $kv == "host"* ]]; then
IFS='=' read -r -a _kv <<< $kv; host=${_kv[1]}
fi
if [[ $kv == "user"* ]]; then
IFS='=' read -r -a _kv <<< $kv; user=${_kv[1]}
fi
if [[ $kv == "port"* ]]; then
IFS='=' read -r -a _kv <<< $kv; port=${_kv[1]}
fi
if [[ $kv == "dbname"* ]]; then
IFS='=' read -r -a _kv <<< $kv; database=${_kv[1]}
fi
done
echo "database=\"$database\""
echo "host=\"$host\""
echo "port=\"$port\""
echo "user=\"$user\""
}
function create_variables() {
local yaml_file="$1"
Expand All @@ -56,4 +85,9 @@ data:
then
eval $(parse_mysql_dsn "$dsn")
fi
if [ $type == "postgres" ]
then
eval $(parse_postgres_dsn "$dsn")
fi
}

0 comments on commit 1121d8e

Please sign in to comment.