Skip to content

Commit 505caf1

Browse files
committed
feat: complete spoke import in multicluster deploy script
Signed-off-by: Chris Butler <chris.butler@redhat.com>
1 parent 1d199ed commit 505caf1

2 files changed

Lines changed: 148 additions & 1 deletion

File tree

rhdp/wrapper-multicluster.sh

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,139 @@ else
166166
echo "Spoke cluster creation completed successfully!"
167167
fi
168168

169+
echo "---------------------"
170+
echo "Verifying ACM deployment on hub cluster"
171+
echo "---------------------"
172+
173+
# Ensure we're using the hub cluster kubeconfig
174+
export KUBECONFIG="$(pwd)/openshift-install-hub/auth/kubeconfig"
175+
176+
# Check if ACM namespace exists
177+
if ! kubectl get namespace open-cluster-management &> /dev/null; then
178+
echo "WARNING: ACM namespace 'open-cluster-management' not found"
179+
ACM_STATUS="FAILED"
180+
exit 1
181+
else
182+
echo "✓ ACM namespace exists"
183+
184+
# Check MultiClusterHub status
185+
MCH_STATUS=$(kubectl get multiclusterhub -n open-cluster-management -o jsonpath='{.items[0].status.phase}' 2>/dev/null || echo "NOT_FOUND")
186+
187+
if [ "$MCH_STATUS" == "Running" ]; then
188+
echo "✓ MultiClusterHub is Running"
189+
ACM_STATUS="SUCCESS"
190+
else
191+
echo "WARNING: MultiClusterHub status is: $MCH_STATUS (expected: Running)"
192+
ACM_STATUS="DEGRADED"
193+
exit 1
194+
fi
195+
fi
196+
197+
198+
echo "ACM Deployment Status: $ACM_STATUS"
199+
echo "---------------------"
200+
201+
# Import spoke cluster into ACM if both ACM and spoke are successful
202+
if [ "$ACM_STATUS" == "SUCCESS" ] && [ $SPOKE_EXIT_CODE -eq 0 ]; then
203+
echo "---------------------"
204+
echo "Importing spoke cluster into ACM"
205+
echo "---------------------"
206+
207+
# Ensure we're using the hub cluster kubeconfig
208+
export KUBECONFIG="$(pwd)/openshift-install-hub/auth/kubeconfig"
209+
210+
# Create ManagedCluster resource with the required label
211+
cat <<EOF | kubectl apply -f -
212+
apiVersion: cluster.open-cluster-management.io/v1
213+
kind: ManagedCluster
214+
metadata:
215+
name: coco-spoke
216+
labels:
217+
clusterGroup: untrusted-spoke
218+
cloud: auto-detect
219+
vendor: auto-detect
220+
spec:
221+
hubAcceptsClient: true
222+
EOF
223+
224+
if [ $? -eq 0 ]; then
225+
echo "✓ ManagedCluster resource created for coco-spoke"
226+
else
227+
echo "ERROR: Failed to create ManagedCluster resource"
228+
exit 1
229+
fi
230+
231+
# Wait for import secret to be created
232+
echo "Waiting for import secret to be generated..."
233+
IMPORT_SECRET_WAIT=0
234+
while [ $IMPORT_SECRET_WAIT -lt 60 ]; do
235+
if kubectl get secret -n coco-spoke coco-spoke-import 2>/dev/null; then
236+
echo "✓ Import secret generated"
237+
break
238+
fi
239+
sleep 5
240+
IMPORT_SECRET_WAIT=$((IMPORT_SECRET_WAIT + 5))
241+
done
242+
243+
if [ $IMPORT_SECRET_WAIT -ge 60 ]; then
244+
echo "ERROR: Timeout waiting for import secret"
245+
exit 1
246+
fi
247+
248+
# Extract and apply import manifests to spoke cluster
249+
echo "Applying import manifests to spoke cluster..."
250+
kubectl get secret -n coco-spoke coco-spoke-import -o jsonpath='{.data.import\.yaml}' | base64 --decode > /tmp/coco-spoke-import.yaml
251+
kubectl get secret -n coco-spoke coco-spoke-import -o jsonpath='{.data.crds\.yaml}' | base64 --decode > /tmp/coco-spoke-crds.yaml
252+
253+
# Switch to spoke cluster and apply import manifests
254+
export KUBECONFIG="$(pwd)/openshift-install-spoke/auth/kubeconfig"
255+
256+
echo "Applying CRDs to spoke cluster..."
257+
kubectl apply -f /tmp/coco-spoke-crds.yaml
258+
259+
echo "Applying import manifests to spoke cluster..."
260+
kubectl apply -f /tmp/coco-spoke-import.yaml
261+
262+
# Clean up temporary files
263+
rm -f /tmp/coco-spoke-import.yaml /tmp/coco-spoke-crds.yaml
264+
265+
# Switch back to hub cluster to verify import
266+
export KUBECONFIG="$(pwd)/openshift-install-hub/auth/kubeconfig"
267+
268+
echo "Waiting for spoke cluster to be imported and available..."
269+
IMPORT_WAIT=0
270+
while [ $IMPORT_WAIT -lt 300 ]; do
271+
CLUSTER_STATUS=$(kubectl get managedcluster coco-spoke -o jsonpath='{.status.conditions[?(@.type=="ManagedClusterConditionAvailable")].status}' 2>/dev/null)
272+
if [ "$CLUSTER_STATUS" == "True" ]; then
273+
echo "✓ Spoke cluster successfully imported and available in ACM"
274+
SPOKE_IMPORT_STATUS="SUCCESS"
275+
break
276+
fi
277+
sleep 10
278+
IMPORT_WAIT=$((IMPORT_WAIT + 10))
279+
echo "Still waiting... ($IMPORT_WAIT/300 seconds)"
280+
done
281+
282+
if [ $IMPORT_WAIT -ge 300 ]; then
283+
echo "WARNING: Spoke cluster import did not complete within 5 minutes"
284+
echo "Current status: $CLUSTER_STATUS"
285+
SPOKE_IMPORT_STATUS="TIMEOUT"
286+
fi
287+
288+
# Verify the label is set correctly
289+
CLUSTER_LABEL=$(kubectl get managedcluster coco-spoke -o jsonpath='{.metadata.labels.clusterGroup}' 2>/dev/null)
290+
if [ "$CLUSTER_LABEL" == "untrustedSpoke" ]; then
291+
echo "✓ Cluster label 'clusterGroup=untrustedSpoke' verified"
292+
else
293+
echo "WARNING: Cluster label is '$CLUSTER_LABEL' (expected: untrustedSpoke)"
294+
fi
295+
296+
echo "---------------------"
297+
else
298+
echo "Skipping spoke cluster import (ACM: $ACM_STATUS, Spoke Exit Code: $SPOKE_EXIT_CODE)"
299+
SPOKE_IMPORT_STATUS="SKIPPED"
300+
fi
301+
169302
echo "---------------------"
170303
echo "Deployment Summary"
171304
echo "---------------------"
@@ -179,12 +312,26 @@ else
179312
echo "Only hub cluster available"
180313
fi
181314

