Skip to content

Commit 3c63e7e

Browse files
Simon Emmsroboquat
authored andcommitted
[kots]: add storage to preflight and support checks
This checks the connection is correct, based upon the configuration given.
1 parent 8a56328 commit 3c63e7e

File tree

6 files changed

+244
-0
lines changed

6 files changed

+244
-0
lines changed

components/BUILD.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ packages:
7171
- components/ws-proxy:docker
7272
- components/ide-proxy:docker
7373
- components/kots-config-check/database:docker
74+
- components/kots-config-check/storage:docker
7475
- test:docker
7576
- dev/version-manifest:app
7677
config:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
packages:
6+
- name: docker
7+
type: docker
8+
argdeps:
9+
- imageRepoBase
10+
srcs:
11+
- entrypoint.sh
12+
config:
13+
dockerfile: leeway.Dockerfile
14+
metadata:
15+
helm-component: kots-config-check.storage
16+
image:
17+
- ${imageRepoBase}/kots-config-check/storage:${version}
18+
- ${imageRepoBase}/kots-config-check/storage:commit-${__git_commit}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/bin/bash
2+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
# Licensed under the GNU Affero General Public License (AGPL).
4+
# See License-AGPL.txt in the project root for license information.
5+
6+
set -euo pipefail
7+
8+
STORE_PROVIDER="${1:-""}"
9+
STORE_LOCATION="${2:-""}"
10+
AZURE_ACCOUNT_NAME="${3:-""}"
11+
AZURE_ACCESS_KEY="${4:-""}"
12+
GCP_PROJECT_ID="${5:-""}"
13+
GCP_SERVICE_ACCOUNT_KEY="${6:-""}"
14+
S3_ENDPOINT="${7:-""}"
15+
S3_ACCESS_KEY_ID="${8:-""}"
16+
S3_SECRET_ACCESS_KEY="${9:-""}"
17+
S3_BUCKET_NAME="${10:-""}"
18+
19+
bucket_name="kots-check-${RANDOM}-${RANDOM}"
20+
downloaded_file=/tmp/download
21+
file_name="kots-check-file"
22+
file_contents="$(date)"
23+
uploaded_file=/tmp/upload
24+
25+
echo "${file_contents}" > "${uploaded_file}"
26+
27+
connection="false"
28+
29+
function test_azure() {
30+
echo "Using Azure storage"
31+
32+
echo "Create a container"
33+
az storage container create \
34+
--account-name "${AZURE_ACCOUNT_NAME}" \
35+
--account-key "${AZURE_ACCESS_KEY}" \
36+
--name "${bucket_name}" || return 1
37+
38+
echo "Upload a file"
39+
az storage blob upload \
40+
--account-name "${AZURE_ACCOUNT_NAME}" \
41+
--account-key "${AZURE_ACCESS_KEY}" \
42+
--container-name "${bucket_name}" \
43+
--file "${uploaded_file}" \
44+
--name "${file_name}" || return 1
45+
46+
echo "Download the file"
47+
az storage blob download \
48+
--account-name "${AZURE_ACCOUNT_NAME}" \
49+
--account-key "${AZURE_ACCESS_KEY}" \
50+
--container-name "${bucket_name}" \
51+
--file "${downloaded_file}" \
52+
--name "${file_name}" || return 1
53+
54+
echo "Compare the file"
55+
diff "${downloaded_file}" "${uploaded_file}" || return 1
56+
57+
echo "Delete the container"
58+
az storage container delete \
59+
--name "${bucket_name}" \
60+
--account-name "${AZURE_ACCOUNT_NAME}" \
61+
--account-key "${AZURE_ACCESS_KEY}" || return 1
62+
}
63+
64+
function test_gcp() {
65+
echo "Using GCP storage"
66+
67+
echo "${GCP_SERVICE_ACCOUNT_KEY}" | base64 -d > /tmp/creds.json
68+
69+
gcloud auth activate-service-account --project="${GCP_PROJECT_ID}" --key-file=/tmp/creds.json
70+
71+
echo "Create bucket"
72+
gsutil mb \
73+
-l "${STORE_LOCATION}" \
74+
"gs://${bucket_name}" || return 1
75+
76+
echo "Upload a file"
77+
gsutil cp \
78+
"${uploaded_file}" \
79+
"gs://${bucket_name}/${file_name}" || return 1
80+
81+
echo "Download a file"
82+
gsutil cp \
83+
"gs://${bucket_name}/${file_name}" \
84+
"${downloaded_file}" || return 1
85+
86+
echo "Compare the file"
87+
diff "${downloaded_file}" "${uploaded_file}" || return 1
88+
89+
echo "Delete bucket"
90+
gsutil rm -r \
91+
"gs://${bucket_name}" || return 1
92+
}
93+
94+
function test_s3() {
95+
echo "Using S3 storage"
96+
97+
create_bucket="1"
98+
s3_bucket_name="${bucket_name}"
99+
if [ -n "${S3_BUCKET_NAME}" ]; then
100+
echo "Specify bucket name"
101+
create_bucket="0"
102+
s3_bucket_name="${S3_BUCKET_NAME}"
103+
fi
104+
105+
echo "Bucket name: ${s3_bucket_name}"
106+
107+
mc alias set s3 "https://${S3_ENDPOINT}" "${S3_ACCESS_KEY_ID}" "${S3_SECRET_ACCESS_KEY}"
108+
109+
if [ "${create_bucket}" = "1" ]; then
110+
echo "Create bucket"
111+
mc mb \
112+
--region="${STORE_LOCATION}" \
113+
"s3/${s3_bucket_name}" || return 1
114+
fi
115+
116+
echo "Upload a file"
117+
mc cp \
118+
"${uploaded_file}" \
119+
"s3/${s3_bucket_name}/${file_name}" || return 1
120+
121+
echo "Download a file"
122+
mc cp \
123+
"s3/${s3_bucket_name}/${file_name}" \
124+
"${downloaded_file}" || return 1
125+
126+
echo "Compare the file"
127+
diff "${downloaded_file}" "${uploaded_file}" || return 1
128+
129+
if [ "${create_bucket}" = "1" ]; then
130+
echo "Delete bucket"
131+
mc rb \
132+
--force \
133+
"s3/${s3_bucket_name}" || return 1
134+
else
135+
echo "Delete file"
136+
mc rm \
137+
--force \
138+
"s3/${s3_bucket_name}/${file_name}" || return 1
139+
fi
140+
}
141+
142+
case "${STORE_PROVIDER}" in
143+
azure)
144+
if test_azure; then
145+
connection="true"
146+
fi
147+
;;
148+
gcp)
149+
if test_gcp; then
150+
connection="true"
151+
fi
152+
;;
153+
incluster)
154+
echo "Using in-cluster storage"
155+
connection="true"
156+
;;
157+
s3)
158+
if test_s3; then
159+
connection="true"
160+
fi
161+
;;
162+
*)
163+
echo "Unknown storage type: '${STORE_PROVIDER}'"
164+
exit 1
165+
;;
166+
esac
167+
168+
if [ "${connection}" = "true" ]; then
169+
echo "connection: ok"
170+
else
171+
echo "connection: error"
172+
fi
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
FROM mcr.microsoft.com/azure-cli
6+
RUN apk add --no-cache bash curl python3
7+
# GSUtil
8+
RUN curl -sSL https://sdk.cloud.google.com | bash
9+
ENV PATH $PATH:/root/google-cloud-sdk/bin
10+
# Minio client
11+
COPY --from=minio/mc /usr/bin/mc /usr/local/bin/mc
12+
COPY entrypoint.sh /entrypoint.sh
13+
ENTRYPOINT [ "/entrypoint.sh" ]

