Skip to content

Commit 1fccdca

Browse files
author
Simon Emms
committed
[kots]: add storage to preflight and support checks
This checks the connection is correct, based upon the configuration given.
1 parent 9271a07 commit 1fccdca

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-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: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
18+
bucket_name="kots-check-${RANDOM}-${RANDOM}"
19+
downloaded_file=/tmp/download
20+
file_name="kots-check-file"
21+
file_contents="$(date)"
22+
uploaded_file=/tmp/upload
23+
24+
echo "${file_contents}" > "${uploaded_file}"
25+
26+
connection="false"
27+
28+
function test_azure() {
29+
echo "Using Azure storage"
30+
31+
echo "Create a container"
32+
az storage container create \
33+
--account-name "${AZURE_ACCOUNT_NAME}" \
34+
--account-key "${AZURE_ACCESS_KEY}" \
35+
--name "${bucket_name}" || return 1
36+
37+
echo "Upload a file"
38+
az storage blob upload \
39+
--account-name "${AZURE_ACCOUNT_NAME}" \
40+
--account-key "${AZURE_ACCESS_KEY}" \
41+
--container-name "${bucket_name}" \
42+
--file "${uploaded_file}" \
43+
--name "${file_name}" || return 1
44+
45+
echo "Download the file"
46+
az storage blob download \
47+
--account-name "${AZURE_ACCOUNT_NAME}" \
48+
--account-key "${AZURE_ACCESS_KEY}" \
49+
--container-name "${bucket_name}" \
50+
--file "${downloaded_file}" \
51+
--name "${file_name}" || return 1
52+
53+
echo "Compare the file"
54+
diff "${downloaded_file}" "${uploaded_file}" || return 1
55+
56+
echo "Delete the container"
57+
az storage container delete \
58+
--name "${bucket_name}" \
59+
--account-name "${AZURE_ACCOUNT_NAME}" \
60+
--account-key "${AZURE_ACCESS_KEY}" || return 1
61+
}
62+
63+
function test_gcp() {
64+
echo "Using GCP storage"
65+
66+
echo "${GCP_SERVICE_ACCOUNT_KEY}" | base64 -d > /tmp/creds.json
67+
68+
gcloud auth activate-service-account --project="${GCP_PROJECT_ID}" --key-file=/tmp/creds.json
69+
70+
echo "Create bucket"
71+
gsutil mb \
72+
-l "${STORE_LOCATION}" \
73+
"gs://${bucket_name}" || return 1
74+
75+
echo "Upload a file"
76+
gsutil cp \
77+
"${uploaded_file}" \
78+
"gs://${bucket_name}/${file_name}" || return 1
79+
80+
echo "Download a file"
81+
gsutil cp \
82+
"gs://${bucket_name}/${file_name}" \
83+
"${downloaded_file}" || return 1
84+
85+
echo "Compare the file"
86+
diff "${downloaded_file}" "${uploaded_file}" || return 1
87+
88+
echo "Delete bucket"
89+
gsutil rm -r \
90+
"gs://${bucket_name}" || return 1
91+
}
92+
93+
function test_s3() {
94+
echo "Using S3 storage"
95+
96+
mc alias set s3 "https://${S3_ENDPOINT}" "${S3_ACCESS_KEY_ID}" "${S3_SECRET_ACCESS_KEY}"
97+
98+
echo "Create bucket"
99+
mc mb \
100+
--region="${STORE_LOCATION}" \
101+
"s3/${bucket_name}" || return 1
102+
103+
echo "Upload a file"
104+
mc cp \
105+
"${uploaded_file}" \
106+
"s3/${bucket_name}/${file_name}" || return 1
107+
108+
echo "Download a file"
109+
mc cp \
110+
"s3/${bucket_name}/${file_name}" \
111+
"${downloaded_file}" || return 1
112+
113+
echo "Compare the file"
114+
diff "${downloaded_file}" "${uploaded_file}" || return 1
115+
116+
echo "Delete bucket"
117+
mc rb \
118+
--force \
119+
"s3/${bucket_name}" || return 1
120+
}
121+
122+
case "${STORE_PROVIDER}" in
123+
azure)
124+
if test_azure; then
125+
connection="true"
126+
fi
127+
;;
128+
gcp)
129+
if test_gcp; then
130+
connection="true"
131+
fi
132+
;;
133+
incluster)
134+
echo "Using in-cluster storage"
135+
connection="true"
136+
;;
137+
s3)
138+
if test_s3; then
139+
connection="true"
140+
fi
141+
;;
142+
*)
143+
echo "Unknown storage type: '${STORE_PROVIDER}'"
144+
exit 1
145+
;;
146+
esac
147+
148+
if [ "${connection}" = "true" ]; then
149+
echo "connection: ok"
150+
else
151+
echo "connection: error"
152+
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ 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.5
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
3246
analyzers:
3347
- clusterVersion:
3448
outcomes:
@@ -184,3 +198,13 @@ spec:
184198
message: Database version is valid
185199
- warn:
186200
message: Database version could not be verified. This should be MySQL 5.7
201+
- textAnalyze:
202+
checkName: Object storage connection is valid
203+
fileName: storage/storage.log
204+
regexGroups: 'connection: (?P<Connection>\w+)'
205+
outcomes:
206+
- pass:
207+
when: "Connection == ok"
208+
message: Object storage connection is valid
209+
- fail:
210+
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ 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.5
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
2337
- clusterInfo: {}
2438
- clusterResources: {}
2539
- logs:

0 commit comments

Comments
 (0)