Skip to content

Commit 02da238

Browse files
Merge pull request #68 from matzew/acm_scripts
OCPMCP-29: Adding ACM setup script
2 parents 31058bd + 54f0967 commit 02da238

File tree

7 files changed

+311
-0
lines changed

7 files changed

+311
-0
lines changed

build/acm.mk

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ACM (Advanced Cluster Management) installation targets for OpenShift
2+
# This file is specific to downstream OpenShift/OCP features only
3+
4+
.PHONY: acm-install acm-mce-install acm-operator-install acm-instance-install acm-status acm-import-cluster acm-uninstall acm-dump-manifests
5+
6+
##@ ACM (OpenShift only)
7+
8+
acm-install: acm-mce-install acm-operator-install acm-instance-install ## Install MCE, ACM operator and instance
9+
10+
acm-mce-install: ## Install MultiCluster Engine (required for ACM)
11+
@./hack/acm/install-mce.sh
12+
13+
acm-operator-install: ## Install ACM operator
14+
@./hack/acm/install-operator.sh
15+
16+
acm-instance-install: ## Install ACM instance (MultiClusterHub CR)
17+
@./hack/acm/install-instance.sh
18+
19+
acm-status: ## Check ACM installation status
20+
@./hack/acm/status.sh
21+
22+
acm-import-cluster: ## Import a managed cluster (requires CLUSTER_NAME and MANAGED_KUBECONFIG)
23+
@./hack/acm/import-cluster.sh "$(CLUSTER_NAME)" "$(MANAGED_KUBECONFIG)"
24+
25+
acm-uninstall: ## Uninstall ACM (reverse order: instance first, then operator)
26+
@./hack/acm/uninstall.sh
27+
28+
acm-dump-manifests: ## Dump ACM manifests locally for inspection
29+
@echo "Dumping ACM Operator manifests..."
30+
@mkdir -p _output/acm-manifests
31+
kustomize build https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14 > _output/acm-manifests/operator.yaml
32+
@echo "Operator manifests saved to _output/acm-manifests/operator.yaml"
33+
@echo ""
34+
@echo "Dumping ACM Instance manifests..."
35+
kustomize build https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/instance/base > _output/acm-manifests/instance.yaml
36+
@echo "Instance manifests saved to _output/acm-manifests/instance.yaml"

hack/acm/import-cluster.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
# Import a managed cluster into ACM
4+
# Usage: ./import-cluster.sh <cluster-name> <kubeconfig-path>
5+
6+
set -euo pipefail
7+
8+
CLUSTER_NAME="${1:-}"
9+
MANAGED_KUBECONFIG="${2:-}"
10+
11+
# Validate inputs
12+
if [ -z "$CLUSTER_NAME" ]; then
13+
echo "Error: CLUSTER_NAME is required"
14+
echo "Usage: $0 <cluster-name> <kubeconfig-path>"
15+
exit 1
16+
fi
17+
18+
if [ -z "$MANAGED_KUBECONFIG" ]; then
19+
echo "Error: MANAGED_KUBECONFIG is required"
20+
echo "Usage: $0 <cluster-name> <kubeconfig-path>"
21+
exit 1
22+
fi
23+
24+
if [ ! -f "$MANAGED_KUBECONFIG" ]; then
25+
echo "Error: Kubeconfig file not found: $MANAGED_KUBECONFIG"
26+
exit 1
27+
fi
28+
29+
echo "==========================================="
30+
echo "Importing cluster: $CLUSTER_NAME"
31+
echo "==========================================="
32+
33+
# Step 1: Create ManagedCluster resource
34+
echo "Step 1: Creating ManagedCluster resource on hub..."
35+
cat <<EOF | oc apply -f -
36+
apiVersion: cluster.open-cluster-management.io/v1
37+
kind: ManagedCluster
38+
metadata:
39+
name: $CLUSTER_NAME
40+
labels:
41+
cloud: auto-detect
42+
vendor: auto-detect
43+
spec:
44+
hubAcceptsClient: true
45+
EOF
46+
47+
# Step 2: Wait for import secret
48+
echo "Step 2: Waiting for import secret to be created..."
49+
for i in {1..60}; do
50+
if oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" 2>/dev/null; then
51+
echo "✅ Import secret created!"
52+
break
53+
fi
54+
echo " Waiting for import secret ($i/60)..."
55+
sleep 2
56+
done
57+
58+
# Step 3: Extract import manifests
59+
echo "Step 3: Extracting import manifests..."
60+
mkdir -p _output/acm-import
61+
oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" -o jsonpath='{.data.crds\.yaml}' | base64 -d > "_output/acm-import/${CLUSTER_NAME}-crds.yaml"
62+
oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" -o jsonpath='{.data.import\.yaml}' | base64 -d > "_output/acm-import/${CLUSTER_NAME}-import.yaml"
63+
echo "Import manifests saved to _output/acm-import/"
64+
65+
# Step 4: Apply CRDs to managed cluster
66+
echo "Step 4: Applying CRDs to managed cluster..."
67+
KUBECONFIG="$MANAGED_KUBECONFIG" oc apply -f "_output/acm-import/${CLUSTER_NAME}-crds.yaml"
68+
echo " Waiting for CRDs to be established..."
69+
sleep 5
70+
71+
# Step 5: Apply import manifest
72+
echo "Step 5: Applying import manifest to managed cluster..."
73+
KUBECONFIG="$MANAGED_KUBECONFIG" oc apply -f "_output/acm-import/${CLUSTER_NAME}-import.yaml"
74+
75+
# Step 6: Wait for klusterlet to be ready
76+
echo "Step 6: Waiting for klusterlet to be ready..."
77+
for i in {1..120}; do
78+
if oc get managedcluster "$CLUSTER_NAME" -o jsonpath='{.status.conditions[?(@.type=="ManagedClusterConditionAvailable")].status}' 2>/dev/null | grep -q "True"; then
79+
echo "✅ Cluster $CLUSTER_NAME is now available!"
80+
break
81+
fi
82+
echo " Waiting for cluster to become available ($i/120)..."
83+
sleep 5
84+
done
85+
86+
echo "==========================================="
87+
echo "✓ Cluster import complete!"
88+
echo "==========================================="
89+
oc get managedcluster "$CLUSTER_NAME"

