Configuring the hub cluster for backup and restore

You can use GitOps ZTP to configure a set of policies to back up BareMetalHost resources. This allows you to recover data from a failed hub cluster and deploy a replacement cluster using Red Hat Advanced Cluster Management (RHACM).

Prerequisites
  • You have installed the OpenShift CLI (oc).

  • You have logged in as a user with cluster-admin privileges.

Procedure
  1. Create a policy to add the cluster.open-cluster-management.io/backup=cluster-activation label to all BareMetalHost resources that have the infraenvs.agent-install.openshift.io label. Save the policy as BareMetalHostBackupPolicy.yaml.

    The following example adds the cluster.open-cluster-management.io/backup label to all BareMetalHost resources that have the infraenvs.agent-install.openshift.io label:

    Example Policy
    apiVersion: policy.open-cluster-management.io/v1
    kind: Policy
    metadata:
      name: bmh-cluster-activation-label
      annotations:
        policy.open-cluster-management.io/description: Policy used to add the cluster.open-cluster-management.io/backup=cluster-activation label to all BareMetalHost resources
    spec:
      disabled: false
      policy-templates:
        - objectDefinition:
            apiVersion: policy.open-cluster-management.io/v1
            kind: ConfigurationPolicy
            metadata:
              name: set-bmh-backup-label
            spec:
              object-templates-raw: |
                {{- /* Set cluster-activation label on all BMH resources */ -}}
                {{- $infra_label := "infraenvs.agent-install.openshift.io" }}
                {{- range $bmh := (lookup "metal3.io/v1alpha1" "BareMetalHost" "" "" $infra_label).items }}
                    - complianceType: musthave
                      objectDefinition:
                        kind: BareMetalHost
                        apiVersion: metal3.io/v1alpha1
                        metadata:
                          name: {{ $bmh.metadata.name }}
                          namespace: {{ $bmh.metadata.namespace }}
                          labels:
                            cluster.open-cluster-management.io/backup: cluster-activation
                {{- end }}
              remediationAction: enforce
              severity: high
    ---
    apiVersion: cluster.open-cluster-management.io/v1beta1
    kind: Placement
    metadata:
      name: bmh-cluster-activation-label-pr
    spec:
      predicates:
        - requiredClusterSelector:
            labelSelector:
              matchExpressions:
                - key: name
                  operator: In
                  values:
                    - local-cluster
    ---
    apiVersion: policy.open-cluster-management.io/v1
    kind: PlacementBinding
    metadata:
      name: bmh-cluster-activation-label-binding
    placementRef:
      name: bmh-cluster-activation-label-pr
      apiGroup: cluster.open-cluster-management.io
      kind: Placement
    subjects:
      - name: bmh-cluster-activation-label
        apiGroup: policy.open-cluster-management.io
        kind: Policy
    ---
    apiVersion: cluster.open-cluster-management.io/v1beta2
    kind: ManagedClusterSetBinding
    metadata:
      name: default
      namespace: default
    spec:
      clusterSet: default

    If you apply the cluster.open-cluster-management.io/backup: cluster-activation label to BareMetalHost resources, the RHACM cluster backs up those resources. You can restore the BareMetalHost resources if the active cluster becomes unavailable, when restoring the hub activation resources.

  2. Apply the policy by running the following command:

    $ oc apply -f BareMetalHostBackupPolicy.yaml
Verification
  1. Find all BareMetalHost resources with the label infraenvs.agent-install.openshift.io by running the following command:

    $ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.io
    Example output
    NAMESPACE      NAME             STATE   CONSUMER   ONLINE   ERROR   AGE
    baremetal-ns   baremetal-name                      false            50s
  2. Verify that the policy has applied the label cluster.open-cluster-management.io/backup=cluster-activation to all these resources, by running the following command:

    $ oc get BareMetalHost -A -l infraenvs.agent-install.openshift.io,cluster.open-cluster-management.io/backup=cluster-activation
    Example output
    NAMESPACE      NAME             STATE   CONSUMER   ONLINE   ERROR   AGE
    baremetal-ns   baremetal-name                      false            50s

    The output must show the same list as in the previous step, which listed all BareMetalHost resources with the label infraenvs.agent-install.openshift.io. This confirms that all the BareMetalHost resources with the infraenvs.agent-install.openshift.io label also have the cluster.open-cluster-management.io/backup: cluster-activation label.

    The following example shows a BareMetalHost resource with the infraenvs.agent-install.openshift.io label. The resource must also have the cluster.open-cluster-management.io/backup: cluster-activation label, which was added by the policy created in step 1.

    apiVersion: metal3.io/v1alpha1
    kind: BareMetalHost
    metadata:
      labels:
        cluster.open-cluster-management.io/backup: cluster-activation
        infraenvs.agent-install.openshift.io: value
      name: baremetal-name
      namespace: baremetal-ns

You can now use Red Hat Advanced Cluster Management to restore a managed cluster.

Important

When you restore BareMetalHost resources as part of restoring the cluster activation data, you must restore the BareMetalHost status. The following RHACM Restore resource example restores activation resources, including BareMetalHost, and also restores the status for the BareMetalHost resources:

apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Restore
metadata:
  name: restore-acm-bmh
  namespace: open-cluster-management-backup
spec:
  cleanupBeforeRestore: CleanupRestored
  veleroManagedClustersBackupName: latest
  veleroCredentialsBackupName: latest
  veleroResourcesBackupName: latest
  restoreStatus:
    includedResources:
      - BareMetalHosts
  • Set veleroManagedClustersBackupName: latest to restore activation resources.

  • Restores the status for BareMetalHost resources.