install/kots/manifests/kots-preflight.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ spec:
2929
- -c
3030
args:
3131
- semver --coerce --range '>=5.4.0' $(uname -r) || echo invalid
32+
- run:
33+
collectorName: storage
34+
image: eu.gcr.io/gitpod-core-dev/build/kots-config-check/storage:sje-kots-storage-check.9
35+
name: storage
36+
args:
37+
- '{{repl ConfigOption "store_provider" }}' # STORE_PROVIDER
38+
- '{{repl ConfigOption "store_region" }}' # STORE_LOCATION
39+
- '{{repl ConfigOption "store_azure_account_name" }}' # AZURE_ACCOUNT_NAME
40+
- '{{repl ConfigOption "store_azure_access_key" }}' # AZURE_ACCESS_KEY
41+
- '{{repl ConfigOption "store_gcp_project" }}' # GCP_PROJECT_ID
42+
- '{{repl ConfigOption "store_gcp_credentials" }}' # GCP_SERVICE_ACCOUNT_KEY
43+
- '{{repl ConfigOption "store_s3_endpoint" }}' # S3_ENDPOINT
44+
- '{{repl ConfigOption "store_s3_access_key_id" }}' # S3_ACCESS_KEY_ID
45+
- '{{repl ConfigOption "store_s3_secret_access_key" }}' # S3_SECRET_ACCESS_KEY
46+
- '{{repl ConfigOption "store_s3_bucket" }}' # S3_BUCKET_NAME
3247
analyzers:
3348
- clusterVersion:
3449
outcomes:
@@ -184,3 +199,13 @@ spec:
184199
message: Database version is valid
185200
- warn:
186201
message: Database version could not be verified. This should be MySQL 5.7
202+
- textAnalyze:
203+
checkName: Object storage connection is valid
204+
fileName: storage/storage.log
205+
regexGroups: 'connection: (?P<Connection>\w+)'
206+
outcomes:
207+
- pass:
208+
when: "Connection == ok"
209+
message: Object storage connection is valid
210+
- fail:
211+
message: Object storage connection is invalid. Please check your settings and that the resource is accessible from your cluster

