-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kots]: add database to preflight and support checks
This checks the connection and the version is correct, based upon the configuration given.
- Loading branch information
Simon Emms
committed
May 11, 2022
1 parent
b517587
commit 4e94f59
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
# Licensed under the GNU Affero General Public License (AGPL). | ||
# See License-AGPL.txt in the project root for license information. | ||
|
||
packages: | ||
- name: docker | ||
type: docker | ||
argdeps: | ||
- imageRepoBase | ||
config: | ||
buildArgs: | ||
VERSION: ${version} | ||
dockerfile: leeway.Dockerfile | ||
metadata: | ||
helm-component: installationTelemetry | ||
image: | ||
- ${imageRepoBase}/kots-config-check/database:${version} | ||
- ${imageRepoBase}/kots-config-check/database:commit-${__git_commit} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
DB_IN_CLUSTER_ENABLED="${1:-""}" | ||
DB_CLOUDSQL_ENABLED="${2:-""}" | ||
DB_USERNAME="${3:-""}" | ||
DB_PASSWORD="${4:-""}" | ||
DB_HOST="${5:-""}" | ||
DB_PORT="${6:-""}" | ||
CSP_INSTANCES="${7:-""}" | ||
CSP_CREDENTIALS="${8:-""}" | ||
|
||
connection="false" | ||
version="" | ||
|
||
DB_TYPE="incluster" | ||
if [ "${DB_IN_CLUSTER_ENABLED}" == "0" ]; then | ||
if [ "${DB_CLOUDSQL_ENABLED}" == "1" ]; then | ||
DB_TYPE="cloudsqlproxy" | ||
else | ||
DB_TYPE="external" | ||
fi | ||
fi | ||
|
||
case "${DB_TYPE}" in | ||
cloudsqlproxy | external) | ||
if [ "${DB_TYPE}" = "cloudsqlproxy" ]; then | ||
echo "Connecting to CloudSQLProxy" | ||
|
||
CREDENTIALS_FILE="/tmp/credentials.json" | ||
echo "${CSP_CREDENTIALS}" | base64 -d > "${CREDENTIALS_FILE}" | ||
|
||
# Config overrides | ||
DB_HOST="0.0.0.0" | ||
DB_PORT="8080" | ||
|
||
# This is a long-running process | ||
cloud_sql_proxy \ | ||
--instances="${CSP_INSTANCES}=tcp:${DB_PORT}" \ | ||
-credential_file="${CREDENTIALS_FILE}" & | ||
|
||
# Give it a chance to connect | ||
sleep 5 | ||
else | ||
echo "Using external database" | ||
fi | ||
|
||
# Check the database version | ||
version_query=$(mysql \ | ||
--connect-timeout=5 \ | ||
--database=gitpod \ | ||
--user="${DB_USERNAME}" \ | ||
--password="${DB_PASSWORD}" \ | ||
--host="${DB_HOST}" \ | ||
--port="${DB_PORT}" \ | ||
--execute="SELECT VERSION();" \ | ||
--silent \ | ||
--raw \ | ||
--skip-column-names || echo "fail") | ||
|
||
if [ "${version_query}" != "fail" ]; then | ||
connection="true" | ||
version="${version_query}" | ||
fi | ||
;; | ||
incluster) | ||
echo "Using in-cluster database" | ||
connection="true" | ||
version="5.7" | ||
;; | ||
*) | ||
echo "Unknown database type: '${DB_TYPE}'" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
if [ "${connection}" = "true" ]; then | ||
echo "connection: ok" | ||
else | ||
echo "connection: error" | ||
fi | ||
echo "version: ${version}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM bitnami/mysql:5.7 | ||
COPY --from=gcr.io/cloudsql-docker/gce-proxy /cloud_sql_proxy /usr/local/bin/cloud_sql_proxy | ||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters