-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kots]: add storage to preflight and support checks
This checks the connection is correct, based upon the configuration given.
- Loading branch information
Simon Emms
committed
Jun 1, 2022
1 parent
563b648
commit 4db0500
Showing
6 changed files
with
244 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 | ||
srcs: | ||
- entrypoint.sh | ||
config: | ||
dockerfile: leeway.Dockerfile | ||
metadata: | ||
helm-component: kots-config-check.storage | ||
image: | ||
- ${imageRepoBase}/kots-config-check/storage:${version} | ||
- ${imageRepoBase}/kots-config-check/storage: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,172 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
set -euo pipefail | ||
|
||
STORE_PROVIDER="${1:-""}" | ||
STORE_LOCATION="${2:-""}" | ||
AZURE_ACCOUNT_NAME="${3:-""}" | ||
AZURE_ACCESS_KEY="${4:-""}" | ||
GCP_PROJECT_ID="${5:-""}" | ||
GCP_SERVICE_ACCOUNT_KEY="${6:-""}" | ||
S3_ENDPOINT="${7:-""}" | ||
S3_ACCESS_KEY_ID="${8:-""}" | ||
S3_SECRET_ACCESS_KEY="${9:-""}" | ||
S3_BUCKET_NAME="${10:-""}" | ||
|
||
bucket_name="kots-check-${RANDOM}-${RANDOM}" | ||
downloaded_file=/tmp/download | ||
file_name="kots-check-file" | ||
file_contents="$(date)" | ||
uploaded_file=/tmp/upload | ||
|
||
echo "${file_contents}" > "${uploaded_file}" | ||
|
||
connection="false" | ||
|
||
function test_azure() { | ||
echo "Using Azure storage" | ||
|
||
echo "Create a container" | ||
az storage container create \ | ||
--account-name "${AZURE_ACCOUNT_NAME}" \ | ||
--account-key "${AZURE_ACCESS_KEY}" \ | ||
--name "${bucket_name}" || return 1 | ||
|
||
echo "Upload a file" | ||
az storage blob upload \ | ||
--account-name "${AZURE_ACCOUNT_NAME}" \ | ||
--account-key "${AZURE_ACCESS_KEY}" \ | ||
--container-name "${bucket_name}" \ | ||
--file "${uploaded_file}" \ | ||
--name "${file_name}" || return 1 | ||
|
||
echo "Download the file" | ||
az storage blob download \ | ||
--account-name "${AZURE_ACCOUNT_NAME}" \ | ||
--account-key "${AZURE_ACCESS_KEY}" \ | ||
--container-name "${bucket_name}" \ | ||
--file "${downloaded_file}" \ | ||
--name "${file_name}" || return 1 | ||
|
||
echo "Compare the file" | ||
diff "${downloaded_file}" "${uploaded_file}" || return 1 | ||
|
||
echo "Delete the container" | ||
az storage container delete \ | ||
--name "${bucket_name}" \ | ||
--account-name "${AZURE_ACCOUNT_NAME}" \ | ||
--account-key "${AZURE_ACCESS_KEY}" || return 1 | ||
} | ||
|
||
function test_gcp() { | ||
echo "Using GCP storage" | ||
|
||
echo "${GCP_SERVICE_ACCOUNT_KEY}" | base64 -d > /tmp/creds.json | ||
|
||
gcloud auth activate-service-account --project="${GCP_PROJECT_ID}" --key-file=/tmp/creds.json | ||
|
||
echo "Create bucket" | ||
gsutil mb \ | ||
-l "${STORE_LOCATION}" \ | ||
"gs://${bucket_name}" || return 1 | ||
|
||
echo "Upload a file" | ||
gsutil cp \ | ||
"${uploaded_file}" \ | ||
"gs://${bucket_name}/${file_name}" || return 1 | ||
|
||
echo "Download a file" | ||
gsutil cp \ | ||
"gs://${bucket_name}/${file_name}" \ | ||
"${downloaded_file}" || return 1 | ||
|
||
echo "Compare the file" | ||
diff "${downloaded_file}" "${uploaded_file}" || return 1 | ||
|
||
echo "Delete bucket" | ||
gsutil rm -r \ | ||
"gs://${bucket_name}" || return 1 | ||
} | ||
|
||
function test_s3() { | ||
echo "Using S3 storage" | ||
|
||
create_bucket="1" | ||
s3_bucket_name="${bucket_name}" | ||
if [ -n "${S3_BUCKET_NAME}" ]; then | ||
echo "Specify bucket name" | ||
create_bucket="0" | ||
s3_bucket_name="${S3_BUCKET_NAME}" | ||
fi | ||
|
||
echo "Bucket name: ${s3_bucket_name}" | ||
|
||
mc alias set s3 "https://${S3_ENDPOINT}" "${S3_ACCESS_KEY_ID}" "${S3_SECRET_ACCESS_KEY}" | ||
|
||
if [ "${create_bucket}" = "1" ]; then | ||
echo "Create bucket" | ||
mc mb \ | ||
--region="${STORE_LOCATION}" \ | ||
"s3/${s3_bucket_name}" || return 1 | ||
fi | ||
|
||
echo "Upload a file" | ||
mc cp \ | ||
"${uploaded_file}" \ | ||
"s3/${s3_bucket_name}/${file_name}" || return 1 | ||
|
||
echo "Download a file" | ||
mc cp \ | ||
"s3/${s3_bucket_name}/${file_name}" \ | ||
"${downloaded_file}" || return 1 | ||
|
||
echo "Compare the file" | ||
diff "${downloaded_file}" "${uploaded_file}" || return 1 | ||
|
||
if [ "${create_bucket}" = "1" ]; then | ||
echo "Delete bucket" | ||
mc rb \ | ||
--force \ | ||
"s3/${s3_bucket_name}" || return 1 | ||
else | ||
echo "Delete file" | ||
mc rm \ | ||
--force \ | ||
"s3/${s3_bucket_name}/${file_name}" || return 1 | ||
fi | ||
} | ||
|
||
case "${STORE_PROVIDER}" in | ||
azure) | ||
if test_azure; then | ||
connection="true" | ||
fi | ||
;; | ||
gcp) | ||
if test_gcp; then | ||
connection="true" | ||
fi | ||
;; | ||
incluster) | ||
echo "Using in-cluster storage" | ||
connection="true" | ||
;; | ||
s3) | ||
if test_s3; then | ||
connection="true" | ||
fi | ||
;; | ||
*) | ||
echo "Unknown storage type: '${STORE_PROVIDER}'" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
if [ "${connection}" = "true" ]; then | ||
echo "connection: ok" | ||
else | ||
echo "connection: error" | ||
fi |
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,13 @@ | ||
# 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. | ||
|
||
FROM mcr.microsoft.com/azure-cli | ||
RUN apk add --no-cache bash curl python3 | ||
# GSUtil | ||
RUN curl -sSL https://sdk.cloud.google.com | bash | ||
ENV PATH $PATH:/root/google-cloud-sdk/bin | ||
# Minio client | ||
COPY --from=minio/mc /usr/bin/mc /usr/local/bin/mc | ||
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