Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions build/acm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ACM (Advanced Cluster Management) installation targets for OpenShift
# This file is specific to downstream OpenShift/OCP features only

.PHONY: acm-install acm-mce-install acm-operator-install acm-instance-install acm-status acm-import-cluster acm-uninstall acm-dump-manifests

##@ ACM (OpenShift only)

acm-install: acm-mce-install acm-operator-install acm-instance-install ## Install MCE, ACM operator and instance

acm-mce-install: ## Install MultiCluster Engine (required for ACM)
@./hack/acm/install-mce.sh

acm-operator-install: ## Install ACM operator
@./hack/acm/install-operator.sh

acm-instance-install: ## Install ACM instance (MultiClusterHub CR)
@./hack/acm/install-instance.sh

acm-status: ## Check ACM installation status
@./hack/acm/status.sh

acm-import-cluster: ## Import a managed cluster (requires CLUSTER_NAME and MANAGED_KUBECONFIG)
@./hack/acm/import-cluster.sh "$(CLUSTER_NAME)" "$(MANAGED_KUBECONFIG)"

acm-uninstall: ## Uninstall ACM (reverse order: instance first, then operator)
@./hack/acm/uninstall.sh

acm-dump-manifests: ## Dump ACM manifests locally for inspection
@echo "Dumping ACM Operator manifests..."
@mkdir -p _output/acm-manifests
kustomize build https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14 > _output/acm-manifests/operator.yaml
@echo "Operator manifests saved to _output/acm-manifests/operator.yaml"
@echo ""
@echo "Dumping ACM Instance manifests..."
kustomize build https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/instance/base > _output/acm-manifests/instance.yaml
@echo "Instance manifests saved to _output/acm-manifests/instance.yaml"
89 changes: 89 additions & 0 deletions hack/acm/import-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash

# Import a managed cluster into ACM
# Usage: ./import-cluster.sh <cluster-name> <kubeconfig-path>

set -euo pipefail

CLUSTER_NAME="${1:-}"
MANAGED_KUBECONFIG="${2:-}"

# Validate inputs
if [ -z "$CLUSTER_NAME" ]; then
echo "Error: CLUSTER_NAME is required"
echo "Usage: $0 <cluster-name> <kubeconfig-path>"
exit 1
fi

if [ -z "$MANAGED_KUBECONFIG" ]; then
echo "Error: MANAGED_KUBECONFIG is required"
echo "Usage: $0 <cluster-name> <kubeconfig-path>"
exit 1
fi

if [ ! -f "$MANAGED_KUBECONFIG" ]; then
echo "Error: Kubeconfig file not found: $MANAGED_KUBECONFIG"
exit 1
fi

echo "==========================================="
echo "Importing cluster: $CLUSTER_NAME"
echo "==========================================="

# Step 1: Create ManagedCluster resource
echo "Step 1: Creating ManagedCluster resource on hub..."
cat <<EOF | oc apply -f -
apiVersion: cluster.open-cluster-management.io/v1
kind: ManagedCluster
metadata:
name: $CLUSTER_NAME
labels:
cloud: auto-detect
vendor: auto-detect
spec:
hubAcceptsClient: true
EOF

# Step 2: Wait for import secret
echo "Step 2: Waiting for import secret to be created..."
for i in {1..60}; do
if oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" 2>/dev/null; then
echo "✅ Import secret created!"
break
fi
echo " Waiting for import secret ($i/60)..."
sleep 2
done

# Step 3: Extract import manifests
echo "Step 3: Extracting import manifests..."
mkdir -p _output/acm-import
oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" -o jsonpath='{.data.crds\.yaml}' | base64 -d > "_output/acm-import/${CLUSTER_NAME}-crds.yaml"
oc get secret -n "$CLUSTER_NAME" "$CLUSTER_NAME-import" -o jsonpath='{.data.import\.yaml}' | base64 -d > "_output/acm-import/${CLUSTER_NAME}-import.yaml"
echo "Import manifests saved to _output/acm-import/"

# Step 4: Apply CRDs to managed cluster
echo "Step 4: Applying CRDs to managed cluster..."
KUBECONFIG="$MANAGED_KUBECONFIG" oc apply -f "_output/acm-import/${CLUSTER_NAME}-crds.yaml"
echo " Waiting for CRDs to be established..."
sleep 5

# Step 5: Apply import manifest
echo "Step 5: Applying import manifest to managed cluster..."
KUBECONFIG="$MANAGED_KUBECONFIG" oc apply -f "_output/acm-import/${CLUSTER_NAME}-import.yaml"

# Step 6: Wait for klusterlet to be ready
echo "Step 6: Waiting for klusterlet to be ready..."
for i in {1..120}; do
if oc get managedcluster "$CLUSTER_NAME" -o jsonpath='{.status.conditions[?(@.type=="ManagedClusterConditionAvailable")].status}' 2>/dev/null | grep -q "True"; then
echo "✅ Cluster $CLUSTER_NAME is now available!"
break
fi
echo " Waiting for cluster to become available ($i/120)..."
sleep 5
done

echo "==========================================="
echo "✓ Cluster import complete!"
echo "==========================================="
oc get managedcluster "$CLUSTER_NAME"
21 changes: 21 additions & 0 deletions hack/acm/install-instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Install ACM instance (MultiClusterHub CR)

set -euo pipefail

echo "Installing ACM Instance (MultiClusterHub)..."
cat <<EOF | oc apply -f -
apiVersion: operator.open-cluster-management.io/v1
kind: MultiClusterHub
metadata:
name: multiclusterhub
namespace: open-cluster-management
spec:
availabilityConfig: High
EOF