install/kots/manifests/kots-support-bundle.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ spec:
2020
- '{{repl ConfigOption "db_port" }}' # DB_PORT
2121
- '{{repl ConfigOption "db_cloudsql_instance" }}' # CloudSQL instances
2222
- '{{repl ConfigOption "db_gcp_credentials" }}' # CloudSQL credentials file
23+
- run:
24+
collectorName: storage
25+
image: eu.gcr.io/gitpod-core-dev/build/kots-config-check/storage:sje-kots-storage-check.9
26+
name: storage
27+
args:
28+
- '{{repl ConfigOption "store_provider" }}' # STORE_PROVIDER
29+
- '{{repl ConfigOption "store_region" }}' # STORE_LOCATION
30+
- '{{repl ConfigOption "store_azure_account_name" }}' # AZURE_ACCOUNT_NAME
31+
- '{{repl ConfigOption "store_azure_access_key" }}' # AZURE_ACCESS_KEY
32+
- '{{repl ConfigOption "store_gcp_project" }}' # GCP_PROJECT_ID
33+
- '{{repl ConfigOption "store_gcp_credentials" }}' # GCP_SERVICE_ACCOUNT_KEY
34+
- '{{repl ConfigOption "store_s3_endpoint" }}' # S3_ENDPOINT
35+
- '{{repl ConfigOption "store_s3_access_key_id" }}' # S3_ACCESS_KEY_ID
36+
- '{{repl ConfigOption "store_s3_secret_access_key" }}' # S3_SECRET_ACCESS_KEY
37+
- '{{repl ConfigOption "store_s3_bucket" }}' # S3_BUCKET_NAME
2338
- clusterInfo: {}
2439
- clusterResources: {}
2540
- logs:

0 commit comments

Comments
 (0)