315+
316+
182317
if [ $PATTERN_EXIT_CODE -eq 0 ]; then
183318
echo "Pattern: Successfully deployed to hub cluster"
184319
else
185320
echo "Pattern: FAILED to deploy (exit code: $PATTERN_EXIT_CODE)"
186321
fi
187322

323+
if [ -n "$ACM_STATUS" ]; then
324+
echo "ACM on hub cluster: $ACM_STATUS"
325+
fi
326+
327+
if [ -n "$SPOKE_IMPORT_STATUS" ]; then
328+
echo "Spoke cluster import to ACM: $SPOKE_IMPORT_STATUS"
329+
if [ "$SPOKE_IMPORT_STATUS" == "SUCCESS" ]; then
330+
echo " - Cluster name: coco-spoke"
331+
echo " - Label: clusterGroup=untrustedSpoke"
332+
fi
333+
fi
334+
188335
echo "---------------------"
189336
echo "done"
190337
echo "---------------------"

values-global.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main:
1515
# WARNING
1616
# This default configuration uses a single cluster on azure.
1717
# It fundamentally violates the separation of duties.
18-
clusterGroupName: simple
18+
clusterGroupName: trusted-hub
1919
multiSourceConfig:
2020
enabled: true
2121
clusterGroupChartVersion: 0.9.*

0 commit comments

Comments
 (0)