Skip to content

Commit d78d6b6

Browse files
authored
cicd: deploy,check,cleanup.sh (#75)
1 parent 789f225 commit d78d6b6

9 files changed

Lines changed: 1300 additions & 32 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
*.tgz
88
deploy/rustfs-operator/charts/
99
deploy/rustfs-operator/Chart.lock
10+
11+
# Operator
12+
operator.log
13+
operator.pid

check-rustfs.sh

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
#!/bin/bash
2+
# Copyright 2025 RustFS Team
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# RustFS cluster quick verification script
17+
# Fully dynamic configuration reading, no hardcoding
18+
19+
set -e
20+
21+
# Configuration parameters (can be overridden via environment variables)
22+
TENANT_NAME="${TENANT_NAME:-}"
23+
NAMESPACE="${NAMESPACE:-}"
24+
25+
# If no parameters provided, try to get from command line arguments
26+
if [ -z "$TENANT_NAME" ] && [ $# -gt 0 ]; then
27+
TENANT_NAME="$1"
28+
fi
29+
if [ -z "$NAMESPACE" ] && [ $# -gt 1 ]; then
30+
NAMESPACE="$2"
31+
fi
32+
33+
# If still not found, try to find the first Tenant from cluster
34+
if [ -z "$TENANT_NAME" ]; then
35+
# If namespace is specified, search in that namespace
36+
if [ -n "$NAMESPACE" ]; then
37+
TENANT_NAME=$(kubectl get tenants -n "$NAMESPACE" -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
38+
else
39+
# Search for first Tenant from all namespaces
40+
TENANT_NAME=$(kubectl get tenants --all-namespaces -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
41+
if [ -n "$TENANT_NAME" ]; then
42+
NAMESPACE=$(kubectl get tenants --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null || echo "")
43+
fi
44+
fi
45+
46+
if [ -z "$TENANT_NAME" ]; then
47+
echo "Error: Tenant resource not found"
48+
echo "Usage: $0 [TENANT_NAME] [NAMESPACE]"
49+
echo " Or set environment variables: TENANT_NAME=<tenant-name> NAMESPACE=<namespace> $0"
50+
exit 1
51+
fi
52+
fi
53+
54+
# If namespace is not specified, read from Tenant resource
55+
if [ -z "$NAMESPACE" ]; then
56+
# Try to find Tenant from all namespaces
57+
NAMESPACE=$(kubectl get tenant "$TENANT_NAME" --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null || echo "")
58+
59+
if [ -z "$NAMESPACE" ]; then
60+
echo "Error: Tenant '$TENANT_NAME' not found"
61+
exit 1
62+
fi
63+
fi
64+
65+
# Verify Tenant exists
66+
if ! kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" &>/dev/null; then
67+
echo "Error: Tenant '$TENANT_NAME' does not exist in namespace '$NAMESPACE'"
68+
exit 1
69+
fi
70+
71+
echo "========================================="
72+
echo " RustFS Cluster Status Check"
73+
echo "========================================="
74+
echo "Tenant: $TENANT_NAME"
75+
echo "Namespace: $NAMESPACE"
76+
echo ""
77+
78+
# Check Tenant status
79+
echo "1. Tenant status:"
80+
kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE"
81+
echo ""
82+
83+
# Check Pod status
84+
echo "2. Pod status:"
85+
kubectl get pods -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME" -o wide
86+
echo ""
87+
88+
# Check Services
89+
echo "3. Services:"
90+
kubectl get svc -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME"
91+
echo ""
92+
93+
# Check PVCs
94+
echo "4. Persistent Volume Claims (PVC):"
95+
kubectl get pvc -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME"
96+
echo ""
97+
98+
# Check StatefulSets
99+
echo "5. StatefulSet:"
100+
kubectl get statefulset -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME"
101+
echo ""
102+
103+
# Check RUSTFS_VOLUMES configuration
104+
echo "6. RustFS volume configuration:"
105+
# Get first Pod name
106+
FIRST_POD=$(kubectl get pods -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME" -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")
107+
if [ -n "$FIRST_POD" ]; then
108+
kubectl describe pod "$FIRST_POD" -n "$NAMESPACE" | grep "RUSTFS_VOLUMES:" -A 1 || echo "RUSTFS_VOLUMES configuration not found"
109+
else
110+
echo "No Pod found"
111+
fi
112+
echo ""
113+
114+
# Show port forward commands
115+
echo "========================================="
116+
echo " Access RustFS"
117+
echo "========================================="
118+
echo ""
119+
120+
# Dynamically get Service information
121+
# Find all related Services by labels
122+
SERVICES=$(kubectl get svc -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME" -o jsonpath='{.items[*].metadata.name}' 2>/dev/null || echo "")
123+
124+
# Find IO Service (port 9000) and Console Service (port 9001)
125+
IO_SERVICE=""
126+
CONSOLE_SERVICE=""
127+
128+
for SVC_NAME in $SERVICES; do
129+
# Check Service port
130+
SVC_PORT=$(kubectl get svc "$SVC_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.ports[0].port}' 2>/dev/null || echo "")
131+
132+
# IO Service typically uses port 9000
133+
if [ "$SVC_PORT" = "9000" ]; then
134+
IO_SERVICE="$SVC_NAME"
135+
fi
136+
137+
# Console Service typically uses port 9001
138+
if [ "$SVC_PORT" = "9001" ]; then
139+
CONSOLE_SERVICE="$SVC_NAME"
140+
fi
141+
done
142+
143+
# If not found by port, try to find by naming convention
144+
if [ -z "$IO_SERVICE" ]; then
145+
# IO Service might be "rustfs" or contain "io"
146+
IO_SERVICE=$(kubectl get svc -n "$NAMESPACE" -l "rustfs.tenant=$TENANT_NAME" -o jsonpath='{.items[?(@.metadata.name=="rustfs")].metadata.name}' 2>/dev/null || echo "")
147+
fi
148+
149+
if [ -z "$CONSOLE_SERVICE" ]; then
150+
# Console Service is typically "{tenant-name}-console"
151+
CONSOLE_SERVICE="${TENANT_NAME}-console"
152+
# Verify it exists
153+
if ! kubectl get svc "$CONSOLE_SERVICE" -n "$NAMESPACE" &>/dev/null; then
154+
CONSOLE_SERVICE=""
155+
fi
156+
fi
157+
158+
# Show IO Service port forward information
159+
if [ -n "$IO_SERVICE" ] && kubectl get svc "$IO_SERVICE" -n "$NAMESPACE" &>/dev/null; then
160+
IO_PORT=$(kubectl get svc "$IO_SERVICE" -n "$NAMESPACE" -o jsonpath='{.spec.ports[0].port}' 2>/dev/null || echo "")
161+
IO_TARGET_PORT=$(kubectl get svc "$IO_SERVICE" -n "$NAMESPACE" -o jsonpath='{.spec.ports[0].targetPort}' 2>/dev/null || echo "$IO_PORT")
162+
163+
echo "S3 API port forward:"
164+
echo " kubectl port-forward -n $NAMESPACE svc/$IO_SERVICE ${IO_PORT}:${IO_TARGET_PORT}"
165+
echo " Access: http://localhost:${IO_PORT}"
166+
echo ""
167+
else
168+
echo "⚠️ IO Service (S3 API) not found"
169+
echo ""
170+
fi
171+
172+
# Show Console Service port forward information
173+
if [ -n "$CONSOLE_SERVICE" ] && kubectl get svc "$CONSOLE_SERVICE" -n "$NAMESPACE" &>/dev/null; then
174+
CONSOLE_PORT=$(kubectl get svc "$CONSOLE_SERVICE" -n "$NAMESPACE" -o jsonpath='{.spec.ports[0].port}' 2>/dev/null || echo "")
175+
CONSOLE_TARGET_PORT=$(kubectl get svc "$CONSOLE_SERVICE" -n "$NAMESPACE" -o jsonpath='{.spec.ports[0].targetPort}' 2>/dev/null || echo "$CONSOLE_PORT")
176+
177+
echo "Web Console port forward:"
178+
echo " kubectl port-forward -n $NAMESPACE svc/$CONSOLE_SERVICE ${CONSOLE_PORT}:${CONSOLE_TARGET_PORT}"
179+
echo " Access: http://localhost:${CONSOLE_PORT}/rustfs/console/index.html"
180+
echo ""
181+
else
182+
echo "⚠️ Console Service (Web UI) not found"
183+
echo ""
184+
fi
185+
186+
# Dynamically get credentials
187+
echo "Credentials:"
188+
CREDS_SECRET=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.credsSecret.name}' 2>/dev/null || echo "")
189+
190+
if [ -n "$CREDS_SECRET" ]; then
191+
# Read credentials from Secret
192+
ACCESS_KEY=$(kubectl get secret "$CREDS_SECRET" -n "$NAMESPACE" -o jsonpath='{.data.accesskey}' 2>/dev/null | base64 -d 2>/dev/null || echo "")
193+
SECRET_KEY=$(kubectl get secret "$CREDS_SECRET" -n "$NAMESPACE" -o jsonpath='{.data.secretkey}' 2>/dev/null | base64 -d 2>/dev/null || echo "")
194+
195+
if [ -n "$ACCESS_KEY" ] && [ -n "$SECRET_KEY" ]; then
196+
echo " Source: Secret '$CREDS_SECRET'"
197+
echo " Access Key: $ACCESS_KEY"
198+
echo " Secret Key: [hidden]"
199+
else
200+
echo " ⚠️ Unable to read credentials from Secret '$CREDS_SECRET'"
201+
fi
202+
else
203+
# Try to read from environment variables
204+
ROOT_USER=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.env[?(@.name=="RUSTFS_ROOT_USER")].value}' 2>/dev/null || echo "")
205+
ROOT_PASSWORD=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.env[?(@.name=="RUSTFS_ROOT_PASSWORD")].value}' 2>/dev/null || echo "")
206+
207+
if [ -n "$ROOT_USER" ] && [ -n "$ROOT_PASSWORD" ]; then
208+
echo " Source: Environment variables"
209+
echo " Username: $ROOT_USER"
210+
echo " Password: $ROOT_PASSWORD"
211+
else
212+
echo " ⚠️ Credentials not configured"
213+
echo " Note: RustFS may use built-in default credentials, please refer to RustFS documentation"
214+
fi
215+
fi
216+
echo ""
217+
218+
# Show cluster configuration
219+
echo "========================================="
220+
echo " Cluster Configuration"
221+
echo "========================================="
222+
echo ""
223+
224+
# Read configuration from Tenant resource
225+
POOLS=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath='{.spec.pools[*].name}' 2>/dev/null || echo "")
226+
POOL_COUNT=$(echo "$POOLS" | wc -w | tr -d ' ')
227+
228+
if [ "$POOL_COUNT" -eq 0 ]; then
229+
echo "⚠️ No Pool configuration found"
230+
else
231+
echo "Pool count: $POOL_COUNT"
232+
echo ""
233+
234+
TOTAL_SERVERS=0
235+
TOTAL_VOLUMES=0
236+
237+
# Iterate through each Pool
238+
for POOL_NAME in $POOLS; do
239+
SERVERS=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath="{.spec.pools[?(@.name==\"$POOL_NAME\")].servers}" 2>/dev/null || echo "0")
240+
VOLUMES_PER_SERVER=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath="{.spec.pools[?(@.name==\"$POOL_NAME\")].persistence.volumesPerServer}" 2>/dev/null || echo "0")
241+
STORAGE_SIZE=$(kubectl get tenant "$TENANT_NAME" -n "$NAMESPACE" -o jsonpath="{.spec.pools[?(@.name==\"$POOL_NAME\")].persistence.volumeClaimTemplate.resources.requests.storage}" 2>/dev/null || echo "")
242+
243+
if [ -n "$SERVERS" ] && [ "$SERVERS" != "0" ] && [ -n "$VOLUMES_PER_SERVER" ] && [ "$VOLUMES_PER_SERVER" != "0" ]; then
244+
POOL_VOLUMES=$((SERVERS * VOLUMES_PER_SERVER))
245+
TOTAL_SERVERS=$((TOTAL_SERVERS + SERVERS))
246+
TOTAL_VOLUMES=$((TOTAL_VOLUMES + POOL_VOLUMES))
247+
248+
echo "Pool: $POOL_NAME"
249+
echo " Servers: $SERVERS"
250+
echo " Volumes per server: $VOLUMES_PER_SERVER"
251+
echo " Total volumes: $POOL_VOLUMES"
252+
253+
if [ -n "$STORAGE_SIZE" ]; then
254+
# Extract number and unit
255+
STORAGE_NUM=$(echo "$STORAGE_SIZE" | sed 's/[^0-9]//g')
256+
STORAGE_UNIT=$(echo "$STORAGE_SIZE" | sed 's/[0-9]//g')
257+
if [ -n "$STORAGE_NUM" ] && [ "$STORAGE_NUM" != "0" ]; then
258+
POOL_CAPACITY_NUM=$((POOL_VOLUMES * STORAGE_NUM))
259+
echo " Total capacity: ${POOL_CAPACITY_NUM}${STORAGE_UNIT} ($POOL_VOLUMES × $STORAGE_SIZE)"
260+
fi
261+
fi
262+
echo ""
263+
fi
264+
done
265+
266+
# Show summary information
267+
if [ "$POOL_COUNT" -gt 1 ]; then
268+
echo "Summary:"
269+
echo " Total servers: $TOTAL_SERVERS"
270+
echo " Total volumes: $TOTAL_VOLUMES"
271+
272+
# Try to calculate total capacity (if all Pools use same storage size)
273+
if [ -n "$STORAGE_SIZE" ]; then
274+
STORAGE_NUM=$(echo "$STORAGE_SIZE" | sed 's/[^0-9]//g')
275+
STORAGE_UNIT=$(echo "$STORAGE_SIZE" | sed 's/[0-9]//g')
276+
if [ -n "$STORAGE_NUM" ] && [ "$STORAGE_NUM" != "0" ]; then
277+
TOTAL_CAPACITY_NUM=$((TOTAL_VOLUMES * STORAGE_NUM))
278+
echo " Total capacity: ${TOTAL_CAPACITY_NUM}${STORAGE_UNIT} ($TOTAL_VOLUMES × $STORAGE_SIZE)"
279+
fi
280+
fi
281+
fi
282+
fi

0 commit comments

Comments
 (0)