hack/acm/install-instance.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Install ACM instance (MultiClusterHub CR)
4+
5+
set -euo pipefail
6+
7+
echo "Installing ACM Instance (MultiClusterHub)..."
8+
cat <<EOF | oc apply -f -
9+
apiVersion: operator.open-cluster-management.io/v1
10+
kind: MultiClusterHub
11+
metadata:
12+
name: multiclusterhub
13+
namespace: open-cluster-management
14+
spec:
15+
availabilityConfig: High
16+
EOF
17+
18+
echo "Waiting for MultiClusterHub to be ready (this may take several minutes)..."
19+
oc wait --for=condition=Complete --timeout=900s multiclusterhub/multiclusterhub -n open-cluster-management || true
20+
21+
echo "✓ ACM Instance installation complete"

hack/acm/install-mce.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
3+
# Install MultiCluster Engine (MCE) - required for ACM
4+
# This script installs the MCE operator and creates a MultiClusterEngine instance
5+
6+
set -euo pipefail
7+
8+
echo "Installing MultiCluster Engine (MCE)..."
9+
10+
# Create namespace
11+
echo "Creating multicluster-engine namespace..."
12+
oc create namespace multicluster-engine --dry-run=client -o yaml | oc apply -f -
13+
14+
# Create OperatorGroup
15+
echo "Creating MCE OperatorGroup..."
16+
cat <<EOF | oc apply -f -
17+
apiVersion: operators.coreos.com/v1
18+
kind: OperatorGroup
19+
metadata:
20+
name: multicluster-engine
21+
namespace: multicluster-engine
22+
spec:
23+
targetNamespaces:
24+
- multicluster-engine
25+
EOF
26+
27+
# Create Subscription
28+
echo "Creating MCE Subscription..."
29+
cat <<EOF | oc apply -f -
30+
apiVersion: operators.coreos.com/v1alpha1
31+
kind: Subscription
32+
metadata:
33+
name: multicluster-engine
34+
namespace: multicluster-engine
35+
spec:
36+
channel: stable-2.9
37+
name: multicluster-engine
38+
source: redhat-operators
39+
sourceNamespace: openshift-marketplace
40+
EOF
41+
42+
# Wait for CSV to appear and get its name
43+
echo "Waiting for MCE operator CSV to be ready..."
44+
CSV_NAME=""
45+
for i in {1..60}; do
46+
CSV_NAME=$(oc get csv -n multicluster-engine -o name 2>/dev/null | grep multicluster-engine || true)
47+
if [ -n "$CSV_NAME" ]; then
48+
echo "MCE CSV found: $CSV_NAME"
49+
break
50+
fi
51+
echo " Waiting for MCE CSV to appear ($i/60)..."
52+
sleep 5
53+
done
54+
55+
if [ -z "$CSV_NAME" ]; then
56+
echo "Error: MCE CSV not found after waiting"
57+
exit 1
58+
fi
59+
60+
# Wait for CSV to be ready
61+
echo "Waiting for CSV to reach Succeeded phase..."
62+
oc wait --for=jsonpath='{.status.phase}'=Succeeded "$CSV_NAME" -n multicluster-engine --timeout=300s
63+
64+
# Create MultiClusterEngine instance
65+
echo "Creating MultiClusterEngine instance..."
66+
cat <<EOF | oc apply -f -
67+
apiVersion: multicluster.openshift.io/v1
68+
kind: MultiClusterEngine
69+
metadata:
70+
name: multiclusterengine
71+
spec: {}
72+
EOF
73+
74+
# Wait for ManagedCluster CRD
75+
echo "Waiting for ManagedCluster CRD to be available..."
76+
for i in {1..120}; do
77+
if oc get crd managedclusters.cluster.open-cluster-management.io >/dev/null 2>&1; then
78+
echo "✅ ManagedCluster CRD is now available!"
79+
break
80+
fi
81+
echo " Waiting for ManagedCluster CRD ($i/120)..."
82+
sleep 5
83+
done
84+
85+
echo "✓ MCE installation complete"