echo "Waiting for MultiClusterHub to be ready (this may take several minutes)..."
oc wait --for=condition=Complete --timeout=900s multiclusterhub/multiclusterhub -n open-cluster-management || true

echo "✓ ACM Instance installation complete"
85 changes: 85 additions & 0 deletions hack/acm/install-mce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

# Install MultiCluster Engine (MCE) - required for ACM
# This script installs the MCE operator and creates a MultiClusterEngine instance

set -euo pipefail

echo "Installing MultiCluster Engine (MCE)..."

# Create namespace
echo "Creating multicluster-engine namespace..."
oc create namespace multicluster-engine --dry-run=client -o yaml | oc apply -f -

# Create OperatorGroup
echo "Creating MCE OperatorGroup..."
cat <<EOF | oc apply -f -
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: multicluster-engine
namespace: multicluster-engine
spec:
targetNamespaces:
- multicluster-engine
EOF

# Create Subscription
echo "Creating MCE Subscription..."
cat <<EOF | oc apply -f -
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: multicluster-engine
namespace: multicluster-engine
spec:
channel: stable-2.9
name: multicluster-engine
source: redhat-operators
sourceNamespace: openshift-marketplace
EOF

# Wait for CSV to appear and get its name
echo "Waiting for MCE operator CSV to be ready..."
CSV_NAME=""
for i in {1..60}; do
CSV_NAME=$(oc get csv -n multicluster-engine -o name 2>/dev/null | grep multicluster-engine || true)
if [ -n "$CSV_NAME" ]; then
echo "MCE CSV found: $CSV_NAME"
break
fi
echo " Waiting for MCE CSV to appear ($i/60)..."
sleep 5
done

if [ -z "$CSV_NAME" ]; then
echo "Error: MCE CSV not found after waiting"
exit 1
fi

# Wait for CSV to be ready
echo "Waiting for CSV to reach Succeeded phase..."
oc wait --for=jsonpath='{.status.phase}'=Succeeded "$CSV_NAME" -n multicluster-engine --timeout=300s

# Create MultiClusterEngine instance
echo "Creating MultiClusterEngine instance..."
cat <<EOF | oc apply -f -
apiVersion: multicluster.openshift.io/v1
kind: MultiClusterEngine
metadata:
name: multiclusterengine
spec: {}
EOF

# Wait for ManagedCluster CRD
echo "Waiting for ManagedCluster CRD to be available..."
for i in {1..120}; do
if oc get crd managedclusters.cluster.open-cluster-management.io >/dev/null 2>&1; then
echo "✅ ManagedCluster CRD is now available!"
break
fi
echo " Waiting for ManagedCluster CRD ($i/120)..."
sleep 5
done

echo "✓ MCE installation complete"
32 changes: 32 additions & 0 deletions hack/acm/install-operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Install ACM operator (Subscription, OperatorGroup, etc.)

set -euo pipefail

echo "Installing ACM Operator (release 2.14)..."
oc apply -k https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14

# Wait for CSV to appear and get its name
echo "Waiting for ACM operator CSV to be ready..."
CSV_NAME=""
for i in {1..60}; do
CSV_NAME=$(oc get csv -n open-cluster-management -o name 2>/dev/null | grep advanced-cluster-management || true)
if [ -n "$CSV_NAME" ]; then
echo "ACM CSV found: $CSV_NAME"
break
fi
echo " Waiting for ACM CSV to appear ($i/60)..."
sleep 5
done

if [ -z "$CSV_NAME" ]; then
echo "Error: ACM CSV not found after waiting"
exit 1
fi

# Wait for CSV to be ready
echo "Waiting for CSV to reach Succeeded phase..."
oc wait --for=jsonpath='{.status.phase}'=Succeeded "$CSV_NAME" -n open-cluster-management --timeout=300s

echo "✓ ACM Operator installation complete"
29 changes: 29 additions & 0 deletions hack/acm/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# Check ACM installation status

set -euo pipefail

echo "=========================================="
echo "ACM Installation Status"
echo "=========================================="
echo ""

echo "Namespaces:"
oc get namespaces | grep -E "(open-cluster-management|multicluster-engine)" || echo "No ACM namespaces found"
echo ""

echo "Operators:"
oc get csv -n open-cluster-management 2>/dev/null || echo "No operators found in open-cluster-management namespace"
echo ""

echo "MultiClusterHub:"
oc get multiclusterhub -n open-cluster-management -o wide 2>/dev/null || echo "No MultiClusterHub found"
echo ""

echo "ACM Pods:"
oc get pods -n open-cluster-management 2>/dev/null || echo "No pods found in open-cluster-management namespace"
echo ""

echo "ManagedClusters:"
oc get managedclusters 2>/dev/null || echo "No ManagedClusters found (this is normal for fresh install)"
19 changes: 19 additions & 0 deletions hack/acm/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# Uninstall ACM (reverse order: instance first, then operator)

set -euo pipefail

echo "Uninstalling ACM Instance..."
oc delete multiclusterhub multiclusterhub -n open-cluster-management 2>/dev/null || true

echo "Waiting for MultiClusterHub to be deleted..."
oc wait --for=delete multiclusterhub/multiclusterhub -n open-cluster-management --timeout=300s 2>/dev/null || true

echo "Uninstalling ACM Operator..."
oc delete -k https://github.com/redhat-cop/gitops-catalog/advanced-cluster-management/operator/overlays/release-2.14 2>/dev/null || true

echo "Cleaning up namespaces..."
oc delete namespace open-cluster-management --timeout=300s 2>/dev/null || true

echo "✓ ACM uninstallation complete"