hack/acm/install-operator.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Install ACM operator (Subscription, OperatorGroup, etc.)
4+
5+
set -euo pipefail
6+
7+
echo "Installing ACM Operator (release 2.14)..."
8+
oc apply -k https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14
9+
10+
# Wait for CSV to appear and get its name
11+
echo "Waiting for ACM operator CSV to be ready..."
12+
CSV_NAME=""
13+
for i in {1..60}; do
14+
CSV_NAME=$(oc get csv -n open-cluster-management -o name 2>/dev/null | grep advanced-cluster-management || true)
15+
if [ -n "$CSV_NAME" ]; then
16+
echo "ACM CSV found: $CSV_NAME"
17+
break
18+
fi
19+
echo " Waiting for ACM CSV to appear ($i/60)..."
20+
sleep 5
21+
done
22+
23+
if [ -z "$CSV_NAME" ]; then
24+
echo "Error: ACM CSV not found after waiting"
25+
exit 1
26+
fi
27+
28+
# Wait for CSV to be ready
29+
echo "Waiting for CSV to reach Succeeded phase..."
30+
oc wait --for=jsonpath='{.status.phase}'=Succeeded "$CSV_NAME" -n open-cluster-management --timeout=300s
31+
32+
echo "✓ ACM Operator installation complete"

hack/acm/status.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Check ACM installation status
4+
5+
set -euo pipefail
6+
7+
echo "=========================================="
8+
echo "ACM Installation Status"
9+
echo "=========================================="
10+
echo ""
11+
12+
echo "Namespaces:"
13+
oc get namespaces | grep -E "(open-cluster-management|multicluster-engine)" || echo "No ACM namespaces found"
14+
echo ""
15+
16+
echo "Operators:"
17+
oc get csv -n open-cluster-management 2>/dev/null || echo "No operators found in open-cluster-management namespace"
18+
echo ""
19+
20+
echo "MultiClusterHub:"
21+
oc get multiclusterhub -n open-cluster-management -o wide 2>/dev/null || echo "No MultiClusterHub found"
22+
echo ""
23+
24+
echo "ACM Pods:"
25+
oc get pods -n open-cluster-management 2>/dev/null || echo "No pods found in open-cluster-management namespace"
26+
echo ""
27+
28+
echo "ManagedClusters:"
29+
oc get managedclusters 2>/dev/null || echo "No ManagedClusters found (this is normal for fresh install)"

hack/acm/uninstall.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
# Uninstall ACM (reverse order: instance first, then operator)
4+
5+
set -euo pipefail
6+
7+
echo "Uninstalling ACM Instance..."
8+
oc delete multiclusterhub multiclusterhub -n open-cluster-management 2>/dev/null || true
9+
10+
echo "Waiting for MultiClusterHub to be deleted..."
11+
oc wait --for=delete multiclusterhub/multiclusterhub -n open-cluster-management --timeout=300s 2>/dev/null || true
12+
13+
echo "Uninstalling ACM Operator..."
14+
oc delete -k https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14 2>/dev/null || true
15+
16+
echo "Cleaning up namespaces..."
17+
oc delete namespace open-cluster-management --timeout=300s 2>/dev/null || true
18+
19+
echo "✓ ACM uninstallation complete"

0 commit comments

Comments
 (0)